private MeshmerizerMesh GenerateMeshmerizerMesh(Primitive prim) { PrimitiveBaseShape primShape = new PrimitiveBaseShape(prim); MeshmerizerMesh mesh = new MeshmerizerMesh(); float pathShearX = primShape.PathShearX < 128 ? (float)primShape.PathShearX * 0.01f : (float)(primShape.PathShearX - 256) * 0.01f; float pathShearY = primShape.PathShearY < 128 ? (float)primShape.PathShearY * 0.01f : (float)(primShape.PathShearY - 256) * 0.01f; float pathBegin = (float)primShape.PathBegin * 2.0e-5f; float pathEnd = 1.0f - (float)primShape.PathEnd * 2.0e-5f; float pathScaleX = (float)(primShape.PathScaleX - 100) * 0.01f; float pathScaleY = (float)(primShape.PathScaleY - 100) * 0.01f; float profileBegin = (float)primShape.ProfileBegin * 2.0e-5f; float profileEnd = 1.0f - (float)primShape.ProfileEnd * 2.0e-5f; float profileHollow = (float)primShape.ProfileHollow * 2.0e-5f; int sides = 4; if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle) sides = 3; else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.Circle) sides = 24; else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle) { // half circle, prim is a sphere sides = 24; profileBegin = 0.5f * profileBegin + 0.5f; profileEnd = 0.5f * profileEnd + 0.5f; } int hollowSides = sides; if (primShape.HollowShape == HollowShape.Circle) hollowSides = 24; else if (primShape.HollowShape == HollowShape.Square) hollowSides = 4; else if (primShape.HollowShape == HollowShape.Triangle) hollowSides = 3; PrimMesh primMesh = new PrimMesh(sides, profileBegin, profileEnd, profileHollow, hollowSides); primMesh.topShearX = pathShearX; primMesh.topShearY = pathShearY; primMesh.pathCutBegin = pathBegin; primMesh.pathCutEnd = pathEnd; if (primShape.PathCurve == (byte)Extrusion.Straight) { primMesh.twistBegin = primShape.PathTwistBegin * 18 / 10; primMesh.twistEnd = primShape.PathTwist * 18 / 10; primMesh.taperX = pathScaleX; primMesh.taperY = pathScaleY; try { primMesh.ExtrudeLinear(); } catch (Exception) { return null; } } else { primMesh.holeSizeX = (200 - primShape.PathScaleX) * 0.01f; primMesh.holeSizeY = (200 - primShape.PathScaleY) * 0.01f; primMesh.radius = 0.01f * primShape.PathRadiusOffset; primMesh.revolutions = 1.0f + 0.015f * primShape.PathRevolutions; primMesh.skew = 0.01f * primShape.PathSkew; primMesh.twistBegin = primShape.PathTwistBegin * 36 / 10; primMesh.twistEnd = primShape.PathTwist * 36 / 10; primMesh.taperX = primShape.PathTaperX * 0.01f; primMesh.taperY = primShape.PathTaperY * 0.01f; try { primMesh.ExtrudeCircular(); } catch (Exception) { return null; } } int numCoords = primMesh.coords.Count; //int numFaces = primMesh.faces.Count; List<Coord> coords = primMesh.coords; for (int i = 0; i < numCoords; i++) { Coord c = coords[i]; mesh.vertices.Add(new MeshmerizerVertex(c.X, c.Y, c.Z)); } mesh.primMesh = primMesh; // trim the vertex and triangle lists to free up memory mesh.vertices.TrimExcess(); mesh.triangles.TrimExcess(); return mesh; }
// Local routine to create a mesh from prim parameters. // Collects parameters and calls PrimMesher to create all the faces of the prim. private LibreMetaverse.PrimMesher.PrimMesh GeneratePrimMesh(Primitive prim, DetailLevel lod, bool viewerMode) { Primitive.ConstructionData primData = prim.PrimData; int sides = 4; int hollowsides = 4; float profileBegin = primData.ProfileBegin; float profileEnd = primData.ProfileEnd; bool isSphere = false; if ((ProfileCurve)(primData.profileCurve & 0x07) == OMV.ProfileCurve.Circle) { switch (lod) { case OMVR.DetailLevel.Low: sides = 6; break; case OMVR.DetailLevel.Medium: sides = 12; break; default: sides = 24; break; } } else if ((ProfileCurve)(primData.profileCurve & 0x07) == OMV.ProfileCurve.EqualTriangle) { sides = 3; } else if ((ProfileCurve)(primData.profileCurve & 0x07) == OMV.ProfileCurve.HalfCircle) { // half circle, prim is a sphere isSphere = true; switch (lod) { case OMVR.DetailLevel.Low: sides = 6; break; case OMVR.DetailLevel.Medium: sides = 12; break; default: sides = 24; break; } profileBegin = 0.5f * profileBegin + 0.5f; profileEnd = 0.5f * profileEnd + 0.5f; } if (primData.ProfileHole == HoleType.Same) { hollowsides = sides; } else if (primData.ProfileHole == HoleType.Circle) { switch (lod) { case DetailLevel.Low: hollowsides = 6; break; case DetailLevel.Medium: hollowsides = 12; break; default: hollowsides = 24; break; } } else if (primData.ProfileHole == HoleType.Triangle) { hollowsides = 3; } PrimMesh newPrim = new PrimMesh(sides, profileBegin, profileEnd, primData.ProfileHollow, hollowsides) { viewerMode = viewerMode, sphereMode = isSphere, holeSizeX = primData.PathScaleX, holeSizeY = primData.PathScaleY, pathCutBegin = primData.PathBegin, pathCutEnd = primData.PathEnd, topShearX = primData.PathShearX, topShearY = primData.PathShearY, radius = primData.PathRadiusOffset, revolutions = primData.PathRevolutions, skew = primData.PathSkew }; switch (lod) { case DetailLevel.Low: newPrim.stepsPerRevolution = 6; break; case DetailLevel.Medium: newPrim.stepsPerRevolution = 12; break; default: newPrim.stepsPerRevolution = 24; break; } if (primData.PathCurve == PathCurve.Line || primData.PathCurve == PathCurve.Flexible) { newPrim.taperX = 1.0f - primData.PathScaleX; newPrim.taperY = 1.0f - primData.PathScaleY; newPrim.twistBegin = (int)(180 * primData.PathTwistBegin); newPrim.twistEnd = (int)(180 * primData.PathTwist); newPrim.ExtrudeLinear(); } else { newPrim.taperX = primData.PathTaperX; newPrim.taperY = primData.PathTaperY; newPrim.twistBegin = (int)(360 * primData.PathTwistBegin); newPrim.twistEnd = (int)(360 * primData.PathTwist); newPrim.ExtrudeCircular(); } return(newPrim); }
private MeshmerizerMesh GenerateMeshmerizerMesh(Primitive prim) { PrimitiveBaseShape primShape = new PrimitiveBaseShape(prim); MeshmerizerMesh mesh = new MeshmerizerMesh(); float pathShearX = primShape.PathShearX < 128 ? (float)primShape.PathShearX * 0.01f : (float)(primShape.PathShearX - 256) * 0.01f; float pathShearY = primShape.PathShearY < 128 ? (float)primShape.PathShearY * 0.01f : (float)(primShape.PathShearY - 256) * 0.01f; float pathBegin = (float)primShape.PathBegin * 2.0e-5f; float pathEnd = 1.0f - (float)primShape.PathEnd * 2.0e-5f; float pathScaleX = (float)(primShape.PathScaleX - 100) * 0.01f; float pathScaleY = (float)(primShape.PathScaleY - 100) * 0.01f; float profileBegin = (float)primShape.ProfileBegin * 2.0e-5f; float profileEnd = 1.0f - (float)primShape.ProfileEnd * 2.0e-5f; float profileHollow = (float)primShape.ProfileHollow * 2.0e-5f; int sides = 4; if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle) { sides = 3; } else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.Circle) { sides = 24; } else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle) { // half circle, prim is a sphere sides = 24; profileBegin = 0.5f * profileBegin + 0.5f; profileEnd = 0.5f * profileEnd + 0.5f; } int hollowSides = sides; if (primShape.HollowShape == HollowShape.Circle) { hollowSides = 24; } else if (primShape.HollowShape == HollowShape.Square) { hollowSides = 4; } else if (primShape.HollowShape == HollowShape.Triangle) { hollowSides = 3; } PrimMesh primMesh = new PrimMesh(sides, profileBegin, profileEnd, profileHollow, hollowSides); primMesh.topShearX = pathShearX; primMesh.topShearY = pathShearY; primMesh.pathCutBegin = pathBegin; primMesh.pathCutEnd = pathEnd; if (primShape.PathCurve == (byte)Extrusion.Straight) { primMesh.twistBegin = primShape.PathTwistBegin * 18 / 10; primMesh.twistEnd = primShape.PathTwist * 18 / 10; primMesh.taperX = pathScaleX; primMesh.taperY = pathScaleY; try { primMesh.ExtrudeLinear(); } catch (Exception) { return(null); } } else { primMesh.holeSizeX = (200 - primShape.PathScaleX) * 0.01f; primMesh.holeSizeY = (200 - primShape.PathScaleY) * 0.01f; primMesh.radius = 0.01f * primShape.PathRadiusOffset; primMesh.revolutions = 1.0f + 0.015f * primShape.PathRevolutions; primMesh.skew = 0.01f * primShape.PathSkew; primMesh.twistBegin = primShape.PathTwistBegin * 36 / 10; primMesh.twistEnd = primShape.PathTwist * 36 / 10; primMesh.taperX = primShape.PathTaperX * 0.01f; primMesh.taperY = primShape.PathTaperY * 0.01f; try { primMesh.ExtrudeCircular(); } catch (Exception) { return(null); } } int numCoords = primMesh.coords.Count; //int numFaces = primMesh.faces.Count; List <Coord> coords = primMesh.coords; for (int i = 0; i < numCoords; i++) { Coord c = coords[i]; mesh.vertices.Add(new MeshmerizerVertex(c.X, c.Y, c.Z)); } mesh.primMesh = primMesh; // trim the vertex and triangle lists to free up memory mesh.vertices.TrimExcess(); mesh.triangles.TrimExcess(); return(mesh); }