Exemplo n.º 1
0
        /// <summary>
        /// Adds a value to each XYZ vertex coordinate in the mesh
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        public void AddPos(float x, float y, float z)
        {
            int   i;
            int   numVerts = this.coords.Count;
            Coord vert;

            for (i = 0; i < numVerts; i++)
            {
                vert           = this.coords[i];
                vert.X        += x;
                vert.Y        += y;
                vert.Z        += z;
                this.coords[i] = vert;
            }

            if (this.viewerFaces != null)
            {
                int numViewerFaces = this.viewerFaces.Count;

                for (i = 0; i < numViewerFaces; i++)
                {
                    ViewerFace v = this.viewerFaces[i];
                    v.AddPos(x, y, z);
                    this.viewerFaces[i] = v;
                }
            }
        }
Exemplo n.º 2
0
        public void Scale(float x, float y, float z)
        {
            int i;
            int numVerts = this.coords.Count;

            Coord m = new Coord(x, y, z);

            for (i = 0; i < numVerts; i++)
            {
                this.coords[i] *= m;
            }

            if (this.viewerFaces != null)
            {
                int numViewerFaces = this.viewerFaces.Count;
                for (i = 0; i < numViewerFaces; i++)
                {
                    ViewerFace v = this.viewerFaces[i];
                    v.v1 *= m;
                    v.v2 *= m;
                    v.v3 *= m;
                    this.viewerFaces[i] = v;
                }
            }
        }
Exemplo n.º 3
0
        public void AddRot(Quat q)
        {
            int i;
            int numVerts = this.coords.Count;

            for (i = 0; i < numVerts; i++)
            {
                this.coords[i] *= q;
            }

            if (this.viewerFaces != null)
            {
                int numViewerFaces = this.viewerFaces.Count;

                for (i = 0; i < numViewerFaces; i++)
                {
                    ViewerFace v = this.viewerFaces[i];
                    v.v1 *= q;
                    v.v2 *= q;
                    v.v3 *= q;

                    v.n1 *= q;
                    v.n2 *= q;
                    v.n3 *= q;

                    this.viewerFaces[i] = v;
                }
            }
        }
Exemplo n.º 4
0
        private void calcVertexNormals(SculptType sculptType, int xSize, int ySize)
        {
            // compute vertex normals by summing all the surface normals of all the triangles sharing
            // each vertex and then normalizing
            var numFaces = faces.Count;

            for (var i = 0; i < numFaces; i++)
            {
                var face          = faces[i];
                var surfaceNormal = face.SurfaceNormal(coords);
                normals[face.n1] += surfaceNormal;
                normals[face.n2] += surfaceNormal;
                normals[face.n3] += surfaceNormal;
            }

            var numNormals = normals.Count;

            for (var i = 0; i < numNormals; i++)
            {
                normals[i] = normals[i].Normalize();
            }

            if (sculptType != SculptType.plane)
            {
                for (var y = 0; y < ySize; y++)
                {
                    var rowOffset = y * xSize;

                    normals[rowOffset] = normals[rowOffset + xSize - 1] =
                        (normals[rowOffset] + normals[rowOffset + xSize - 1]).Normalize();
                }
            }

            foreach (var face in faces)
            {
                var vf = new ViewerFace(0);
                vf.v1 = coords[face.v1];
                vf.v2 = coords[face.v2];
                vf.v3 = coords[face.v3];

                vf.coordIndex1 = face.v1;
                vf.coordIndex2 = face.v2;
                vf.coordIndex3 = face.v3;

                vf.n1 = normals[face.n1];
                vf.n2 = normals[face.n2];
                vf.n3 = normals[face.n3];

                vf.uv1 = uvs[face.uv1];
                vf.uv2 = uvs[face.uv2];
                vf.uv3 = uvs[face.uv3];

                viewerFaces.Add(vf);
            }
        }
Exemplo n.º 5
0
        private void calcVertexNormals(SculptType sculptType, int xSize, int ySize)
        {  // compute vertex normals by summing all the surface normals of all the triangles sharing
            // each vertex and then normalizing
            int numFaces = this.faces.Count;

            for (int i = 0; i < numFaces; i++)
            {
                Face  face          = this.faces[i];
                Coord surfaceNormal = face.SurfaceNormal(this.coords);
                this.normals[face.n1] += surfaceNormal;
                this.normals[face.n2] += surfaceNormal;
                this.normals[face.n3] += surfaceNormal;
            }

            int numNormals = this.normals.Count;

            for (int i = 0; i < numNormals; i++)
            {
                this.normals[i] = this.normals[i].Normalize();
            }

            if (sculptType != SculptType.plane)
            { // blend the vertex normals at the cylinder seam
                for (int y = 0; y < ySize; y++)
                {
                    int rowOffset = y * xSize;

                    this.normals[rowOffset] = this.normals[rowOffset + xSize - 1] = (this.normals[rowOffset] + this.normals[rowOffset + xSize - 1]).Normalize();
                }
            }

            foreach (Face face in this.faces)
            {
                ViewerFace vf = new ViewerFace(0);
                vf.v1 = this.coords[face.v1];
                vf.v2 = this.coords[face.v2];
                vf.v3 = this.coords[face.v3];

                vf.coordIndex1 = face.v1;
                vf.coordIndex2 = face.v2;
                vf.coordIndex3 = face.v3;

                vf.n1 = this.normals[face.n1];
                vf.n2 = this.normals[face.n2];
                vf.n3 = this.normals[face.n3];

                vf.uv1 = this.uvs[face.uv1];
                vf.uv2 = this.uvs[face.uv2];
                vf.uv3 = this.uvs[face.uv3];

                this.viewerFaces.Add(vf);
            }
        }
Exemplo n.º 6
0
        public static Mesh ToMesh(
#if (COLLIDER_ODE)
            PrimitiveBaseShape pbs,
#endif
            List <Coord> coords, List <Face> faces, List <ViewerFace> viewerFaces, bool isSphere)
        {
            Mesh mesh = new Mesh(

#if COLLIDER_ODE
                pbs
#endif

                );

            int numCoords = coords.Count;
            int numFaces  = faces.Count;

            for (int i = 0; i < numCoords; i++)
            {
                Coord c = coords[i];
                mesh.vertices.Add(new Vertex(c.X, c.Y, c.Z));
            }

            List <Vertex> vertices = mesh.vertices;

            for (int i = 0; i < numFaces; i++)
            {
                Face f = faces[i];
                mesh.triangles.Add(new Triangle(vertices[f.v1], vertices[f.v2], vertices[f.v3]));
            }
            if (UseViewerMode && viewerFaces != null)
            {
                int numViewerFaces = viewerFaces.Count;
                for (uint i = 0; i < numViewerFaces; i++)
                {
                    ViewerFace vf = viewerFaces[(int)i];

                    if (isSphere)
                    {
                        vf.uv1.U = (vf.uv1.U - 0.5f) * 2.0f;
                        vf.uv2.U = (vf.uv2.U - 0.5f) * 2.0f;
                        vf.uv3.U = (vf.uv3.U - 0.5f) * 2.0f;
                    }
                }
            }
            return(mesh);
        }
Exemplo n.º 7
0
        bool IsValidFace(ViewerFace vf)
        {
            if (Math.Abs(vf.n1.X) + Math.Abs(vf.n1.Y) + Math.Abs(vf.n1.Z) < 0.2f)
            {
                return(false);
            }
            if (Math.Abs(vf.n2.X) + Math.Abs(vf.n2.Y) + Math.Abs(vf.n2.Z) < 0.2f)
            {
                return(false);
            }
            if (Math.Abs(vf.n3.X) + Math.Abs(vf.n3.Y) + Math.Abs(vf.n3.Z) < 0.2f)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Rotates the mesh
        /// </summary>
        /// <param name="q"></param>
        public void AddRot(Quat q)
        {
            if (q.X == 0 && q.Y == 0 && q.Z == 0 && q.W == 1)
            {
                return;
            }

            int i;
            int numVerts = this.coords.Count;

            for (i = 0; i < numVerts; i++)
            {
                this.coords[i] *= q;
            }

            int numNormals = this.normals.Count;

            for (i = 0; i < numNormals; i++)
            {
                this.normals[i] *= q;
            }

            if (this.viewerFaces != null)
            {
                int numViewerFaces = this.viewerFaces.Count;

                for (i = 0; i < numViewerFaces; i++)
                {
                    ViewerFace v = this.viewerFaces[i];
                    v.v1 *= q;
                    v.v2 *= q;
                    v.v3 *= q;

                    v.n1 *= q;
                    v.n2 *= q;
                    v.n3 *= q;

                    this.viewerFaces[i] = v;
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Rotates the mesh
        /// </summary>
        /// <param name="q"></param>
        public void AddRot(Quat q)
        {
            int i;
            int numVerts = coords.Count;

            for (i = 0; i < numVerts; i++)
            {
                coords[i] *= q;
            }

            int numNormals = normals.Count;

            for (i = 0; i < numNormals; i++)
            {
                normals[i] *= q;
            }

            if (viewerFaces != null)
            {
                int numViewerFaces = viewerFaces.Count;

                for (i = 0; i < numViewerFaces; i++)
                {
                    ViewerFace v = viewerFaces[i];
                    v.v1 *= q;
                    v.v2 *= q;
                    v.v3 *= q;

                    v.n1 *= q;
                    v.n2 *= q;
                    v.n3 *= q;

                    viewerFaces[i] = v;
                }
            }
        }
Exemplo n.º 10
0
        // from IdealistViewer.PrimMesherG.cs
        public PrimMesh ConstructionDataToPrimMesh(Primitive.ConstructionData primData, LevelOfDetail detail, float detailMult)
        {
            this.sides       = 4;
            this.hollowsides = 4;

            float profileBegin = primData.ProfileBegin;
            float profileEnd   = primData.ProfileEnd;
            bool  isSphere     = false;

            if ((ProfileCurve)(primData.profileCurve & 0x07) == ProfileCurve.Circle)
            {
                switch (detail)
                {
                case LevelOfDetail.Low:
                    sides = 6;
                    break;

                case LevelOfDetail.Medium:
                    sides = 12;
                    break;

                default:
                    sides = 24;
                    break;
                }
            }
            else if ((ProfileCurve)(primData.profileCurve & 0x07) == ProfileCurve.EqualTriangle)
            {
                sides = 3;
            }
            else if ((ProfileCurve)(primData.profileCurve & 0x07) == ProfileCurve.HalfCircle)
            { // half circle, prim is a sphere
                isSphere = true;
                switch (detail)
                {
                case LevelOfDetail.Low:
                    sides = 6;
                    break;

                case LevelOfDetail.Medium:
                    sides = 12;
                    break;

                default:
                    sides = 24;
                    break;
                }
                profileBegin = 0.5f * profileBegin + 0.5f;
                profileEnd   = 0.5f * profileEnd + 0.5f;
            }

            if ((HoleType)primData.ProfileHole == HoleType.Same)
            {
                hollowsides = sides;
            }
            else if ((HoleType)primData.ProfileHole == HoleType.Circle)
            {
                switch (detail)
                {
                case LevelOfDetail.Low:
                    hollowsides = 6;
                    break;

                case LevelOfDetail.Medium:
                    hollowsides = 12;
                    break;

                default:
                    hollowsides = 24;
                    break;
                }
            }
            else if ((HoleType)primData.ProfileHole == HoleType.Triangle)
            {
                hollowsides = 3;
            }

            //  if (UseExtremeDetail)
            {
                sides       = (int)(sides * detailMult);
                hollowsides = (int)(hollowsides * detailMult);
            }
            PrimMesh primMesh = new PrimMesh(sides, profileBegin, profileEnd, (float)primData.ProfileHollow, hollowsides);

            primMesh.viewerMode   = UseViewerMode;
            primMesh.holeSizeX    = primData.PathScaleX;
            primMesh.holeSizeY    = primData.PathScaleY;
            primMesh.pathCutBegin = primData.PathBegin;
            primMesh.pathCutEnd   = primData.PathEnd;
            primMesh.topShearX    = primData.PathShearX;
            primMesh.topShearY    = primData.PathShearY;
            primMesh.radius       = primData.PathRadiusOffset;
            primMesh.revolutions  = primData.PathRevolutions;
            primMesh.skew         = primData.PathSkew;
            switch (detail)
            {
            case LevelOfDetail.Low:
                primMesh.stepsPerRevolution = 6;
                break;

            case LevelOfDetail.Medium:
                primMesh.stepsPerRevolution = 12;
                break;

            default:
                primMesh.stepsPerRevolution = 24;
                break;
            }

            //if (UseExtremeDetail)
            {
                primMesh.stepsPerRevolution = (int)(primMesh.stepsPerRevolution * detailMult);
            }


            if (primData.PathCurve == PathCurve.Line)
            {
                primMesh.taperX     = 1.0f - primData.PathScaleX;
                primMesh.taperY     = 1.0f - primData.PathScaleY;
                primMesh.twistBegin = (int)(180 * primData.PathTwistBegin);
                primMesh.twistEnd   = (int)(180 * primData.PathTwist);
                primMesh.ExtrudeLinear();
            }
            else
            {
                primMesh.taperX     = primData.PathTaperX;
                primMesh.taperY     = primData.PathTaperY;
                primMesh.twistBegin = (int)(360 * primData.PathTwistBegin);
                primMesh.twistEnd   = (int)(360 * primData.PathTwist);
                primMesh.ExtrudeCircular();
            }


            if (UseViewerMode)
            {
                int numViewerFaces = primMesh.viewerFaces.Count;
                for (uint i = 0; i < numViewerFaces; i++)
                {
                    ViewerFace vf = primMesh.viewerFaces[(int)i];

                    if (isSphere)
                    {
                        vf.uv1.U = (vf.uv1.U - 0.5f) * 2.0f;
                        vf.uv2.U = (vf.uv2.U - 0.5f) * 2.0f;
                        vf.uv3.U = (vf.uv3.U - 0.5f) * 2.0f;
                    }
                }
            }
            return(primMesh);
        }