// Out of this we need scl, negx, negz and flipyz bool TryMapping1(Vector3[] tverts, Vector3[] verts) { //for ( int i = 0; i < 4; i++ ) // Debug.Log("cache vert " + tverts[i].ToString("0.00000")); //for ( int i = 0; i < 4; i++ ) // Debug.Log("mesh vert " + verts[i].ToString("0.00000")); // Get extents for mod verts and for imported meshes, if not the same then scale Vector3 min1, max1; Vector3 min2, max2; Vector3 ex1 = Extents(verts, out min1, out max1); Vector3 ex2 = Extents(tverts, out min2, out max2); //Debug.Log("mesh extents " + ex1.ToString("0.00000")); //Debug.Log("cache extents " + ex2.ToString("0.00000")); //Debug.Log("mesh min " + min1.ToString("0.00000")); //Debug.Log("cache min " + min2.ToString("0.00000")); //Debug.Log("mesh max " + max1.ToString("0.00000")); //Debug.Log("cache max " + max2.ToString("0.00000")); int largest1 = MegaUtils.LargestComponent(ex1); int largest2 = MegaUtils.LargestComponent(ex2); //Debug.Log(largest1 + " " + largest2); scl = ex1[largest1] / ex2[largest2]; //Debug.Log("scl " + scl); //Vector3 offset = verts[0] - (tverts[0] * scl); //Debug.Log("Offset " + offset.ToString("0.00000")); // need min max on all axis so we can produce an offset to add int map = 0; for (map = 0; map < 8; map++) { flipyz = ((map & 4) != 0); negx = ((map & 2) != 0); negz = ((map & 1) != 0); bool mapped = DoMapping(verts, tverts, scl, flipyz, negx, negz); if (mapped) { break; } } if (map == 8) // We couldnt find any mapping { return(false); } //Debug.Log("scl " + scl + " negx " + negx + " negz " + negz + " flipyz " + flipyz); return(true); }
void AdjustVerts(MegaModifiers mods, MegaPointCache am) { if (am.Verts != null) { Vector3[] baseverts = new Vector3[am.Verts.Length]; for (int i = 0; i < am.Verts.Length; i++) { baseverts[i] = am.Verts[i].points[0]; } Vector3 min1, max1; Vector3 min2, max2; Vector3 ex1 = Extents(mods.verts, out min1, out max1); Vector3 ex2 = Extents(baseverts, out min2, out max2); //Debug.Log("mesh extents " + ex1.ToString("0.00000")); //Debug.Log("cache extents " + ex2.ToString("0.00000")); //Debug.Log("mesh min " + min1.ToString("0.00000")); //Debug.Log("cache min " + min2.ToString("0.00000")); //Debug.Log("mesh max " + max1.ToString("0.00000")); //Debug.Log("cache max " + max2.ToString("0.00000")); int largest1 = MegaUtils.LargestComponent(ex1); int largest2 = MegaUtils.LargestComponent(ex2); //Debug.Log(largest1 + " " + largest2); am.adjustscl = ex1[largest1] / ex2[largest2]; //Debug.Log("scl " + scl1.ToString("0.0000")); //off = verts[0] - (tverts[0] * scl); am.adjustoff = (min2 * am.adjustscl) - min1; //Debug.Log("scl " + am.adjustscl); //Debug.Log("off " + am.adjustoff); for (int i = 0; i < am.Verts.Length; i++) { for (int j = 0; j < am.Verts[i].points.Length; j++) { Vector3 p = am.Verts[i].points[j] * am.adjustscl; am.Verts[i].points[j] = p - am.adjustoff; } } } }