// We should know the mapping // remove morph pass tolerance instead bool TryMapping1(MegaTargetMesh tm, MegaMorphOMatic morph) { MegaModifiers mod = morph.GetComponent<MegaModifiers>(); if ( mod == null ) { EditorUtility.DisplayDialog("Missing ModifyObject!", "No ModifyObject script found on the object", "OK"); return false; } // Get extents for mod verts and for imported meshes, if not the same then scale Vector3 min1,max1; Vector3 min2,max2; Vector3 ex1 = MegaUtils.Extents(mod.verts, out min1, out max1); Vector3 ex2 = MegaUtils.Extents(tm.verts, out min2, out max2); // need min max on all axis so we can produce an offset to add float d1 = ex1.x; float d2 = ex2.x; float scl = d1 / d2; //d2 / d1; bool flipyz = false; bool negx = false; // So try to match first vert using autoscale and no flip bool mapped = DoMapping(mod, morph, tm, scl, flipyz, negx); if ( !mapped ) { flipyz = true; mapped = DoMapping(mod, morph, tm, scl, flipyz, negx); if ( !mapped ) //DoMapping(mod, morph, tm, mapping, scl, flipyz, negx) ) { flipyz = false; negx = true; mapped = DoMapping(mod, morph, tm, scl, flipyz, negx); if ( !mapped ) { flipyz = true; mapped = DoMapping(mod, morph, tm, scl, flipyz, negx); } } } if ( mapped ) { morph.importScale = scl; morph.flipyz = flipyz; morph.negx = negx; // if mapping was ok set opoints morph.oPoints = tm.verts.ToArray(); for ( int i = 0; i < morph.oPoints.Length; i++ ) { Vector3 p = morph.oPoints[i]; if ( negx ) p.x = -p.x; if ( flipyz ) { float z = p.z; p.z = p.y; p.y = z; } morph.oPoints[i] = p * morph.importScale; } morph.mapping = new MegaMomVertMap[morph.oPoints.Length]; for ( int i = 0; i < morph.oPoints.Length; i++ ) { //int[] indices = morph.FindVerts(morph.oPoints[i], mod); int[] indices = FindVerts(morph.oPoints[i], mod); morph.mapping[i] = new MegaMomVertMap(); morph.mapping[i].indices = indices; //morph.FindVerts(morph.oPoints[i], mod); } return true; } return false; }
// We should know the mapping // remove morph pass tolerance instead bool TryMapping1(MegaTargetMesh tm, MegaMorphOMatic morph) { MegaModifiers mod = morph.GetComponent <MegaModifiers>(); if (mod == null) { EditorUtility.DisplayDialog("Missing ModifyObject!", "No ModifyObject script found on the object", "OK"); return(false); } // Get extents for mod verts and for imported meshes, if not the same then scale Vector3 min1, max1; Vector3 min2, max2; Vector3 ex1 = MegaUtils.Extents(mod.verts, out min1, out max1); Vector3 ex2 = MegaUtils.Extents(tm.verts, out min2, out max2); // need min max on all axis so we can produce an offset to add float d1 = ex1.x; float d2 = ex2.x; float scl = d1 / d2; //d2 / d1; bool flipyz = false; bool negx = false; // So try to match first vert using autoscale and no flip bool mapped = DoMapping(mod, morph, tm, scl, flipyz, negx); if (!mapped) { flipyz = true; mapped = DoMapping(mod, morph, tm, scl, flipyz, negx); if (!mapped) //DoMapping(mod, morph, tm, mapping, scl, flipyz, negx) ) { flipyz = false; negx = true; mapped = DoMapping(mod, morph, tm, scl, flipyz, negx); if (!mapped) { flipyz = true; mapped = DoMapping(mod, morph, tm, scl, flipyz, negx); } } } if (mapped) { morph.importScale = scl; morph.flipyz = flipyz; morph.negx = negx; // if mapping was ok set opoints morph.oPoints = tm.verts.ToArray(); for (int i = 0; i < morph.oPoints.Length; i++) { Vector3 p = morph.oPoints[i]; if (negx) { p.x = -p.x; } if (flipyz) { float z = p.z; p.z = p.y; p.y = z; } morph.oPoints[i] = p * morph.importScale; } morph.mapping = new MegaMomVertMap[morph.oPoints.Length]; for (int i = 0; i < morph.oPoints.Length; i++) { //int[] indices = morph.FindVerts(morph.oPoints[i], mod); int[] indices = FindVerts(morph.oPoints[i], mod); morph.mapping[i] = new MegaMomVertMap(); morph.mapping[i].indices = indices; //morph.FindVerts(morph.oPoints[i], mod); } return(true); } return(false); }