Comments (5)
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.
Arguably, we should have an obj reader in this library too to make this operation easier.
from dracopy.
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.
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.
Closing due to inactivity. Let me know if you still need help.
from dracopy.
Related Issues (20)
- DracoPy issue HOT 1
- Python 3.8 Binaries HOT 1
- Python 3.9 Binaries HOT 3
- Windows Binaries HOT 4
- Decoding error for hemibrain meshes introduced between 0.0.15 and 0.0.18 release HOT 3
- Encoding does not return resulting faces and points count HOT 2
- Custom metadata support HOT 2
- Attributes compression support? HOT 1
- Error in reshape HOT 3
- How to build wheel on apple silicon? HOT 3
- color & custom attributes encoding / decoding
- encoding and decoding intensity values in point cloud HOT 3
- Draco Submodule Should Point to Exact Version HOT 5
- Changes needed in setup.py in order to work with Python 3.11 on MacOS HOT 2
- std::vector larger than max_size HOT 2
- 1.2.1 with Python3.11 to PYPI HOT 5
- Removal of DracoPy.cpp from this repository HOT 2
- Pointcloud support HOT 14
- Encode .obj HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dracopy.