diffuse() public method

public diffuse ( ) : Meshellator.Importers.Autodesk3ds.Color3ds
return Meshellator.Importers.Autodesk3ds.Color3ds
Ejemplo n.º 1
0
        public override Scene ImportFile(FileStream fileStream, string fileName)
        {
            Scene3ds scene3ds = new Scene3ds(fileStream, null, Scene3ds.DECODE_ALL);

            Scene result = new Scene();

            // Compute normals for our scene
            computeNormals(scene3ds, result);

            Material defaultMaterial = new Material
            {
                Name          = "Default",
                FileName      = fileName,
                DiffuseColor  = ColorsRgbF.Gray,
                SpecularColor = ColorsRgbF.White,
                Shininess     = 64
            };

            for (int i = 0; i < scene3ds.Materials.Count(); ++i)
            {
                Material3ds material3ds = scene3ds.Materials.ElementAt(i);
                Material    material    = new Material
                {
                    Name          = material3ds.name(),
                    FileName      = fileName,
                    DiffuseColor  = material3ds.diffuse().ToColorRgbF(),
                    AmbientColor  = material3ds.ambient().ToColorRgbF(),
                    SpecularColor = material3ds.specular().ToColorRgbF(),
                    Transparency  = material3ds.transparency()
                };
                if (material3ds.DiffuseTexture != null)
                {
                    material.DiffuseTextureName = Path.Combine(Path.GetDirectoryName(fileName), material3ds.DiffuseTexture.MapName);
                }
                if ((int)material3ds._shininess != 0)
                {
                    material.Shininess = (int)material3ds._shininess;
                }
                result.Materials.Add(material);
            }

            for (int i = 0; i < scene3ds.Meshes.Count(); ++i)
            {
                Mesh3ds mesh3ds = scene3ds.Meshes.ElementAt(i);

                Mesh resultMesh = result.Meshes[i];

                //resultMesh.Material = defaultMaterial;

                // TODO: Is this right?
                if (mesh3ds.faceMats() == 0)
                {
                    resultMesh.Material = defaultMaterial;

                    for (int fi = 0; fi < mesh3ds.faces(); ++fi)
                    {
                        Face3ds f = mesh3ds.face(fi);


                        resultMesh.Indices.Add(f.P0);
                        resultMesh.Indices.Add(f.P1);
                        resultMesh.Indices.Add(f.P2);
                    }
                }
                else
                {
                    // TODO: Split by face materials so that each mesh only has one material.
                    Debug.Assert(mesh3ds.faceMats() == 1);
                    for (int fm = 0; fm < mesh3ds.faceMats(); ++fm)
                    {
                        // Get current material's face.
                        FaceMat3ds fmat     = mesh3ds.faceMat(fm);
                        Material   material = result.Materials[fmat.material()];
                        resultMesh.Material = material;

                        for (int fi = 0; fi < fmat.faces(); ++fi)
                        {
                            int     idx = fmat.face(fi);
                            Face3ds f   = mesh3ds.face(idx);


                            resultMesh.Indices.Add(f.P0);
                            resultMesh.Indices.Add(f.P1);
                            resultMesh.Indices.Add(f.P2);
                        }
                    }
                }
            }

            return(result);
        }