コード例 #1
0
        /// <summary>
        /// Builds a line list containing a line for each face binormal.
        /// </summary>
        public List <Vector3> BuildLineListForFaceBinormals()
        {
            List <Vector3> result = new List <Vector3>();

            //Generate all lines
            foreach (Triangle actTriangle in this.Triangles)
            {
                //Get all vertices of current face
                GeometryData geo1 = m_owner.RawGeometry[actTriangle.Index1];
                GeometryData geo2 = m_owner.RawGeometry[actTriangle.Index2];
                GeometryData geo3 = m_owner.RawGeometry[actTriangle.Index3];

                //Get average values for current face
                Vector3 averageBinormal = Vector3.Normalize(Vector3Ex.Average(geo1.Binormal, geo2.Binormal, geo3.Binormal));
                Vector3 averagePosition = Vector3Ex.Average(geo1.Position, geo2.Position, geo3.Position);
                averageBinormal *= 0.2f;

                //Generate a line
                if (averageBinormal.Length() > 0.1f)
                {
                    result.Add(averagePosition);
                    result.Add(averagePosition + averageBinormal);
                }
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Copies this structure and replaces the given values
        /// </summary>
        public GeometryData Copy(Vector3 newPosition)
        {
            GeometryData result = this;

            result.m_position = newPosition;
            return(result);
        }
コード例 #3
0
        public Vertex AddVertex(
            int indexToCloneFrom = -1)
        {
            if (indexToCloneFrom > -1)
            {
                indexToCloneFrom.EnsureInRange(0, m_rawGeometry.Count - 1, nameof(indexToCloneFrom));

                GeometryData  geoData  = m_rawGeometry[indexToCloneFrom];
                TextureData   texData  = m_rawTexture != null ? m_rawTexture[indexToCloneFrom] : default(TextureData);
                AnimationData animData = m_rawAnimation != null ? m_rawAnimation[indexToCloneFrom] : default(AnimationData);

                m_rawGeometry.Add(geoData);
                m_rawTexture?.Add(texData);
                m_rawAnimation?.Add(animData);

                return(new Vertex(this, m_rawGeometry.Count - 1));
            }
            else
            {
                m_rawGeometry.Add(new GeometryData());
                if (m_rawAnimation != null)
                {
                    m_rawAnimation.Add(new AnimationData());
                }
                if (m_rawTexture != null)
                {
                    m_rawTexture.Add(new TextureData());
                }
                return(new Vertex(this, m_rawGeometry.Count - 1));
            }
        }
コード例 #4
0
        /// <summary>
        /// Copies this structure and replaces the given values
        /// </summary>
        public GeometryData Copy(Vector3 newPosition, Vector3 newNormal)
        {
            GeometryData result = this;

            result.m_position = newPosition;
            result.m_normal   = newNormal;
            return(result);
        }
コード例 #5
0
 /// <summary>
 /// Changes the color on each vertex.
 /// </summary>
 /// <param name="newColor">The new color.</param>
 public void SetColorOnEachVertex(Color4 newColor)
 {
     for (int loop = 0; loop < m_rawGeometry.Count; loop++)
     {
         GeometryData rawGeo = m_rawGeometry[loop];
         rawGeo.Color        = newColor;
         m_rawGeometry[loop] = rawGeo;
     }
 }
コード例 #6
0
        /// <summary>
        /// Calculates normals for all triangles specifyed by the given parameters.
        /// </summary>
        /// <param name="startVertex">The vertex index on which to start.</param>
        /// <param name="vertexCount">Total count of vertices to be updated.</param>
        public void CalculateNormals(int startVertex, int vertexCount)
        {
            if ((startVertex < 0) || (startVertex >= m_rawGeometry.Count))
            {
                throw new ArgumentException("startVertex");
            }
            if (vertexCount + startVertex > m_rawGeometry.Count)
            {
                throw new ArgumentException("vertexCount");
            }

            for (int actVertexIndex = startVertex; actVertexIndex < startVertex + vertexCount; actVertexIndex++)
            {
                // Find all triangles connected to this vertex and get normals from them
                Vector3 finalNormalHelper  = Vector3.Zero;
                Vector3 finalNormalHelper2 = Vector3.Zero;
                int     normalCount        = 0;

                int surfaceCount = m_surfaces.Count;
                for (int actSurfaceIndex = 0; actSurfaceIndex < surfaceCount; actSurfaceIndex++)
                {
                    VertexStructureSurface actSurface = m_surfaces[actSurfaceIndex];
                    int triangleCount = actSurface.CountTriangles;
                    for (int loopTriangle = 0; loopTriangle < triangleCount; loopTriangle++)
                    {
                        int triangleStartIndex = loopTriangle * 3;
                        if ((actSurface.IndicesInternal[triangleStartIndex] == actVertexIndex) ||
                            (actSurface.IndicesInternal[triangleStartIndex + 1] == actVertexIndex) ||
                            (actSurface.IndicesInternal[triangleStartIndex + 2] == actVertexIndex))
                        {
                            GeometryData geo1 = m_rawGeometry[actSurface.IndicesInternal[triangleStartIndex]];
                            GeometryData geo2 = m_rawGeometry[actSurface.IndicesInternal[triangleStartIndex + 1]];
                            GeometryData geo3 = m_rawGeometry[actSurface.IndicesInternal[triangleStartIndex + 2]];

                            finalNormalHelper += Vector3Ex.CalculateTriangleNormal(geo1.Position, geo2.Position, geo3.Position, false);

                            normalCount++;
                        }
                    }
                }

                // Calculate final normal
                if (normalCount > 0)
                {
                    GeometryData actGeometry = m_rawGeometry[actVertexIndex];
                    actGeometry.Normal            = finalNormalHelper / finalNormalHelper.Length();
                    m_rawGeometry[actVertexIndex] = actGeometry;
                    normalCount = 0;
                }
            }
        }