Exemple #1
0
        private static ThreeDSMesh.UV[] ParseTexVerts(DataReader3DS subSegment)
        {
            ThreeDSMesh.UV[] uv = new ThreeDSMesh.UV[subSegment.GetUShort()];

            for (int coord = 0; coord < uv.Length; coord++)
            {
                uv[coord].u = subSegment.GetFloat();
                uv[coord].v = subSegment.GetFloat();
            }

            return(uv);
        }
Exemple #2
0
        private static ThreeDSMesh ParsePolygonalData(DataReader3DS dataSegment)
        {
            DataReader3DS subSegment = dataSegment.GetNextSubSegment(); // working data subsegment

            ThreeDSMesh mesh = new ThreeDSMesh();

            while (subSegment != null)
            {
                switch ((ChunkCodes)subSegment.Tag)
                {
                case ChunkCodes.MESH_VERTICES:          // Subsegment contains vertex information
                    mesh.verticies = new ThreeDSMesh.Vertex[subSegment.GetUShort()];
                    for (int vertex = 0; vertex < mesh.verticies.Length; vertex++)
                    {
                        mesh.verticies[vertex].x = subSegment.GetFloat();
                        mesh.verticies[vertex].y = subSegment.GetFloat();
                        mesh.verticies[vertex].z = subSegment.GetFloat();
                    }
                    break;

                case ChunkCodes.MESH_XFMATRIX:          // Subsegment contains translation matrix info (ignore for now)
                    break;

                case ChunkCodes.MESH_FACES:     // Subsegment contains face information
                    mesh.groups.Add(ParseFaceData(subSegment));
                    break;

                case ChunkCodes.MESH_TEX_VERT:          // Subsegment contains texture mapping information
                    mesh.uvMap = ParseTexVerts(subSegment);
                    break;
                }
                subSegment = dataSegment.GetNextSubSegment();
            }

            // Also use face data to calculate vertex normals
            CalculateVertexNormals(mesh);

            return(mesh);
        }
Exemple #3
0
        private static ThreeDSMesh.Colour ParseColorData(DataReader3DS dataSegment)
        {
            ThreeDSMesh.Colour clr = new ThreeDSMesh.Colour();

            switch ((ChunkCodes)dataSegment.Tag)
            {
            case ChunkCodes.COLOR_F:            // Color is in float format
                clr.r = (byte)(1.0f / dataSegment.GetFloat());
                clr.g = (byte)(1.0f / dataSegment.GetFloat());
                clr.b = (byte)(1.0f / dataSegment.GetFloat());
                break;

            case ChunkCodes.COLOR_24:           // Color is in byte format
                clr.r = dataSegment.GetByte();
                clr.g = dataSegment.GetByte();
                clr.b = dataSegment.GetByte();
                break;

            default:                    // If there are any other formats, then we ignore them
                break;
            }

            return(clr);
        }
        private static ThreeDSMesh.Colour ParseColorData(DataReader3DS dataSegment)
        {
            ThreeDSMesh.Colour clr = new ThreeDSMesh.Colour();

            switch ((ChunkCodes)dataSegment.Tag)
            {
                case ChunkCodes.COLOR_F:	// Color is in float format
                    clr.r = (byte)(1.0f / dataSegment.GetFloat());
                    clr.g = (byte)(1.0f / dataSegment.GetFloat());
                    clr.b = (byte)(1.0f / dataSegment.GetFloat());
                    break;
                case ChunkCodes.COLOR_24:	// Color is in byte format
                    clr.r = dataSegment.GetByte();
                    clr.g = dataSegment.GetByte();
                    clr.b = dataSegment.GetByte();
                    break;
                default:		// If there are any other formats, then we ignore them
                    break;
            }

            return clr;
        }
        private static ThreeDSMesh.UV[] ParseTexVerts(DataReader3DS subSegment)
        {
            ThreeDSMesh.UV[] uv = new ThreeDSMesh.UV[subSegment.GetUShort()];

            for (int coord = 0; coord < uv.Length; coord++)
            {
                uv[coord].u = subSegment.GetFloat();
                uv[coord].v = subSegment.GetFloat();
            }

            return uv;
        }