Thank you for replying #1383. But this just combine the both models but they are not fitting on model1 by matching the inner surface of model2 to outer surface of model1. I have the both pictures one is what I am getting with this code that you have suggested and the second is expected result.
If we have transformation which can work on surfaces not on the Bounding Box then it may work but I am not sure.
Thank you for helping,
Akshay
Python 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 7.22.0 -- An enhanced Interactive Python.
import numpy as np
import trimesh
a = trimesh.load('model1.stl')
b = trimesh.load('model2.stl')
Data not utf-8! Trying Windows-1252 (confidence 0.73)
at = a.bounding_box_oriented.primitive.transform
bt = b.bounding_box_oriented.primitive.transform
a_to_b = np.dot(bt, np.linalg.inv(at))
at
Out[8]:
TrackedArray([[-0.92817622, -0.35878948, -0.09878775, 3.17065155],
[-0.06162009, -0.1136176 , 0.99161182, 39.2899497 ],
[-0.36700392, 0.92647782, 0.08334852, 2.22560429],
[ 0. , 0. , 0. , 1. ]])
a.bounds
Out[9]:
array([[-4.58730364, 30.99465752, -6.10579252],
[ 9.77338219, 48.5644455 , 11.24947166]])
b.bounds
Out[10]:
array([[-4.66867018, -6.44354057, -4.65808773],
[ 5.90229559, 6.26821184, 3.41614819]])
a.apply_transform(a_to_b)
Out[11]: <trimesh.Trimesh(vertices.shape=(38137, 3), faces.shape=(75908, 3))>
a.bounds
Out[12]:
array([[-10.03075575, -10.71799307, -7.50492806],
[ 6.82770259, 7.95139979, 4.4296185 ]])
b.bounds
Out[13]:
array([[-4.66867018, -6.44354057, -4.65808773],
[ 5.90229559, 6.26821184, 3.41614819]])
identify the faces on both meshes you want to match (through hand labeling or some heuristic you generate). Perhaps segmenting by face_adjacency_angle would work.
start with the OBB transform, modified to match the normals of the two face patches
run something like iterative closest point (trimesh.registration.icp) to move them close.
Hi @mikedh ,
Thank you for replying #1383. But this just combine the both models but they are not fitting on model1 by matching the inner surface of model2 to outer surface of model1. I have the both pictures one is what I am getting with this code that you have suggested and the second is expected result.
If we have transformation which can work on surfaces not on the Bounding Box then it may work but I am not sure.
Thank you for helping, Akshay
Originally posted by @akshaypatel1811 in https://github.com/mikedh/trimesh/issues/1383#issuecomment-947758273