Example #1
0
        private static ThreeDSMesh.FaceGroup ParseFaceData(DataReader3DS dataSegment)
        {
            DataReader3DS subSegment;   // will be used to read other subsegments (do not initialize yet)

            ThreeDSMesh.FaceGroup group = new ThreeDSMesh.FaceGroup();
            group.faces = new ThreeDSMesh.Face[dataSegment.GetUShort()];

            // Read face data
            for (int face = 0; face < group.faces.Length; face++)
            {
                group.faces[face].p1 = dataSegment.GetUShort();
                group.faces[face].p2 = dataSegment.GetUShort();
                group.faces[face].p3 = dataSegment.GetUShort();
                // Ignore flag
                dataSegment.GetUShort();
            }

            // Read other subsegments
            subSegment = dataSegment.GetNextSubSegment();
            while (subSegment != null)
            {
                switch ((ChunkCodes)subSegment.Tag)
                {
                case ChunkCodes.MESH_MATER:     // Name of material used
                    group.mappings.Add(ParseMeshMaterial(subSegment));
                    break;

                case ChunkCodes.TRI_SMOOTH:
                    break;
                }
                subSegment = dataSegment.GetNextSubSegment();
            }

            return(group);
        }
Example #2
0
        private static ThreeDSObject ParseMeshData(DataReader3DS dataSegment)
        {
            string        name       = dataSegment.GetString();
            DataReader3DS subSegment = dataSegment.GetNextSubSegment();

            ThreeDSObject obj = new ThreeDSObject();

            obj.name = name;

            while (subSegment != null)
            {
                switch ((ChunkCodes)subSegment.Tag)
                {
                case ChunkCodes.OBJ_MESH:       // Current subsegment contains the polygonal information
                    obj.meshes.Add(ParsePolygonalData(subSegment));
                    break;

                default:                // Ignore all other subsegment types
                    break;
                }
                subSegment = dataSegment.GetNextSubSegment();
            }

            return(obj);
        }
Example #3
0
        private static ThreeDSMesh.Material ParseMaterialData(DataReader3DS dataSegment)
        {
            DataReader3DS subSegment = dataSegment.GetNextSubSegment();

            ThreeDSMesh.Material mat = new ThreeDSMesh.Material();

            while (subSegment != null)
            {
                switch ((ChunkCodes)subSegment.Tag)
                {
                case ChunkCodes.MAT_NAME:       // Subsegment holds material name
                    mat.name = subSegment.GetString();
                    break;

                case ChunkCodes.MAT_AMBIENT:            // Subsegment holds ambient color
                    mat.ambient = ParseColorData(subSegment.GetNextSubSegment());
                    break;

                case ChunkCodes.MAT_DIFFUSE:            // Subsegment holds diffuse color (this is iffy...)
                    mat.diffuse = ParseColorData(subSegment.GetNextSubSegment());
                    break;

                case ChunkCodes.MAT_TEXMAP:     // Subsegment holds texture map info
                    /*ParseTextureWeight(*/ subSegment.GetNextSubSegment();
                    mat.texture = subSegment.GetNextSubSegment().GetString();
                    break;

                default:                // Ignore all other subsegment types
                    break;
                }
                subSegment = dataSegment.GetNextSubSegment();
            }

            // Check if this is a duplicate material entry (by name)
            // NOTE: Duplicate material name update should be in form materialname_submeshname

            /*if (materialDataStore.ContainsKey(currentMaterialData.name))
             * {
             *  // Select an "owning" submesh for the material
             *  referencingSubmeshes = (ArrayList)(submeshesUsingMaterials[currentMaterialData.name]);
             *  owningSubmesh = (SubmeshData3DS)(referencingSubmeshes[referencingSubmeshes.Count - 1]);
             *  // Qualify the material name with the submesh's name as well (see above note)
             *  currentMaterialData.name = currentMaterialData.name + "_" + owningSubmesh.name;
             *  owningSubmesh.materialUsed = currentMaterialData.name;
             *  // Clean up and update submesh reference lists
             *  referencingSubmeshes.RemoveAt(referencingSubmeshes.Count - 1);
             *  referencingSubmeshes = new ArrayList();
             *  referencingSubmeshes.Add(owningSubmesh);
             *  submeshesUsingMaterials.Add(currentMaterialData.name, referencingSubmeshes);
             * }*/

            return(mat);
        }
Example #4
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);
        }
Example #5
0
        private static void Parse3DSData(DataReader3DS dataSegment, ThreeDSFileData file)
        {
            DataReader3DS subSegment = dataSegment.GetNextSubSegment();

            while (subSegment != null)
            {
                switch ((ChunkCodes)subSegment.Tag)
                {
                case ChunkCodes.MATERIAL:
                    file.materials.Add(ParseMaterialData(subSegment));
                    break;

                case ChunkCodes.NAMED_OBJECT:
                    file.objects.Add(ParseMeshData(subSegment));
                    break;

                default:
                    break;
                }
                subSegment = dataSegment.GetNextSubSegment();
            }
        }
Example #6
0
        static ThreeDSFileData ParseFromData(DataReader3DS data)
        {
            DataReader3DS dataSubSegment = null;

            if ((ChunkCodes)data.Tag == ChunkCodes.PRIMARY)
            {
                dataSubSegment = data.GetNextSubSegment();
            }
            else
            {
                return(null);
            }

            ThreeDSFileData file = new ThreeDSFileData();

            while (dataSubSegment != null)
            {
                // Check the tag to see what sort of data is in this subsegment (or "chunk")
                switch ((ChunkCodes)dataSubSegment.Tag)
                {
                case ChunkCodes.VERSION:
                    file.version = dataSubSegment.GetUShort();
                    break;

                case ChunkCodes.EDIT3DS:
                    Parse3DSData(dataSubSegment, file);
                    break;

                default:
                    break;
                }
                dataSubSegment = data.GetNextSubSegment();
            }

            return(file);
        }
Example #7
0
        static ThreeDSFileData ParseFromData(DataReader3DS data)
        {
            DataReader3DS dataSubSegment = null;

            if ((ChunkCodes)data.Tag == ChunkCodes.PRIMARY)
            {
                dataSubSegment = data.GetNextSubSegment();
            }
            else
                return null;

            ThreeDSFileData file = new ThreeDSFileData();

            while (dataSubSegment != null)
            {
                // Check the tag to see what sort of data is in this subsegment (or "chunk")
                switch ((ChunkCodes)dataSubSegment.Tag)
                {
                    case ChunkCodes.VERSION:
                        file.version = dataSubSegment.GetUShort();
                        break;
                    case ChunkCodes.EDIT3DS:
                        Parse3DSData(dataSubSegment, file);
                        break;
                    default:
                        break;
                }
                dataSubSegment = data.GetNextSubSegment();
            }

            return file;
        }
Example #8
0
        private static ThreeDSMesh.Material ParseMaterialData(DataReader3DS dataSegment)
        {
            DataReader3DS subSegment = dataSegment.GetNextSubSegment();
            ThreeDSMesh.Material mat = new ThreeDSMesh.Material();

            while (subSegment != null)
            {
                switch ((ChunkCodes)subSegment.Tag)
                {
                    case ChunkCodes.MAT_NAME:	// Subsegment holds material name
                        mat.name = subSegment.GetString();
                        break;
                    case ChunkCodes.MAT_AMBIENT:	// Subsegment holds ambient color
                        mat.ambient = ParseColorData(subSegment.GetNextSubSegment());
                        break;
                    case ChunkCodes.MAT_DIFFUSE:	// Subsegment holds diffuse color (this is iffy...)
                        mat.diffuse = ParseColorData(subSegment.GetNextSubSegment());
                        break;
                    case ChunkCodes.MAT_TEXMAP:	// Subsegment holds texture map info
                        /*ParseTextureWeight(*/subSegment.GetNextSubSegment();
                        mat.texture = subSegment.GetNextSubSegment().GetString();
                        break;
                    default:		// Ignore all other subsegment types
                        break;
                }
                subSegment = dataSegment.GetNextSubSegment();
            }

            // Check if this is a duplicate material entry (by name)
            // NOTE: Duplicate material name update should be in form materialname_submeshname
            /*if (materialDataStore.ContainsKey(currentMaterialData.name))
            {
                // Select an "owning" submesh for the material
                referencingSubmeshes = (ArrayList)(submeshesUsingMaterials[currentMaterialData.name]);
                owningSubmesh = (SubmeshData3DS)(referencingSubmeshes[referencingSubmeshes.Count - 1]);
                // Qualify the material name with the submesh's name as well (see above note)
                currentMaterialData.name = currentMaterialData.name + "_" + owningSubmesh.name;
                owningSubmesh.materialUsed = currentMaterialData.name;
                // Clean up and update submesh reference lists
                referencingSubmeshes.RemoveAt(referencingSubmeshes.Count - 1);
                referencingSubmeshes = new ArrayList();
                referencingSubmeshes.Add(owningSubmesh);
                submeshesUsingMaterials.Add(currentMaterialData.name, referencingSubmeshes);
            }*/

            return mat;
        }
Example #9
0
        private static ThreeDSMesh.FaceGroup ParseFaceData(DataReader3DS dataSegment)
        {
            DataReader3DS subSegment;	// will be used to read other subsegments (do not initialize yet)

            ThreeDSMesh.FaceGroup group = new ThreeDSMesh.FaceGroup();
            group.faces = new ThreeDSMesh.Face[dataSegment.GetUShort()];

            // Read face data
            for (int face = 0; face < group.faces.Length; face++)
            {
                group.faces[face].p1 = dataSegment.GetUShort();
                group.faces[face].p2 = dataSegment.GetUShort();
                group.faces[face].p3 = dataSegment.GetUShort();
                // Ignore flag
                dataSegment.GetUShort();
            }

            // Read other subsegments
            subSegment = dataSegment.GetNextSubSegment();
            while (subSegment != null)
            {
                switch ((ChunkCodes)subSegment.Tag)
                {
                    case ChunkCodes.MESH_MATER:	// Name of material used
                        group.mappings.Add(ParseMeshMaterial(subSegment));
                        break;
                    case ChunkCodes.TRI_SMOOTH:
                        break;
                }
                subSegment = dataSegment.GetNextSubSegment();
            }

            return group;
        }
Example #10
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;
        }
Example #11
0
        private static ThreeDSObject ParseMeshData(DataReader3DS dataSegment)
        {
            string name = dataSegment.GetString();
            DataReader3DS subSegment = dataSegment.GetNextSubSegment();

            ThreeDSObject obj = new ThreeDSObject();
            obj.name = name;

            while (subSegment != null)
            {
                switch ((ChunkCodes)subSegment.Tag)
                {
                    case ChunkCodes.OBJ_MESH:	// Current subsegment contains the polygonal information
                        obj.meshes.Add(ParsePolygonalData(subSegment));
                        break;
                    default:		// Ignore all other subsegment types
                        break;
                }
                subSegment = dataSegment.GetNextSubSegment();
            }

            return obj;
        }
Example #12
0
        private static void Parse3DSData(DataReader3DS dataSegment, ThreeDSFileData file)
        {
            DataReader3DS subSegment = dataSegment.GetNextSubSegment();

            while (subSegment != null)
            {
                switch ((ChunkCodes)subSegment.Tag)
                {
                    case ChunkCodes.MATERIAL:
                        file.materials.Add(ParseMaterialData(subSegment));
                        break;
                    case ChunkCodes.NAMED_OBJECT:
                        file.objects.Add(ParseMeshData(subSegment));
                        break;
                    default:
                        break;
                }
                subSegment = dataSegment.GetNextSubSegment();
            }
        }