a little update of this script

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

#    Import modules
import operator 

#    Math utils
def dotProduct(v1, v2):
    return sum(map(operator.mul, v1, v2))
    
#    Maya variable
object_space = OpenMaya.MSpace.kObject
world_space = OpenMaya.MSpace.kWorld

#    Maya node
obj_1 = pmc.selected()[0]
obj_2 = pmc.selected()[1]
obj_3 = pmc.selected()[2]

#    Maya MFn
mfn_obj_1 = obj_1.getShape().__apimfn__()
mfn_obj_2 = obj_2.getShape().__apimfn__()
mfn_obj_3 = obj_3.getShape().__apimfn__()

#    Points
points_1 = OpenMaya.MPointArray()
mfn_obj_1.getPoints(points_1, object_space)
points_2 = OpenMaya.MPointArray()
mfn_obj_2.getPoints(points_2, object_space)
points_3 = OpenMaya.MPointArray()
mfn_obj_3.getPoints(points_3, object_space)

#    Normals
normals_1 = OpenMaya.MFloatVectorArray()
mfn_obj_1.getVertexNormals(False, normals_1, world_space)
normals_2 = OpenMaya.MFloatVectorArray()
mfn_obj_2.getVertexNormals(False, normals_2, world_space)
normals_3 = OpenMaya.MFloatVectorArray()
mfn_obj_3.getVertexNormals(False, normals_3, world_space)

#    Tangents
Tangents_1 = OpenMaya.MFloatVectorArray()
mfn_obj_1.getVertexNormals(False, Tangents_1, world_space)
Tangents_2 = OpenMaya.MFloatVectorArray()
mfn_obj_2.getVertexNormals(False, Tangents_2, world_space)
Tangents_3 = OpenMaya.MFloatVectorArray()
mfn_obj_3.getVertexNormals(False, Tangents_3, world_space)

#    Binormals
Binormals_1 = OpenMaya.MFloatVectorArray()
mfn_obj_1.getVertexNormals(False, Binormals_1, world_space)
Binormals_2 = OpenMaya.MFloatVectorArray()
mfn_obj_2.getVertexNormals(False, Binormals_2, world_space)
Binormals_3 = OpenMaya.MFloatVectorArray()
mfn_obj_3.getVertexNormals(False, Binormals_3, world_space)

#    Offset
for idx, (f_idx, t_idx) in enumerate(vertex_matched.items()):

    f_idx = int(f_idx)
    if len(t_idx) > 1:
        pmc.warning("Multi Index -- %s --" % t_idx)
        continue
    t_idx = int(t_idx[0])

    offset_point = points_2[f_idx] - points_1[f_idx]
    op_x = dotProduct(offset_point, Tangents_1[f_idx])
    op_y = dotProduct(offset_point, normals_1[f_idx])
    op_z = dotProduct(offset_point, Binormals_1[f_idx])

    offset_point_normal = OpenMaya.MVector(Tangents_3[t_idx]) * op_x
    offset_point_normal += OpenMaya.MVector(normals_3[t_idx]) * op_y
    offset_point_normal += OpenMaya.MVector(Binormals_3[t_idx]) * op_z

    final_point = points_3[t_idx] + offset_point
    

    mfn_obj_3.setPoint(t_idx, OpenMaya.MPoint(final_point), object_space)

#    Restore point
# mfn_obj_3.setPoints(points_3, object_space)

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

This is very powerful with a comparison between two mesh points.
I used to pass on blendshape a mesh to another. It is possible to combine 
it with blendshapes etc etc.

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/84b5165b-6501-4611-a4fa-8e28e8445842%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to