/// <summary> /// /// </summary> protected void AttachMaterial() { this.phongMaterial = Material as PhongMaterial; if (phongMaterial != null) { this.effectMaterial = new EffectMaterialVariables(this.effect); /// --- has texture if (phongMaterial.DiffuseMap != null) { this.texDiffuseMapView = ShaderResourceView.FromMemory(Device, phongMaterial.DiffuseMap.ToByteArray()); this.effectMaterial.texDiffuseMapVariable.SetResource(this.texDiffuseMapView); this.effectMaterial.bHasDiffuseMapVariable.Set(true); } else { this.effectMaterial.bHasDiffuseMapVariable.Set(false); } // --- has bumpmap if (phongMaterial.NormalMap != null) { var geometry = this.Geometry as MeshGeometry3D; if (geometry != null) { if (geometry.Tangents == null) { //System.Windows.MessageBox.Show(string.Format("No Tangent-Space found. NormalMap will be omitted."), "Warrning", MessageBoxButton.OK); phongMaterial.NormalMap = null; } else { this.texNormalMapView = ShaderResourceView.FromMemory(Device, phongMaterial.NormalMap.ToByteArray()); this.effectMaterial.texNormalMapVariable.SetResource(this.texNormalMapView); this.effectMaterial.bHasNormalMapVariable.Set(true); } } } else { this.effectMaterial.bHasNormalMapVariable.Set(false); } // --- has displacement map if (phongMaterial.DisplacementMap != null) { this.texDisplacementMapView = ShaderResourceView.FromMemory(Device, phongMaterial.DisplacementMap.ToByteArray()); this.effectMaterial.texDisplacementMapVariable.SetResource(this.texDisplacementMapView); this.effectMaterial.bHasDisplacementMapVariable.Set(true); } else { this.effectMaterial.bHasDisplacementMapVariable.Set(false); } } }
/// <summary> /// Creates the material. /// </summary> /// <param name="texturePath">The texture path.</param> /// <returns>A WPF material.</returns> private Material CreateMaterial(string texturePath) { MemoryStream diffuseMapMS = null; if (DiffuseMap != null) { using (var fs = new FileStream(Path.GetFullPath(Path.Combine(texturePath, "./" + this.DiffuseMap)), FileMode.Open)) { diffuseMapMS = new MemoryStream(); fs.CopyTo(diffuseMapMS); } } MemoryStream bumpMapMS = null; if (BumpMap != null) { using (var fs = new FileStream(Path.GetFullPath(Path.Combine(texturePath, "./" + this.BumpMap)), FileMode.Open)) { bumpMapMS = new MemoryStream(); fs.CopyTo(bumpMapMS); } } MemoryStream alphaMapMS = null; if (AlphaMap != null) { using (var fs = new FileStream(Path.GetFullPath(Path.Combine(texturePath, "./" + this.AlphaMap)), FileMode.Open)) { alphaMapMS = new MemoryStream(); fs.CopyTo(alphaMapMS); } } var mat = new PhongMaterial() { AmbientColor = this.Ambient, //AmbientMap = this.AmbientMap, DiffuseColor = this.Diffuse, DiffuseMap = diffuseMapMS, SpecularColor = this.Specular, SpecularShininess = (float)this.SpecularCoefficient, //SpecularMap = this.SpecularMap, NormalMap = bumpMapMS, DiffuseAlphaMap = alphaMapMS, //Dissolved = this.Dissolved, //Illumination = this.Illumination, }; //return mg.Children.Count != 1 ? mg : mg.Children[0]; return(mat); }
public ViewBoxModel3D() { Geometry = defaultBoxModel; var map = new MemoryStream(); var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("HelixToolkit.Wpf.SharpDX.Textures.DefaultViewboxTexture.jpg"); stream.CopyTo(map); stream.Dispose(); Material = new PhongMaterial() { DiffuseColor = Color.White, DiffuseMap = map }; CullMode = CullMode.Back; }
/// <summary> /// /// </summary> public override void Detach() { Disposer.RemoveAndDispose(ref this.vertexBuffer); Disposer.RemoveAndDispose(ref this.indexBuffer); Disposer.RemoveAndDispose(ref this.instanceBuffer); Disposer.RemoveAndDispose(ref this.effectMaterial); Disposer.RemoveAndDispose(ref this.effectTransforms); Disposer.RemoveAndDispose(ref this.texDiffuseMapView); Disposer.RemoveAndDispose(ref this.texNormalMapView); Disposer.RemoveAndDispose(ref this.texDisplacementMapView); Disposer.RemoveAndDispose(ref this.bHasInstances); this.phongMaterial = null; this.effectTechnique = null; this.vertexLayout = null; base.Detach(); }
public EffectMaterialVariables(Effect effect, PhongMaterial material) { this.material = material; this.material.OnMaterialPropertyChanged += Material_OnMaterialPropertyChanged; this.vMaterialAmbientVariable = effect.GetVariableByName("vMaterialAmbient").AsVector(); this.vMaterialDiffuseVariable = effect.GetVariableByName("vMaterialDiffuse").AsVector(); this.vMaterialEmissiveVariable = effect.GetVariableByName("vMaterialEmissive").AsVector(); this.vMaterialSpecularVariable = effect.GetVariableByName("vMaterialSpecular").AsVector(); this.vMaterialReflectVariable = effect.GetVariableByName("vMaterialReflect").AsVector(); this.sMaterialShininessVariable = effect.GetVariableByName("sMaterialShininess").AsScalar(); this.bHasDiffuseMapVariable = effect.GetVariableByName("bHasDiffuseMap").AsScalar(); this.bHasDiffuseAlphaMapVariable = effect.GetVariableByName("bHasAlphaMap").AsScalar(); this.bHasNormalMapVariable = effect.GetVariableByName("bHasNormalMap").AsScalar(); this.bHasDisplacementMapVariable = effect.GetVariableByName("bHasDisplacementMap").AsScalar(); this.bHasShadowMapVariable = effect.GetVariableByName("bHasShadowMap").AsScalar(); this.texDiffuseMapVariable = effect.GetVariableByName("texDiffuseMap").AsShaderResource(); this.texNormalMapVariable = effect.GetVariableByName("texNormalMap").AsShaderResource(); this.texDisplacementMapVariable = effect.GetVariableByName("texDisplacementMap").AsShaderResource(); this.texShadowMapVariable = effect.GetVariableByName("texShadowMap").AsShaderResource(); this.texDiffuseAlphaMapVariable = effect.GetVariableByName("texAlphaMap").AsShaderResource(); }
/// <summary> /// Creates the material. /// </summary> /// <param name="texturePath">The texture path.</param> /// <returns>A WPF material.</returns> private Material CreateMaterial(string texturePath) { var mat = new PhongMaterial() { AmbientColor = this.Ambient, //AmbientMap = this.AmbientMap, DiffuseColor = this.Diffuse, DiffuseMap = (this.DiffuseMap == null) ? null : new FileStream(Path.GetFullPath(Path.Combine(texturePath, "./" + this.DiffuseMap)), FileMode.Open), SpecularColor = this.Specular, SpecularShininess = (float)this.SpecularCoefficient, //SpecularMap = this.SpecularMap, NormalMap = (this.BumpMap == null) ? null : new FileStream(Path.GetFullPath(Path.Combine(texturePath, "./" + this.BumpMap)), FileMode.Open), //Dissolved = this.Dissolved, //Illumination = this.Illumination, }; //return mg.Children.Count != 1 ? mg : mg.Children[0]; return(mat); }
/// <summary> /// Creates the material. /// </summary> /// <param name="texturePath">The texture path.</param> /// <returns>A WPF material.</returns> private Material CreateMaterial(string texturePath) { var mat = new PhongMaterial() { AmbientColor = this.Ambient, //AmbientMap = this.AmbientMap, DiffuseColor = this.Diffuse, DiffuseMap = (this.DiffuseMap == null) ? null : LoadImage(this.DiffuseMap), SpecularColor = this.Specular, SpecularShininess = (float)this.SpecularCoefficient, //SpecularMap = this.SpecularMap, NormalMap = (this.BumpMap == null) ? null : LoadImage(this.BumpMap), //Dissolved = this.Dissolved, //Illumination = this.Illumination, }; //return mg.Children.Count != 1 ? mg : mg.Children[0]; return(mat); }
/// <summary> /// /// </summary> protected virtual void AttachMaterial() { this.phongMaterial = Material as PhongMaterial; if (phongMaterial != null) { this.effectMaterial = new EffectMaterialVariables(this.effect); /// --- has texture if (phongMaterial.DiffuseMap != null) { this.texDiffuseMapView = new ShaderResourceView(Device,TextureLoader.CreateTexture2DFromMediaBitamp(this.Device, phongMaterial.DiffuseMap));// ShaderResourceView.FromMemory(Device, phongMaterial.DiffuseMap.ToByteArray()); this.effectMaterial.texDiffuseMapVariable.SetResource(this.texDiffuseMapView); this.effectMaterial.bHasDiffuseMapVariable.Set(true); } else { this.effectMaterial.bHasDiffuseMapVariable.Set(false); } // --- has bumpmap if (phongMaterial.NormalMap != null) { var geometry = this.Geometry as MeshGeometry3D; if (geometry != null) { if (geometry.Tangents == null) { //System.Windows.MessageBox.Show(string.Format("No Tangent-Space found. NormalMap will be omitted."), "Warrning", MessageBoxButton.OK); phongMaterial.NormalMap = null; } else { this.texNormalMapView = new ShaderResourceView(Device, TextureLoader.CreateTexture2DFromMediaBitamp(this.Device, phongMaterial.NormalMap)); this.effectMaterial.texNormalMapVariable.SetResource(this.texNormalMapView); this.effectMaterial.bHasNormalMapVariable.Set(true); } } } else { this.effectMaterial.bHasNormalMapVariable.Set(false); } // --- has displacement map if (phongMaterial.DisplacementMap != null) { this.texDisplacementMapView = new ShaderResourceView(Device, TextureLoader.CreateTexture2DFromMediaBitamp(this.Device, phongMaterial.DisplacementMap)); this.effectMaterial.texDisplacementMapVariable.SetResource(this.texDisplacementMapView); this.effectMaterial.bHasDisplacementMapVariable.Set(true); } else { this.effectMaterial.bHasDisplacementMapVariable.Set(false); } } }
/// <summary> /// /// </summary> public override void Detach() { Disposer.RemoveAndDispose(ref this.vertexBuffer); Disposer.RemoveAndDispose(ref this.indexBuffer); Disposer.RemoveAndDispose(ref this.instanceBuffer); Disposer.RemoveAndDispose(ref this.effectMaterial); Disposer.RemoveAndDispose(ref this.effectTransforms); Disposer.RemoveAndDispose(ref this.texDiffuseMapView); Disposer.RemoveAndDispose(ref this.texNormalMapView); Disposer.RemoveAndDispose(ref this.texDisplacementMapView); Disposer.RemoveAndDispose(ref this.bHasInstances); this.phongMaterial = null; this.effectTechnique = null; this.vertexLayout = null; base.Detach(); }
private void AggregateRenderPackages(PackageAggregationParams parameters) { //Clear the geometry values before adding the package. VisualizationManager_WorkspaceOpenedClosedHandled(); foreach (var rp in parameters.Packages) { //Node ID gets updated with a ":" everytime this function is called. //For example, if the same point node is called multiple times (CBN), the ID has a ":" //and this makes the dictionary to have multiple entries for the same node. var baseId = rp.Description; if (baseId.IndexOf(":", StringComparison.Ordinal) > 0) { baseId = baseId.Split(':')[0]; } var id = baseId; var p = rp.Points; if (p.Positions.Any()) { id = baseId + ":points"; PointGeometryModel3D pointGeometry3D; if (model3DDictionary.ContainsKey(id)) { pointGeometry3D = model3DDictionary[id] as PointGeometryModel3D; } else { pointGeometry3D = new PointGeometryModel3D { Geometry = HelixRenderPackage.InitPointGeometry(), Transform = Model1Transform, Color = SharpDX.Color.White, Figure = PointGeometryModel3D.PointFigure.Ellipse, Size = DefaultPointSize, IsHitTestVisible = true, IsSelected = rp.IsSelected }; model3DDictionary.Add(id, pointGeometry3D); } var points = pointGeometry3D.Geometry as PointGeometry3D; var startIdx = points.Positions.Count; points.Positions.AddRange(p.Positions); points.Colors.AddRange(p.Colors.Any() ? p.Colors : Enumerable.Repeat(defaultPointColor, points.Positions.Count)); points.Indices.AddRange(p.Indices.Select(i => i + startIdx)); if (rp.DisplayLabels) { var pt = p.Positions[0]; parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f))); Text = parameters.Text; } pointGeometry3D.Geometry = points; pointGeometry3D.Name = baseId; pointGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D; } var l = rp.Lines; if (l.Positions.Any()) { id = baseId + ":lines"; LineGeometryModel3D lineGeometry3D; if (model3DDictionary.ContainsKey(id)) { lineGeometry3D = model3DDictionary[id] as LineGeometryModel3D; } else { lineGeometry3D = new LineGeometryModel3D() { Geometry = HelixRenderPackage.InitLineGeometry(), Transform = Model1Transform, Color = SharpDX.Color.White, Thickness = 0.5, IsHitTestVisible = true, IsSelected = rp.IsSelected }; model3DDictionary.Add(id, lineGeometry3D); } var lineSet = lineGeometry3D.Geometry as LineGeometry3D; var startIdx = lineSet.Positions.Count; lineSet.Positions.AddRange(l.Positions); lineSet.Colors.AddRange(l.Colors.Any() ? l.Colors : Enumerable.Repeat(defaultLineColor, l.Positions.Count)); lineSet.Indices.AddRange(l.Indices.Any() ? l.Indices.Select(i => i + startIdx) : Enumerable.Range(startIdx, startIdx + l.Positions.Count)); if (rp.DisplayLabels) { var pt = lineSet.Positions[startIdx]; parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f))); Text = parameters.Text; } lineGeometry3D.Geometry = lineSet; lineGeometry3D.Name = baseId; lineGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D; } var m = rp.Mesh; if (!m.Positions.Any()) continue; id = ((rp.RequiresPerVertexColoration || rp.Colors != null) ? rp.Description : baseId) + ":mesh"; DynamoGeometryModel3D meshGeometry3D; if (model3DDictionary.ContainsKey(id)) { meshGeometry3D = model3DDictionary[id] as DynamoGeometryModel3D; } else { meshGeometry3D = new DynamoGeometryModel3D() { Transform = Model1Transform, Material = WhiteMaterial, IsHitTestVisible = true, RequiresPerVertexColoration = rp.RequiresPerVertexColoration, IsSelected = rp.IsSelected, }; if (rp.Colors != null) { var pf = PixelFormats.Bgra32; var stride = (rp.ColorsStride / 4 * pf.BitsPerPixel + 7) / 8; try { var diffMap = BitmapSource.Create(rp.ColorsStride/4, rp.Colors.Count()/rp.ColorsStride, 96.0, 96.0, pf, null, rp.Colors.ToArray(), stride); var diffMat = new PhongMaterial { Name = "White", AmbientColor = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0), DiffuseColor = materialColor, SpecularColor = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0), EmissiveColor = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0), SpecularShininess = 12.8f, DiffuseMap = diffMap }; meshGeometry3D.Material = diffMat; } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } } ((MaterialGeometryModel3D) meshGeometry3D).SelectionColor = selectionColor; model3DDictionary.Add(id, meshGeometry3D); } var mesh = meshGeometry3D.Geometry == null ? HelixRenderPackage.InitMeshGeometry() : meshGeometry3D.Geometry as MeshGeometry3D; var idxCount = mesh.Positions.Count; mesh.Positions.AddRange(m.Positions); mesh.Colors.AddRange(m.Colors); mesh.Normals.AddRange(m.Normals); mesh.TextureCoordinates.AddRange(m.TextureCoordinates); mesh.Indices.AddRange(m.Indices.Select(i => i + idxCount)); if (mesh.Colors.Any(c => c.Alpha < 1.0)) { meshGeometry3D.HasTransparency = true; } if (rp.DisplayLabels) { var pt = mesh.Positions[idxCount]; parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f))); Text = parameters.Text; } meshGeometry3D.Geometry = mesh; meshGeometry3D.Name = baseId; meshGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D; } Attach(); }
private void SetImages(BitmapSource img) { var ratio = img.PixelWidth / (double)img.PixelHeight; var transform = Media3D.Transform3D.Identity; ushort orientation = 1; if (this.ExifReader.GetTagValue(ExifTags.Orientation, out orientation)) { switch (orientation) { default: case 1: // transform = transform.AppendTransform(new Media3D.ScaleTransform3D(ratio, 1.0, 1.0)); break; case 2: //"-flip horizontal";; //transform = Media3D.Transform3D.Identity; break; case 3: //"-rotate 180";; transform = transform.AppendTransform(new Media3D.ScaleTransform3D(ratio, 1.0, 1.0)); transform = transform.AppendTransform(new Media3D.RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 0, 1), -180))); break; case 4: //"-flip vertical";; //transform = Media3D.Transform3D.Identity; break; case 5: //"-transpose";; //transform = Media3D.Transform3D.Identity; break; case 6: //"-rotate 90";; transform = transform.AppendTransform(new Media3D.ScaleTransform3D(1.0, 1.0 / ratio, 1.0)); transform = transform.AppendTransform(new Media3D.RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 0, 1), -90))); break; case 7: //"-transverse";; // transform = Media3D.Transform3D.Identity; break; case 8: //"-rotate 270";; transform = transform.AppendTransform(new Media3D.ScaleTransform3D(1.0, 1.0 / ratio, 1.0)); transform = transform.AppendTransform(new Media3D.RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 0, 1), -270))); break; } this.PlaneTransform = transform; this.GridTransform = transform; } else { if (ratio > 1) { transform = transform.AppendTransform(new Media3D.ScaleTransform3D(ratio, 1.0, 1.0)); this.PlaneTransform = transform; this.GridTransform = PlaneTransform; } else { transform = transform.AppendTransform(new Media3D.ScaleTransform3D(1.0, 1.0 / ratio, 1.0)); this.PlaneTransform = transform; this.GridTransform = PlaneTransform; } } var white = new PhongMaterial() { DiffuseColor = Color.White, AmbientColor = Color.Black, ReflectiveColor = Color.Black, EmissiveColor = Color.Black, SpecularColor = Color.Black, DiffuseMap = img, }; this.PlaneMaterial = white; this.RenderTechnique = Techniques.RenderDiffuse; }
private void SetupScene() { var ptColor = (Color)SharedDictionaryManager.DynamoColorsAndBrushesDictionary["PointColor"]; defaultPointColor = new Color4(ptColor.R/255.0f, ptColor.G/255.0f, ptColor.B/255.0f, ptColor.A/255.0f); var lineColor = (Color)SharedDictionaryManager.DynamoColorsAndBrushesDictionary["EdgeColor"]; defaultLineColor = new Color4(lineColor.R/255.0f, lineColor.G/255.0f, lineColor.B/255.0f, lineColor.A/255.0f); directionalLightColor = new Color4(0.9f, 0.9f, 0.9f, 1.0f); directionalLightDirection = new Vector3(-0.5f, -1.0f, 0.0f); var matColor = (Color)SharedDictionaryManager.DynamoColorsAndBrushesDictionary["MaterialColor"]; materialColor = new Color4(matColor.R/255.0f, matColor.G/255.0f, matColor.B/255.0f, matColor.A/255.0f); RenderTechnique = Techniques.RenderDynamo; WhiteMaterial = new PhongMaterial { Name = "White", AmbientColor = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0), DiffuseColor = materialColor, SpecularColor = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0), EmissiveColor = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0), SpecularShininess = 12.8f, }; var selColor = (Color)SharedDictionaryManager.DynamoColorsAndBrushesDictionary["SelectionColor"]; selectionColor = new Color4(selColor.R/255.0f, selColor.G/255.0f, selColor.B/255.0f, selColor.A/255.0f); SelectedMaterial = new PhongMaterial { Name = "White", AmbientColor = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0), DiffuseColor = selectionColor, SpecularColor = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0), EmissiveColor = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0), SpecularShininess = 12.8f, }; Model1Transform = new TranslateTransform3D(0, -0, 0); // camera setup Camera = new PerspectiveCamera { UpDirection = new Vector3D(0, 1, 0), FarPlaneDistance = 10000000, }; ResetCamera(); DrawGrid(); }
/// <summary> /// Creates the material. /// </summary> /// <param name="texturePath">The texture path.</param> /// <returns>A WPF material.</returns> private Material CreateMaterial(string texturePath) { var mat = new PhongMaterial() { AmbientColor = this.Ambient, //AmbientMap = this.AmbientMap, DiffuseColor = this.Diffuse, DiffuseMap = (this.DiffuseMap == null) ? null : LoadImage(this.DiffuseMap), SpecularColor = this.Specular, SpecularShininess = (float)this.SpecularCoefficient, //SpecularMap = this.SpecularMap, NormalMap = (this.BumpMap == null) ? null : LoadImage(this.BumpMap), //Dissolved = this.Dissolved, //Illumination = this.Illumination, }; //return mg.Children.Count != 1 ? mg : mg.Children[0]; return mat; }
private DynamoGeometryModel3D CreateDynamoGeometryModel3D(HelixRenderPackage rp) { var meshGeometry3D = new DynamoGeometryModel3D() { Transform = Model1Transform, Material = WhiteMaterial, IsHitTestVisible = true, RequiresPerVertexColoration = rp.RequiresPerVertexColoration, IsSelected = rp.IsSelected, }; if (rp.Colors != null) { var pf = PixelFormats.Bgra32; var stride = (rp.ColorsStride / 4 * pf.BitsPerPixel + 7) / 8; try { var diffMap = BitmapSource.Create(rp.ColorsStride / 4, rp.Colors.Count() / rp.ColorsStride, 96.0, 96.0, pf, null, rp.Colors.ToArray(), stride); var diffMat = new PhongMaterial { Name = "White", AmbientColor = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0), DiffuseColor = defaultMaterialColor, SpecularColor = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0), EmissiveColor = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0), SpecularShininess = 12.8f, DiffuseMap = diffMap }; meshGeometry3D.Material = diffMat; } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } } ((MaterialGeometryModel3D)meshGeometry3D).SelectionColor = defaultSelectionColor; return meshGeometry3D; }
private void SetupScene() { RenderTechnique = Techniques.RenderDynamo; WhiteMaterial = new PhongMaterial { Name = "White", AmbientColor = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0), DiffuseColor = defaultMaterialColor, SpecularColor = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0), EmissiveColor = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0), SpecularShininess = 12.8f, }; SelectedMaterial = new PhongMaterial { Name = "White", AmbientColor = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0), DiffuseColor = defaultSelectionColor, SpecularColor = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0), EmissiveColor = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0), SpecularShininess = 12.8f, }; Model1Transform = new TranslateTransform3D(0, -0, 0); // camera setup Camera = new PerspectiveCamera(); SetCameraData(new CameraData()); DrawGrid(); }
/// <summary> /// reads the Material of a chunck /// </summary> /// <param name="reader"></param> /// <param name="chunkSize"></param> private void ReadMaterial(BinaryReader reader,int chunkSize) { int total = 6; string name = null; var luminance = Color.Transparent; //SharpDX.Color not System.Windows.Media.Color var diffuse = Color.Transparent; var specular = Color.Transparent; var shininess = Color.Transparent; string texture = null; while (total < chunkSize) { ChunkID id = this.ReadChunkId(reader); int size = this.ReadChunkSize(reader); total += size; switch (id) { case ChunkID.MAT_NAME01: name = this.ReadString(reader); break; case ChunkID.MAT_LUMINANCE: luminance = this.ReadColor(reader); break; case ChunkID.MAT_DIFFUSE: diffuse = this.ReadColor(reader); break; case ChunkID.MAT_SPECULAR: specular = this.ReadColor(reader); break; case ChunkID.MAT_SHININESS: byte[] bytes = this.ReadData(reader, size - 6); break; case ChunkID.MAT_MAP: texture = this.ReadMatMap(reader, size - 6); break; case ChunkID.MAT_MAPFILE: this.ReadData(reader, size - 6); break; default: this.ReadData(reader, size - 6); break; } } int specularPower = 100;//check if we can find this somewhere instead of just setting it to 100 BitmapSource image = ReadBitmapSoure(texture, diffuse); var material = new PhongMaterial() { DiffuseColor = diffuse, AmbientColor = luminance, //not really sure about this, lib3ds uses 0xA010 as AmbientColor SpecularColor = specular, SpecularShininess = specularPower, }; if(image!= null) { material.NormalMap = image; } if (name != null) { materials[name] = material; } }
/// <summary> /// reads the Material of a chunck /// </summary> /// <param name="reader"></param> /// <param name="chunkSize"></param> private void ReadMaterial(BinaryReader reader, int chunkSize) { int total = 6; string name = null; var luminance = Color.Transparent; //SharpDX.Color not System.Windows.Media.Color var diffuse = Color.Transparent; var specular = Color.Transparent; var shininess = Color.Transparent; string texture = null; while (total < chunkSize) { ChunkID id = this.ReadChunkId(reader); int size = this.ReadChunkSize(reader); total += size; switch (id) { case ChunkID.MAT_NAME01: name = this.ReadString(reader); break; case ChunkID.MAT_LUMINANCE: luminance = this.ReadColor(reader); break; case ChunkID.MAT_DIFFUSE: diffuse = this.ReadColor(reader); break; case ChunkID.MAT_SPECULAR: specular = this.ReadColor(reader); break; case ChunkID.MAT_SHININESS: byte[] bytes = this.ReadData(reader, size - 6); break; case ChunkID.MAT_MAP: texture = this.ReadMatMap(reader, size - 6); break; case ChunkID.MAT_MAPFILE: this.ReadData(reader, size - 6); break; default: this.ReadData(reader, size - 6); break; } } int specularPower = 100;//check if we can find this somewhere instead of just setting it to 100 BitmapSource image = ReadBitmapSoure(texture, diffuse); var material = new PhongMaterial() { DiffuseColor = diffuse, AmbientColor = luminance, //not really sure about this, lib3ds uses 0xA010 as AmbientColor SpecularColor = specular, SpecularShininess = specularPower, }; if (image != null) { material.NormalMap = image; } if (name != null) { materials[name] = material; } }