Buckets:
| import os | |
| os.environ['OPENCV_IO_ENABLE_OPENEXR'] = '1' | |
| os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True" # Can save GPU memory | |
| import cv2 | |
| import imageio | |
| from PIL import Image | |
| import torch | |
| from trellis2.pipelines import Trellis2ImageTo3DPipeline | |
| from trellis2.utils import render_utils | |
| from trellis2.renderers import EnvMap | |
| import o_voxel | |
| # 1. Setup Environment Map | |
| envmap = EnvMap(torch.tensor( | |
| cv2.cvtColor(cv2.imread('assets/hdri/forest.exr', cv2.IMREAD_UNCHANGED), cv2.COLOR_BGR2RGB), | |
| dtype=torch.float32, device='cuda' | |
| )) | |
| # 2. Load Pipeline | |
| pipeline = Trellis2ImageTo3DPipeline.from_pretrained("microsoft/TRELLIS.2-4B") | |
| pipeline.cuda() | |
| # 3. Load Image & Run | |
| image = Image.open("assets/example_image/T.png") | |
| mesh = pipeline.run(image)[0] | |
| mesh.simplify(16777216) # nvdiffrast limit | |
| # 4. Render Video | |
| video = render_utils.make_pbr_vis_frames(render_utils.render_video(mesh, envmap=envmap)) | |
| imageio.mimsave("sample.mp4", video, fps=15) | |
| # 5. Export to GLB | |
| glb = o_voxel.postprocess.to_glb( | |
| vertices = mesh.vertices, | |
| faces = mesh.faces, | |
| attr_volume = mesh.attrs, | |
| coords = mesh.coords, | |
| attr_layout = mesh.layout, | |
| voxel_size = mesh.voxel_size, | |
| aabb = [[-0.5, -0.5, -0.5], [0.5, 0.5, 0.5]], | |
| decimation_target = 1000000, | |
| texture_size = 4096, | |
| remesh = True, | |
| remesh_band = 1, | |
| remesh_project = 0, | |
| verbose = True | |
| ) | |
| glb.export("sample.glb", extension_webp=True) |
Xet Storage Details
- Size:
- 1.58 kB
- Xet hash:
- d46bf86e61aae49ee789bc30f3a6b88dcba923f0de4983670d8cdb23f4601096
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.