public override Scene GetScene(ISite site, bool designMode) { Scene scene = new Scene(); foreach (Mesh mesh in Meshes) { Meshellator.Mesh meshellatorMesh = new Meshellator.Mesh(); scene.Meshes.Add(meshellatorMesh); meshellatorMesh.Positions.AddRange(mesh.Positions.Select(p => new Nexus.Point3D(p.X, p.Y, p.Z))); meshellatorMesh.TextureCoordinates.AddRange(mesh.TextureCoordinates.Select(p => new Nexus.Point3D(p.X, p.Y, 0))); MeshUtility.CalculateNormals(meshellatorMesh, false); meshellatorMesh.Indices.AddRange(mesh.Indices.Select(i => i.Value)); Meshellator.Material meshellatorMaterial = new Meshellator.Material(); meshellatorMaterial.DiffuseColor = ConversionUtility.ToNexusColorRgbF(mesh.Material.DiffuseColor); if (!string.IsNullOrEmpty(mesh.Material.TextureFileName)) { string textureFileName = FileSourceHelper.ResolveFileName(mesh.Material.TextureFileName, Site, DesignMode); if (!File.Exists(textureFileName)) throw new DynamicImageException("Could not find texture '" + mesh.Material.TextureFileName + "'."); meshellatorMaterial.DiffuseTextureName = textureFileName; } meshellatorMaterial.Shininess = mesh.Material.Shininess; meshellatorMaterial.SpecularColor = ConversionUtility.ToNexusColorRgbF(mesh.Material.SpecularColor); meshellatorMaterial.Transparency = mesh.Material.Transparency; meshellatorMesh.Material = meshellatorMaterial; scene.Materials.Add(meshellatorMaterial); } return scene; }
public static void CalculateNormals(Mesh mesh, bool overwriteExistingNormals) { if (mesh == null) throw new ArgumentNullException("mesh"); if (overwriteExistingNormals || !mesh.Normals.Any()) { Vector3D[] vertexNormals = new Vector3D[mesh.Positions.Count]; AccumulateTriangleNormals(mesh.Indices, mesh.Positions, vertexNormals); for (int i = 0; i < vertexNormals.Length; i++) vertexNormals[i] = Vector3D.Normalize(vertexNormals[i]); mesh.Normals.AddRange(vertexNormals); } }
public override Scene GetScene(ImageGenerationContext context) { Scene scene = new Scene(); foreach (Mesh mesh in Meshes) { Meshellator.Mesh meshellatorMesh = new Meshellator.Mesh(); scene.Meshes.Add(meshellatorMesh); meshellatorMesh.Positions.AddRange(mesh.Positions.Select(p => new Nexus.Point3D(p.X, p.Y, p.Z))); meshellatorMesh.TextureCoordinates.AddRange(mesh.TextureCoordinates.Select(p => new Nexus.Point3D(p.X, p.Y, 0))); MeshUtility.CalculateNormals(meshellatorMesh, false); meshellatorMesh.Indices.AddRange(mesh.Indices.Select(i => i.Value)); Meshellator.Material meshellatorMaterial = new Meshellator.Material(); meshellatorMaterial.DiffuseColor = ConversionUtility.ToNexusColorRgbF(mesh.Material.DiffuseColor); if (!string.IsNullOrEmpty(mesh.Material.TextureFileName)) { string textureFileName = FileSourceHelper.ResolveFileName(context, mesh.Material.TextureFileName); if (!File.Exists(textureFileName)) { throw new DynamicImageException("Could not find texture '" + mesh.Material.TextureFileName + "'."); } meshellatorMaterial.DiffuseTextureName = textureFileName; } meshellatorMaterial.Shininess = mesh.Material.Shininess; meshellatorMaterial.SpecularColor = ConversionUtility.ToNexusColorRgbF(mesh.Material.SpecularColor); meshellatorMaterial.Transparency = mesh.Material.Transparency; meshellatorMesh.Material = meshellatorMaterial; scene.Materials.Add(meshellatorMaterial); } return(scene); }
private static Scene CreateFromPrimitive(BasicPrimitiveTessellator tessellator) { tessellator.Tessellate(); Material material = new Material(); material.Name = "Default"; material.DiffuseColor = ColorsRgbF.Blue; material.SpecularColor = ColorsRgbF.White; Mesh mesh = new Mesh(); mesh.Positions.AddRange(tessellator.Positions); mesh.Indices.AddRange(tessellator.Indices); mesh.Normals.AddRange(tessellator.Normals); mesh.Material = material; Scene scene = new Scene { FileName = "[New Sphere]" }; scene.Materials.Add(material); scene.Meshes.Add(mesh); return scene; }