Git Product home page Git Product logo

Comments (5)

william-silversmith avatar william-silversmith commented on June 7, 2024

Hi Johnathan,

The main problem is the mesh is currently in OBJ form which is a text stream describing the mesh. It needs to be decoded into numpy arrays of vertices and faces. Luckily, we provide some libraries that may help (though they support only a subset of the OBJ format).

zmesh comes with a zmesh.Mesh class that has a mesh = Mesh.from_obj(txt) function. We also provide a similar mesh class with more lenient licensing in cloud-volume. This will yield a decoded mesh object that has mesh.vertices and mesh.faces. You can then proceed to use DracoPy. Here's an example:

import zmesh
import DracoPy

with open(os.path.join(testdata_directory, "bunny.obj"), "rt") as improper_file: 
    file_content = improper_file.read() 

mesh = zmesh.Mesh.from_obj(file_content)
draco_binary = DracoPy.encode_mesh_to_buffer(mesh.vertices.flatten('C'), mesh.faces.flatten('C'))

There are probably several other libraries you could use to convert the obj to raw vertices too.

from dracopy.

william-silversmith avatar william-silversmith commented on June 7, 2024

Arguably, we should have an obj reader in this library too to make this operation easier.

from dracopy.

Jonathan1045 avatar Jonathan1045 commented on June 7, 2024

thanks for your reply dude !
I use your example in my project:

drc_file = open("testdata_files/head3d.drc", "wb")
with open("testdata_files/head3d.obj", "rt") as improper_file:
    file_content = improper_file.read()
    mesh = zmesh.Mesh.from_obj(file_content)
    draco_binary = DracoPy.encode_mesh_to_buffer(mesh.vertices.flatten('C'), mesh.faces.flatten('C'))
    drc_file.write(draco_binary)
    drc_file.close()

but error

Traceback (most recent call last):
  File "compressDraco.py", line 33, in <module>
    compress_obj_to_draco()
  File "compressDraco.py", line 27, in compress_obj_to_draco
    mesh = zmesh.Mesh.from_obj(file_content)
  File "C:\ProgramData\Anaconda3\envs\py37\lib\site-packages\zmesh\mesh.py", line 136, in from_obj
    (n1, n2, n3) = re.match(r'vn\s+([-\d\.]+)\s+([-\d\.]+)\s+([-\d\.]+)', line).groups()
AttributeError: 'NoneType' object has no attribute 'groups'

How to solve this problem?

from dracopy.

william-silversmith avatar william-silversmith commented on June 7, 2024

It seems the regexp I wrote does not match the format of the vertex normals line in your OBJ file. You can try looking at other OBJ parsers that might be more complete (the one I wrote is very simple). Another possibility is that your OBJ file is malformed, but I wouldn't bet on that unless other OBJ parsers fail on it. If you can share the OBJ, I could try it myself and see if the behavior is reasonable.

from dracopy.

william-silversmith avatar william-silversmith commented on June 7, 2024

Closing due to inactivity. Let me know if you still need help.

from dracopy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.