Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
84 changed files
with
8,478 additions
and
2,547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# exit if any line fails | ||
set -xe | ||
# grab the binvox binary from the trimesh S3 bucket | ||
# do this to avoid CI hammering the original address: | ||
# http://www.patrickmin.com/binvox/linux64/binvox | ||
wget https://trimesh.s3-us-west-1.amazonaws.com/binvox | ||
# check the hash of the file before using it | ||
echo "cc05b3ceec0b3f7061f629448c3764e87f035ec34bba46ec4dcc21e089dd40c5 binvox" | sha256sum --check | ||
# make it executable | ||
chmod +x binvox | ||
# move binary to path | ||
mv binvox /usr/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import os | ||
import numpy as np | ||
import inspect | ||
import trimesh | ||
from trimesh.exchange.binvox import voxelize_mesh | ||
from trimesh import voxel as v | ||
|
||
|
||
dir_current = os.path.dirname( | ||
os.path.abspath( | ||
inspect.getfile( | ||
inspect.currentframe()))) | ||
# the absolute path for our reference models | ||
dir_models = os.path.abspath( | ||
os.path.join(dir_current, '..', 'models')) | ||
|
||
|
||
def show(chair_mesh, chair_voxels, colors=(1, 1, 1, 0.3)): | ||
scene = chair_mesh.scene() | ||
scene.add_geometry(chair_voxels.as_boxes(colors=colors)) | ||
scene.show() | ||
|
||
|
||
base_name = 'chair_model' | ||
chair_mesh = trimesh.load(os.path.join(dir_models, '%s.obj' % base_name)) | ||
if isinstance(chair_mesh, trimesh.scene.Scene): | ||
chair_mesh = trimesh.util.concatenate([ | ||
trimesh.Trimesh(mesh.vertices, mesh.faces) | ||
for mesh in chair_mesh.geometry.values()]) | ||
|
||
binvox_path = os.path.join(dir_models, '%s.binvox' % base_name) | ||
chair_voxels = trimesh.load(binvox_path) | ||
|
||
chair_voxels = v.VoxelGrid(chair_voxels.encoding.dense, chair_voxels.transform) | ||
|
||
print('white: voxelized chair (binvox, exact)') | ||
show( | ||
chair_mesh, | ||
voxelize_mesh(chair_mesh, exact=True), | ||
colors=(1, 1, 1, 0.3)) | ||
|
||
print('red: binvox-loaded chair') | ||
show(chair_mesh, chair_voxels, colors=(1, 0, 0, 0.3)) | ||
|
||
voxelized_chair_mesh = chair_mesh.voxelized(np.max(chair_mesh.extents) / 32) | ||
print('green: voxelized chair (default).') | ||
show(chair_mesh, voxelized_chair_mesh, colors=(0, 1, 0, 0.3)) | ||
|
||
shape = (50, 17, 63) | ||
revox = chair_voxels.revoxelized(shape) | ||
print('cyan: revoxelized.') | ||
show(chair_mesh, revox, colors=(0, 1, 1, 0.3)) | ||
|
||
values = chair_voxels.encoding.dense.copy() | ||
values[:values.shape[0] // 2] = 0 | ||
stripped = v.VoxelGrid(values, chair_voxels.transform.copy()).strip() | ||
print('yellow: stripped halved voxel grid. Transform is updated appropriately') | ||
show(chair_mesh, stripped, colors=(1, 1, 0, 0.3)) | ||
|
||
transform = np.eye(4) | ||
transform[:3] += np.random.normal(size=(3, 4)) * 0.2 | ||
transformed_chair_mesh = chair_mesh.copy().apply_transform(transform) | ||
print('original transform volume: %s' | ||
% str(chair_voxels.element_volume)) | ||
|
||
chair_voxels.apply_transform(transform) | ||
print('warped transform volume: %s' % str(chair_voxels.element_volume)) | ||
print('blue: transformed voxels. Transformation is lazy, and each voxel is ' | ||
'no longer a cube.') | ||
show(transformed_chair_mesh, chair_voxels, colors=(0, 0, 1, 0.3)) | ||
|
||
|
||
voxelized = chair_mesh.voxelized(pitch=0.02, method='subdivide').fill() | ||
print('green: subdivided') | ||
show(chair_mesh, voxelized, colors=(0, 1, 0, 0.3)) | ||
|
||
voxelized = chair_mesh.voxelized(pitch=0.02, method='ray') | ||
print('red: ray. Poor performance on thin structures') | ||
show(chair_mesh, voxelized, colors=(1, 0, 0, 0.3)) | ||
|
||
voxelized = chair_mesh.voxelized(pitch=0.02, method='binvox') | ||
print('red: binvox (default). Poor performance on thin structures') | ||
show(chair_mesh, voxelized, colors=(1, 0, 0, 0.3)) | ||
|
||
voxelized = chair_mesh.voxelized(pitch=0.02, method='binvox', wireframe=True) | ||
print('green: binvox (wireframe). Still doesn\'t capture all thin structures') | ||
show(chair_mesh, voxelized, colors=(0, 1, 0, 0.3)) | ||
|
||
voxelized = chair_mesh.voxelized(pitch=0.02, method='binvox', exact=True) | ||
print('blue: binvox (exact). Does a good job') | ||
show(chair_mesh, voxelized, colors=(0, 0, 1, 0.3)) | ||
|
||
voxelized = chair_mesh.voxelized( | ||
pitch=0.02, | ||
method='binvox', | ||
exact=True, | ||
downsample_factor=2, | ||
downsample_threshold=1, | ||
) | ||
print('red: binvox (exact downsampled) surface') | ||
show(chair_mesh, voxelized, colors=(1, 0, 0, 0.3)) | ||
|
||
chair_voxels = chair_mesh.voxelized(pitch=0.02, method='binvox', exact=True) | ||
|
||
voxelized = chair_voxels.copy().fill(method='base') | ||
print('blue: binvox (exact) filled (base). Gets a bit overly excited') | ||
show(chair_mesh, voxelized, colors=(0, 0, 1, 0.3)) | ||
|
||
voxelized = chair_voxels.copy().fill(method='orthographic') | ||
print('green: binvox (exact) filled (orthographic). ' | ||
'Doesn\'t do much as should be expected') | ||
show(chair_mesh, voxelized, colors=(0, 1, 0, 0.3)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from trimesh.scene import Scene | ||
from trimesh.primitives import Sphere | ||
from trimesh.voxel.morphology import fillers | ||
|
||
mesh = Sphere() | ||
|
||
|
||
def show(surface, filled, label): | ||
print(label) | ||
scene = Scene() | ||
scene.add_geometry(surface.as_boxes(colors=(1, 0, 0, 0.3))) | ||
scene.add_geometry(filled.as_boxes(colors=(0, 0, 1, 0.5))) | ||
scene.show() | ||
|
||
|
||
# remove_internal produced unexpected results when boundary pixels are occupied | ||
# not useful very often, but handy to demonstrate filling algorithms. | ||
surface = mesh.voxelized( | ||
pitch=0.2, method='binvox', remove_internal=True) | ||
for impl in fillers: | ||
show(surface, surface.copy().fill(method=impl), impl) | ||
|
||
|
||
filled = mesh.voxelized( | ||
pitch=0.05, method='binvox', exact=True).fill(method='holes') | ||
hollow = filled.copy().hollow() | ||
print('filled volume, hollow_volume') | ||
print(filled.volume, hollow.volume) | ||
print('hollow voxel (zoom in to see hollowness)') | ||
hollow.show() |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Exported from Wings 3D 0.98.29b | ||
newmtl default | ||
Ns 100.000 | ||
d 1.00000 | ||
illum 2 | ||
Kd 1.00000 0.00000 1.00000 | ||
Ka 1.00000 0.00000 1.00000 | ||
Ks 1.00000 0.00000 1.00000 | ||
Ke 0.00000e+0 0.00000e+0 0.00000e+0 |
Oops, something went wrong.