dylanebert HF staff commited on
Commit
8a63854
1 Parent(s): ee54d2d

initial commit

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. .gitignore +4 -0
  3. app.py +38 -0
  4. examples/chair.obj +3 -0
  5. requirements.txt +1 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.obj filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ __pycache__
2
+
3
+ gradio_cached_examples/
4
+ venv/
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import trimesh
3
+ from instant_texture import Converter
4
+
5
+ converter = Converter()
6
+
7
+
8
+ def extract_texture(mesh_path: str):
9
+ mesh = trimesh.load(mesh_path)
10
+ mesh = next(iter(mesh.geometry.values()))
11
+ texture = mesh.visual.material.baseColorTexture
12
+ return texture
13
+
14
+
15
+ def convert(input_mesh_path: str):
16
+ if not input_mesh_path.endswith(".obj"):
17
+ raise ValueError("Only .obj files are supported")
18
+ output_path = "/tmp/output.glb"
19
+ converter.convert(input_mesh_path, output_path)
20
+ texture = extract_texture(output_path)
21
+ return output_path, texture
22
+
23
+
24
+ demo = gr.Interface(
25
+ convert,
26
+ title="Instant Texture",
27
+ description="Convert a vertex-colored mesh (.obj) to a uv-mapped, textured mesh (.glb).",
28
+ inputs=gr.Model3D(label="Vertex-colored mesh (.obj)"),
29
+ outputs=[
30
+ gr.Model3D(label="Output uv-mapped, textured mesh (.glb)"),
31
+ gr.Image(label="Output texture"),
32
+ ],
33
+ examples=["examples/chair.obj"],
34
+ cache_examples=True,
35
+ )
36
+
37
+ if __name__ == "__main__":
38
+ demo.queue().launch()
examples/chair.obj ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2d348aa68e6d3fc2b1359c3c60b227dc47484421cd0ce0bde81f386a4ec94ffa
3
+ size 4453602
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ instant-texture @ git+https://github.com/dylanebert/InstantTexture