private void button6_Click(object sender, RoutedEventArgs e) { for (int cntr = 1; cntr <= 1; cntr++) { // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.GetRandomColor(64, 192)))); materials.Children.Add(new SpecularMaterial(Brushes.White, 100d)); // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; //geometry.Geometry = UtilityWPF.GetCube(.5d); //geometry.Geometry = UtilityWPF.GetRectangle3D() //geometry.Geometry = model.get // Transform Transform3DGroup transform = new Transform3DGroup(); // rotate needs to be added before translate transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(Math3D.GetRandomVector_Spherical(10), Math1D.GetNearZeroValue(360d)))); transform.Children.Add(new TranslateTransform3D(Math3D.GetRandomVector(_boundryMin, _boundryMax))); // Model Visual //ModelVisual3D model = new ModelVisual3D(); //model.Content = geometry; //model.Transform = transform; SphereVisual3D model = new SphereVisual3D(); //model.Content = geometry; model.Transform = transform; _viewport.Children.Add(model); } }
public static ContainerUIElement3D Map3DModelToUIElement3D(Map3DModel map3D) { List <Viewport2DVisual3D> visual3DList = new List <Viewport2DVisual3D>(); for (int i = 0; i < map3D.Geometries.Count; i++) { CylinderVisual3DModel cylinderVisual3DModel = map3D.Geometries[i]; DiffuseMaterial imageMaterial = new DiffuseMaterial(new ImageBrush(new BitmapImage(new Uri(string.Format(@"Images\MapTextures\{0}.png", "1"), UriKind.Relative)))); //MeshGeometry3D upperGeometry3D = Visual3DCreateHelper.CreateGeometry3D(cylinderVisual3DModel.UpperUndersurface); //Material upperMaterial = Visual3DCreateHelper.CreateMaterial3D(map3D.Materials[i][0]); //MaterialGroup mg = new MaterialGroup(); //mg.Children.Add(upperMaterial); ////mg.Children.Add(imageMaterial); //Viewport2DVisual3D upperVisual3D = Visual3DCreateHelper.CreateVisual3D(upperGeometry3D, mg); //visual3DList.Add(upperVisual3D); MeshGeometry3D lowerGeometry3D = Visual3DCreateHelper.CreateGeometry3D(cylinderVisual3DModel.LowerUndersurface); Material lowerMaterial = Visual3DCreateHelper.CreateMaterial3D(map3D.Materials[i][1]); MaterialGroup mg1 = new MaterialGroup(); mg1.Children.Add(lowerMaterial); //mg1.Children.Add(imageMaterial); Viewport2DVisual3D lowerVisual3D = Visual3DCreateHelper.CreateVisual3D(lowerGeometry3D, mg1); visual3DList.Add(lowerVisual3D); MeshGeometry3D sideGeometry3D = Visual3DCreateHelper.CreateGeometry3D(cylinderVisual3DModel.SideSurface); Material sideMaterial = Visual3DCreateHelper.CreateMaterial3D(map3D.Materials[i][2]); Viewport2DVisual3D sideVisual3D = Visual3DCreateHelper.CreateVisual3D(sideGeometry3D, sideMaterial); visual3DList.Add(sideVisual3D); } ContainerUIElement3D uIElement3D = Visual3DCreateHelper.CreateUIElement3D(visual3DList); return(uIElement3D); }
public ModelVisual3D GetCube(MaterialGroup materialGroup, Point3D point, Size3D size) { var farPoint = new Point3D(point.X - (size.X / 2), point.Y - (size.Y / 2), point.Z - (size.Z / 2)); var nearPoint = new Point3D(point.X + (size.X / 2), point.Y + (size.Y / 2), point.Z + (size.Z / 2)); var cube = new Model3DGroup(); var p0 = new Point3D(farPoint.X, farPoint.Y, farPoint.Z); var p1 = new Point3D(nearPoint.X, farPoint.Y, farPoint.Z); var p2 = new Point3D(nearPoint.X, farPoint.Y, nearPoint.Z); var p3 = new Point3D(farPoint.X, farPoint.Y, nearPoint.Z); var p4 = new Point3D(farPoint.X, nearPoint.Y, farPoint.Z); var p5 = new Point3D(nearPoint.X, nearPoint.Y, farPoint.Z); var p6 = new Point3D(nearPoint.X, nearPoint.Y, nearPoint.Z); var p7 = new Point3D(farPoint.X, nearPoint.Y, nearPoint.Z); //front side triangles cube.Children.Add(CreateTriangleModel(materialGroup, p3, p2, p6)); cube.Children.Add(CreateTriangleModel(materialGroup, p3, p6, p7)); //right side triangles cube.Children.Add(CreateTriangleModel(materialGroup, p2, p1, p5)); cube.Children.Add(CreateTriangleModel(materialGroup, p2, p5, p6)); //back side triangles cube.Children.Add(CreateTriangleModel(materialGroup, p1, p0, p4)); cube.Children.Add(CreateTriangleModel(materialGroup, p1, p4, p5)); //left side triangles cube.Children.Add(CreateTriangleModel(materialGroup, p0, p3, p7)); cube.Children.Add(CreateTriangleModel(materialGroup, p0, p7, p4)); //top side triangles cube.Children.Add(CreateTriangleModel(materialGroup, p7, p6, p5)); cube.Children.Add(CreateTriangleModel(materialGroup, p7, p5, p4)); //bottom side triangles cube.Children.Add(CreateTriangleModel(materialGroup, p2, p3, p0)); cube.Children.Add(CreateTriangleModel(materialGroup, p2, p0, p1)); var model = new ModelVisual3D(); model.Content = cube; return(model); }
private void CreateCube(Color color, Point3D location) { #region WPF Model // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color))); materials.Children.Add(new SpecularMaterial(Brushes.White, 100d)); // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.Geometry = UtilityWPF.GetCube(1d); //geometry.Geometry = UtilityWPF.GetRectangle3D() // Transform Transform3DGroup transform = new Transform3DGroup(); // rotate needs to be added before translate //transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(Math3D.GetRandomVectorSpherical(_rand, 10), Math3D.GetNearZeroValue(_rand, 360d)))); transform.Children.Add(new TranslateTransform3D(location.ToVector())); // Model Visual ModelVisual3D model = new ModelVisual3D(); model.Content = geometry; model.Transform = transform; #endregion // Add to the viewport _viewport.Children.Add(model); // Make a physics body that represents this cube ConvexBody3D body = new ConvexBody3D(_world, model); body.Mass = 1f; _cubes.Add(body); }
public NetworkOutputs(string[] names) { this.Size = names.Length; this.Names = names; this.DistanceMult = 1.5d / Math.Sqrt(this.Size); // the 1.5 doesn't mean anything. It just helps push them apart a little more this.Hues = CreateHues(this.Size); #region Materials SpecularMaterial specular = new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("50FFFFFF")), 2); // Colors this.DotColors = this.Hues.Select(o => { ColorHSV color = new ColorHSV(o, 75, 75); MaterialGroup material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(color.ToRGB()))); material.Children.Add(specular); return(new Tuple <ColorHSV, Material>(color, material)); }).ToArray(); // Gray this.ColorGray = new ColorHSV(0, 0, 50); MaterialGroup material_Gray = new MaterialGroup(); material_Gray.Children.Add(new DiffuseMaterial(new SolidColorBrush(this.ColorGray.ToRGB()))); material_Gray.Children.Add(specular); this.DotGray = material_Gray; #endregion }
private void CreateStars_GRID() { // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(new DiffuseMaterial(Brushes.GhostWhite)); materials.Children.Add(new SpecularMaterial(Brushes.White, 100d)); Model3DGroup geometries = new Model3DGroup(); for (double x = _boundryMin.X * 1.1; x < _boundryMax.X * 1.1; x += 30) { for (double y = _boundryMin.Y * 1.1; y < _boundryMax.Y * 1.1; y += 30) { for (double z = _boundryMin.Z * 1.5; z > _boundryMin.Z * 10; z -= 30) { // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = _sharedVisuals.StarMesh; geometry.Transform = new TranslateTransform3D(new Vector3D(x, y, z)); geometries.Children.Add(geometry); } } } // Visual ModelVisual3D visual = new ModelVisual3D(); visual.Content = geometries; _viewport.Children.Add(visual); _stars = visual; }
private Visual3D AddDot(Point3D position, Color color, double radius = .03) { // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color))); materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(color, Colors.White, .5d)), 50d)); // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetSphere_Ico(radius, 4, true); // Model Visual ModelVisual3D visual = new ModelVisual3D(); visual.Content = geometry; visual.Transform = new TranslateTransform3D(position.ToVector()); _viewport.Children.Add(visual); return(visual); }
private void btnSinglePolygon_Click(object sender, RoutedEventArgs e) { try { int numSides; if (!int.TryParse(txtNumSides.Text, out numSides)) { throw new ApplicationException("Couldn't parse number of sides"); } List <TubeRingDefinition_ORIG> rings = new List <TubeRingDefinition_ORIG>(); rings.Add(new TubeRingDefinition_ORIG(1d, 1d, 0d, true, false)); // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(Colors.HotPink))); materials.Children.Add(new SpecularMaterial(new SolidColorBrush(Colors.Teal), 100d)); // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetMultiRingedTube_ORIG(numSides, rings, chkSoftSides.IsChecked.Value, true); // Model Visual ModelVisual3D visual = new ModelVisual3D(); visual.Content = geometry; // Store it SetCurrentVisual(visual); } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// 初始化3D模型 /// </summary> private void init3DModels(List <string> modelsNames) { //var modelsNames = System.IO.Directory.GetFiles(Utility.ConstValue.AppPath + @"3D_Models", "*.STL", SearchOption.TopDirectoryOnly).ToList(); //var modelsNames = System.IO.Directory.GetFiles(Utility.ConstValue.AppPath + @"3D_Models/工件/1号工件", "*.STL", SearchOption.TopDirectoryOnly).ToList(); HelixToolkit.Wpf.ModelImporter import = new HelixToolkit.Wpf.ModelImporter(); //joints = new List<Joint>(); Model3DGroup model3DGroup = new Model3DGroup(); foreach (string modelName in modelsNames) { var materialGroup = new MaterialGroup(); Color mainColor = Colors.White; EmissiveMaterial emissMat = new EmissiveMaterial(new SolidColorBrush(mainColor)); System.Windows.Media.Media3D.DiffuseMaterial diffMat = new System.Windows.Media.Media3D.DiffuseMaterial(new SolidColorBrush(mainColor)); SpecularMaterial specMat = new SpecularMaterial(new SolidColorBrush(mainColor), 200); materialGroup.Children.Add(emissMat); materialGroup.Children.Add(diffMat); materialGroup.Children.Add(specMat); var link = import.Load(modelName); System.Windows.Media.Media3D.GeometryModel3D model = link.Children[0] as System.Windows.Media.Media3D.GeometryModel3D; model.Material = materialGroup; model.BackMaterial = materialGroup; //joints.Add(new Joint(link)); model3DGroup.Children.Add(link); } ModelVisual3D modelVisual3D = new ModelVisual3D(); modelVisual3D.Content = model3DGroup; mainContent.Children.Add(modelVisual3D); mainContent.InputBindings.Add(new MouseBinding(this.PointSelectionCommand, new MouseGesture(MouseAction.LeftClick))); mainContent.ZoomExtents(); }
private void CreateShape() { GeometryModel3D shape = new GeometryModel3D(); MeshGeometry3D mesh = new MeshGeometry3D(); Point3DCollection corners = new Point3DCollection(); corners.Add(new Point3D(x1, y1, 1)); corners.Add(new Point3D(x2, y1, 1)); corners.Add(new Point3D(x1, y1, 3)); corners.Add(new Point3D(x2, y1, 3)); corners.Add(new Point3D(x1, y2, 1)); corners.Add(new Point3D(x2, y2, 1)); corners.Add(new Point3D(x1, y2, 3)); corners.Add(new Point3D(x2, y2, 3)); mesh.Positions = corners; mesh.TriangleIndices = new Int32Collection(new int[] { 0, 1, 2, 3, 2, 1, 1, 5, 3, 5, 7, 3, 7, 5, 4, 4, 6, 7, 6, 2, 3, 3, 7, 6, 0, 4, 1, 1, 4, 5, 0, 2, 4, 2, 6, 4 }); shape.Geometry = mesh; MaterialGroup materialGroup = new MaterialGroup(); materialGroup.Children.Add(new DiffuseMaterial(new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 75, 150)))); shape.Material = materialGroup; wall3D = shape; }
public TestData getCreatedParentAndChildEntitiesInListTestData() { String dataName = "CreatedParentAndChildEntitiesInList"; String xml = GetJavaTestXml(dataName); String xmlCS = GetCsTestXml(dataName); MaterialGroup materialGroup = EntityFactory.CreateEntity <MaterialGroup>(); materialGroup.Buid = "new mg"; materialGroup.Name = "new mg name"; Material newMaterial = EntityFactory.CreateEntity <Material>(); newMaterial.Buid = "Created Material"; newMaterial.MaterialGroup = materialGroup; newMaterial.Name = "Created Material"; IList <Object> obj = new List <Object>(); obj.Add(newMaterial); obj.Add(materialGroup); return(new TestData(xml, xmlCS, obj)); }
/* * void Transform(double adjustBy) * { * _angle += adjustBy; * * var rotateTransform3D = new RotateTransform3D { CenterX = 0, CenterZ = 0 }; * var axisAngleRotation3D = new AxisAngleRotation3D { Axis = new Vector3D(1, 1, 1), Angle = _angle }; * rotateTransform3D.Rotation = axisAngleRotation3D; * var myTransform3DGroup = new Transform3DGroup(); * myTransform3DGroup.Children.Add(rotateTransform3D); * _models.ForEach(x => x.Transform = myTransform3DGroup); * }*/ public static ModelVisual3D GetFloor(MaterialGroup materialGroup, Point3D midPoint) { var cylinder = new Model3DGroup(); Triangle triangle = new Triangle(); triangle.P0 = new Point3D(-100, midPoint.Y, 100); triangle.P1 = new Point3D(100, midPoint.Y, -100); triangle.P2 = new Point3D(-100, midPoint.Y, -100); //cylinder.Children.Add(CreateTriangleFace(triangle.P2, triangle.P1, triangle.P0, Color.FromRgb(255,0,0))); cylinder.Children.Add(CreateTriangleModel(materialGroup, triangle)); triangle.P0 = new Point3D(100, midPoint.Y, -100); triangle.P1 = new Point3D(-100, midPoint.Y, 100); triangle.P2 = new Point3D(100, midPoint.Y, 100); //cylinder.Children.Add(CreateTriangleFace(triangle.P2, triangle.P1, triangle.P0, Color.FromRgb(255,0,0))); cylinder.Children.Add(CreateTriangleModel(materialGroup, triangle)); cylinder.Freeze(); var model = new ModelVisual3D { Content = cylinder }; return(model); }
private void CreateMouseVisual() { // Material MaterialGroup material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(255, 227, 227, 154)))); material.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(255, 235, 245, 184)), 50d)); // Geometry Model _mouseCursorGeometry = new GeometryModel3D(); _mouseCursorGeometry.Material = material; _mouseCursorGeometry.BackMaterial = material; _mouseCursorGeometry.Geometry = UtilityWPF.GetSphere_LatLon(4, .1, .1, .1); _mouseCursorGeometry.Transform = new ScaleTransform3D(1, 1, 1); // Model Visual _mouseCursor = new ModelVisual3D(); _mouseCursor.Content = _mouseCursorGeometry; //NOTE: _mouseCursor.Transform is set on each mousemove event // Add to the viewport _viewport.Children.Add(_mouseCursor); }
public IActionResult DeleteMaterialGroup(string code) { if (string.IsNullOrWhiteSpace(code)) { return(Ok(new APIResponse() { status = APIStatus.FAIL.ToString(), response = $"{nameof(code)} cannot be null" })); } try { MaterialGroup result = MaterialGroupHelper.DeleteMaterialGroup(code); if (result != null) { return(Ok(new APIResponse() { status = APIStatus.PASS.ToString(), response = code })); } else { return(Ok(new APIResponse() { status = APIStatus.FAIL.ToString(), response = "Deletion Failed" })); } } catch (Exception ex) { return(Ok(new APIResponse() { status = APIStatus.FAIL.ToString(), response = ex.Message })); } }
/// <summary> /// Creates a material with the specified diffuse, emissive and specular brushes. /// </summary> /// <param name="diffuse">The diffuse.</param> /// <param name="emissive">The emissive.</param> /// <param name="specular">The specular.</param> /// <param name="opacity">The opacity.</param> /// <param name="specularPower">The specular power.</param> /// <returns></returns> public static Material CreateMaterial(Brush diffuse, Brush emissive, Brush specular, double opacity, double specularPower) { var mg = new MaterialGroup(); if (diffuse != null) { diffuse = diffuse.Clone(); diffuse.Opacity = opacity; mg.Children.Add(new DiffuseMaterial(diffuse)); } if (emissive != null) { emissive = emissive.Clone(); emissive.Opacity = opacity; mg.Children.Add(new EmissiveMaterial(emissive)); } if (specular != null) { specular = specular.Clone(); specular.Opacity = opacity; mg.Children.Add(new SpecularMaterial(specular, specularPower)); } return(mg); }
private Model3DGroup Initialize_Environment(List <string> modelsNames) { try { ModelImporter import = new ModelImporter(); joints = new List <Joint>(); foreach (string modelName in modelsNames) { var materialGroup = new MaterialGroup(); Color mainColor = Colors.White; EmissiveMaterial emissMat = new EmissiveMaterial(new SolidColorBrush(mainColor)); DiffuseMaterial diffMat = new DiffuseMaterial(new SolidColorBrush(mainColor)); SpecularMaterial specMat = new SpecularMaterial(new SolidColorBrush(mainColor), 200); materialGroup.Children.Add(emissMat); materialGroup.Children.Add(diffMat); materialGroup.Children.Add(specMat); var link = import.Load(basePath + modelName); GeometryModel3D model = link.Children[0] as GeometryModel3D; model.Material = materialGroup; model.BackMaterial = materialGroup; joints.Add(new Joint(link)); } RA.Children.Add(joints[0].model); RA.Children.Add(joints[1].model); RA.Children.Add(joints[2].model); RA.Children.Add(joints[3].model); RA.Children.Add(joints[4].model); RA.Children.Add(joints[5].model); RA.Children.Add(joints[6].model); RA.Children.Add(joints[7].model); RA.Children.Add(joints[8].model); Color cableColor = Colors.DarkSlateGray; joints[0].angleMin = 482; joints[0].angleMax = 2500; joints[0].rotAxisX = 0; joints[0].rotAxisY = 0; joints[0].rotAxisZ = 1; joints[0].rotPointX = 0; joints[0].rotPointY = 0; joints[0].rotPointZ = 0; joints[1].angleMin = 0; joints[1].angleMax = 360; joints[1].rotAxisX = 0; joints[1].rotAxisY = 1; joints[1].rotAxisZ = 0; joints[1].rotPointX = 0; joints[1].rotPointY = 0; joints[1].rotPointZ = 0; joints[2].angleMin = 0; joints[2].angleMax = 150; joints[2].rotAxisX = 1; joints[2].rotAxisY = 0; joints[2].rotAxisZ = 0; joints[2].rotPointX = 0; joints[2].rotPointY = 0; joints[2].rotPointZ = 0; joints[3].angleMin = 0; joints[3].angleMax = 150; joints[3].rotAxisX = 1; joints[3].rotAxisY = 0; joints[3].rotAxisZ = 0; joints[3].rotPointX = 0; joints[3].rotPointY = 0; joints[3].rotPointZ = 0; joints[4].angleMin = -150; joints[4].angleMax = 0; joints[4].rotAxisX = 1; joints[4].rotAxisY = 0; joints[4].rotAxisZ = 0; joints[4].rotPointX = 0; joints[4].rotPointY = 0; joints[4].rotPointZ = 0; joints[5].angleMin = -150; joints[5].angleMax = 0; joints[5].rotAxisX = 1; joints[5].rotAxisY = 0; joints[5].rotAxisZ = 0; joints[5].rotPointX = 0; joints[5].rotPointY = 0; joints[5].rotPointZ = 0; joints[6].angleMin = -150; joints[6].angleMax = 0; joints[6].rotAxisX = 1; joints[6].rotAxisY = 0; joints[6].rotAxisZ = 0; joints[6].rotPointX = 0; joints[6].rotPointY = 0; joints[6].rotPointZ = 325; } catch (Exception e) { MessageBox.Show("Exception Error:" + e.StackTrace); } return(RA); }
// Define the model. private void DefineModel(Model3DGroup group) { // Make the surface mesh. SurfaceMesh = new MeshGeometry3D(); AddSurface(SurfaceMesh, -3, -3, 3, 3, 50, 50, F); SurfaceModel = new GeometryModel3D(SurfaceMesh, null); group.Children.Add(SurfaceModel); // Make a "sun." MeshGeometry3D sun_mesh = MakeCubeMesh( MainLight.Position.X, MainLight.Position.Y, MainLight.Position.Z, 0.25); MaterialGroup sun_group = new MaterialGroup(); sun_group.Children.Add(new DiffuseMaterial(Brushes.Yellow)); sun_group.Children.Add(new EmissiveMaterial(Brushes.Yellow)); GeometryModel3D sun_model = new GeometryModel3D(sun_mesh, sun_group); group.Children.Add(sun_model); #if SHOW_AXES // Make coordinate axis cubes. const double dist = 3; const double width = 0.5; MeshGeometry3D x_mesh = MakeCubeMesh(dist, 0, 0, width); DiffuseMaterial x_material = new DiffuseMaterial(Brushes.Red); GeometryModel3D x_model = new GeometryModel3D(x_mesh, x_material); group.Children.Add(x_model); MeshGeometry3D y_mesh = MakeCubeMesh(0, dist, 0, width); DiffuseMaterial y_material = new DiffuseMaterial(Brushes.Green); GeometryModel3D y_model = new GeometryModel3D(y_mesh, y_material); group.Children.Add(y_model); MeshGeometry3D z_mesh = MakeCubeMesh(0, 0, dist, width); DiffuseMaterial z_material = new DiffuseMaterial(Brushes.Blue); GeometryModel3D z_model = new GeometryModel3D(z_mesh, z_material); group.Children.Add(z_model); #endif // Make materials. Order matters! ImageBrush smileyBrush = new ImageBrush(); smileyBrush.ImageSource = new BitmapImage(new Uri("Smiley.png", UriKind.Relative)); AddMaterial(new DiffuseMaterial(smileyBrush), "Image"); AddMaterial(new DiffuseMaterial(Brushes.LightBlue), "Diffuse"); LinearGradientBrush linear = new LinearGradientBrush(); linear.GradientStops.Add(new GradientStop(Colors.Blue, 0.0)); linear.GradientStops.Add(new GradientStop(Colors.White, 0.4)); linear.GradientStops.Add(new GradientStop(Colors.Green, 0.5)); linear.GradientStops.Add(new GradientStop(Colors.White, 0.6)); linear.GradientStops.Add(new GradientStop(Colors.Red, 1.0)); linear.StartPoint = new Point(1, 0); linear.EndPoint = new Point(0, 1); AddMaterial(new DiffuseMaterial(linear), "Linear"); RadialGradientBrush radial = new RadialGradientBrush(); radial.GradientStops.Add(new GradientStop(Colors.Blue, 0.0)); radial.GradientStops.Add(new GradientStop(Colors.White, 0.25)); radial.GradientStops.Add(new GradientStop(Colors.Green, 0.5)); radial.GradientStops.Add(new GradientStop(Colors.White, 0.75)); radial.GradientStops.Add(new GradientStop(Colors.Red, 1.0)); AddMaterial(new DiffuseMaterial(radial), "Radial"); AddMaterial(new SpecularMaterial(Brushes.LightBlue, 100), "Specular"); AddMaterial(new EmissiveMaterial(Brushes.DarkBlue), "Emissive"); }
public static Model3D GetNewVisual(MineralType mineralType, SharedVisuals sharedVisuals = null, double scale = 1d) { if (sharedVisuals == null) { sharedVisuals = _sharedVisuals.Value; } MineralStats stats = GetSettingsForMineralType(mineralType); Model3DGroup retVal = new Model3DGroup(); // Material MaterialGroup materials = new MaterialGroup(); if (stats.DiffuseColor.A > 0) { materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(stats.DiffuseColor))); } if (stats.SpecularColor.A > 0) { materials.Children.Add(new SpecularMaterial(new SolidColorBrush(stats.SpecularColor), stats.SpecularPower)); } if (stats.EmissiveColor.A > 0) { materials.Children.Add(new EmissiveMaterial(new SolidColorBrush(stats.EmissiveColor))); } // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = sharedVisuals.GetMineralMesh(mineralType); retVal.Children.Add(geometry); if (mineralType == MineralType.Rixium) { #region Rixium Visuals // These need to be added after the main crystal, because they are semitransparent retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, -.6), .38, .5, sharedVisuals)); retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, -.3), .44, .75, sharedVisuals)); retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, 0), .5, 1, sharedVisuals)); retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, .3), .44, .75, sharedVisuals)); retVal.Children.Add(GetRixiumTorusVisual(new Vector3D(0, 0, .6), .38, .5, sharedVisuals)); //TODO: Look at the global lighting options PointLight pointLight = new PointLight(); pointLight.Color = Color.FromArgb(255, 54, 147, 168); pointLight.Range = 20; pointLight.LinearAttenuation = .33; retVal.Children.Add(pointLight); #endregion } geometry.Transform = new ScaleTransform3D(scale, scale, scale); return(retVal); }
/// <summary> /// Read a material. /// </summary> /// <param name="reader">The reader.</param> /// <param name="chunkSize">The chunk size.</param> private void ReadMaterial(BinaryReader reader, int chunkSize) { int total = 6; string name = null; var luminance = Colors.Transparent; var diffuse = Colors.Transparent; var specular = Colors.Transparent; var shininess = Colors.Transparent; string texture = null; while (total < chunkSize) { ChunkID id = this.ReadChunkId(reader); int size = this.ReadChunkSize(reader); // Debug.WriteLine(id); total += size; switch (id) { case ChunkID.MAT_NAME01: name = this.ReadString(reader); // name = ReadString(size - 6); 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); // shininess = ReadColor(r, size); 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; this.Dispatch(() => { var mg = new MaterialGroup(); // mg.Children.Add(new DiffuseMaterial(new SolidColorBrush(luminance))); if (texture != null) { string ext = Path.GetExtension(texture); if (ext != null) { ext = ext.ToLower(); } // TGA not supported - convert textures to .png! if (ext == ".tga") { texture = Path.ChangeExtension(texture, ".png"); } var actualTexturePath = this.TexturePath ?? string.Empty; string path = Path.Combine(actualTexturePath, texture); if (File.Exists(path)) { var img = new BitmapImage(new Uri(path, UriKind.Relative)); var textureBrush = new ImageBrush(img) { ViewportUnits = BrushMappingMode.Absolute, TileMode = TileMode.Tile }; mg.Children.Add(new DiffuseMaterial(textureBrush)); } else { // Debug.WriteLine(string.Format("Texture not found: {0}", Path.GetFullPath(path))); mg.Children.Add(new DiffuseMaterial(new SolidColorBrush(diffuse))); } } else { mg.Children.Add(new DiffuseMaterial(new SolidColorBrush(diffuse))); } mg.Children.Add(new SpecularMaterial(new SolidColorBrush(specular), specularPower)); if (name != null) { this.materials[name] = mg; } }); }
internal static GeometryModel3D MakeLine3D(Vector3D start, Vector3D end, Brush brush, double scale = 0.01) { MeshGeometry3D mesh = new MeshGeometry3D(); var length = (end - start).Length; var positions = new List <Point3D>(); positions.Add(new Point3D(-scale, +scale, 0)); positions.Add(new Point3D(-scale, +scale, +length)); positions.Add(new Point3D(+scale, +scale, +length)); positions.Add(new Point3D(+scale, +scale, 0)); positions.Add(new Point3D(-scale, -scale, 0)); positions.Add(new Point3D(-scale, -scale, +length)); positions.Add(new Point3D(+scale, -scale, +length)); positions.Add(new Point3D(+scale, -scale, 0)); var segment = end - start; var defaultAxis = new Vector3D(0, 0, length); var rot = Vector3D.AngleBetween(defaultAxis, segment); var rotAxis = Vector3D.CrossProduct(defaultAxis.NormalizeTo(), segment.NormalizeTo()); var matRot = new Matrix3D(); if (rotAxis.Length > 0.0) { matRot.Rotate(new Quaternion(rotAxis, rot)); } foreach (var pos in positions) { mesh.Positions.Add(matRot.Transform(pos) + start); } // top mesh.TriangleIndices.Add(0); mesh.TriangleIndices.Add(1); mesh.TriangleIndices.Add(3); mesh.TriangleIndices.Add(2); mesh.TriangleIndices.Add(3); mesh.TriangleIndices.Add(1); // bottom mesh.TriangleIndices.Add(4); mesh.TriangleIndices.Add(5); mesh.TriangleIndices.Add(7); mesh.TriangleIndices.Add(6); mesh.TriangleIndices.Add(7); mesh.TriangleIndices.Add(5); // left mesh.TriangleIndices.Add(0); mesh.TriangleIndices.Add(1); mesh.TriangleIndices.Add(4); mesh.TriangleIndices.Add(5); mesh.TriangleIndices.Add(4); mesh.TriangleIndices.Add(1); // right mesh.TriangleIndices.Add(3); mesh.TriangleIndices.Add(2); mesh.TriangleIndices.Add(7); mesh.TriangleIndices.Add(6); mesh.TriangleIndices.Add(7); mesh.TriangleIndices.Add(2); mesh.Freeze(); var diffuse = new DiffuseMaterial(Brushes.Black); var emissive = new EmissiveMaterial(brush); diffuse.Freeze(); emissive.Freeze(); var material = new MaterialGroup(); material.Children.Add(diffuse); material.Children.Add(emissive); material.Freeze(); return(new GeometryModel3D(mesh, material) { BackMaterial = material }); }
internal static Model3DGroup CreateGeometry(List <MaterialColorProps> materialBrushes, List <EmissiveMaterial> selectionEmissives, Transform3D transform, Color cameraBase, SpecularMaterial cameraBaseSpecular, Color cameraLensColor, SpecularMaterial cameraLensSpecular, bool isFinal) { ScaleTransform3D scaleTransformLocal = new ScaleTransform3D(SCALE, SCALE, SCALE); int domeSegments = isFinal ? 2 : 10; int cylinderSegments = isFinal ? 6 : 35; Model3DGroup retVal = new Model3DGroup(); GeometryModel3D geometry; MaterialGroup material; DiffuseMaterial diffuse; SpecularMaterial specular; Transform3DGroup transformGroup = new Transform3DGroup(); transformGroup.Children.Add(new TranslateTransform3D(CameraDirection * ((HEIGHT / 2d) - .15d))); transformGroup.Children.Add(scaleTransformLocal); #region Spotlight //// Even when I make it extreme, it doesn't seem to make the gradient brighter //SpotLight spotLight = new SpotLight(); //spotLight.Color = Colors.White; ////spotLight.LinearAttenuation = 1d; //spotLight.LinearAttenuation = .1d; //spotLight.Range = 10; //spotLight.InnerConeAngle = 66; //spotLight.OuterConeAngle = 80; //spotLight.Direction = new Vector3D(0, 0, -1); //spotLight.Transform = new TranslateTransform3D(0, 0, 1); //retVal.Children.Add(spotLight); #endregion #region Back Lens if (!isFinal) { geometry = new GeometryModel3D(); material = new MaterialGroup(); RadialGradientBrush eyeBrush = new RadialGradientBrush(); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FFFFEA00"), 0d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FFF5E100"), 0.0187702d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FFECD800"), 0.0320388d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FFD46C00"), 0.0485437d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FFBC0000"), 0.104167d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF8E0000"), 0.267322d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF600000"), 0.486408d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF3E0000"), 0.61068d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF1D0000"), 0.713592d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF0E0000"), 0.760544d)); eyeBrush.GradientStops.Add(new GradientStop(UtilityWPF.ColorFromHex("#FF000000"), 1d)); diffuse = new DiffuseMaterial(eyeBrush); materialBrushes.Add(new MaterialColorProps(diffuse, cameraLensColor)); // using the final's lens color, because it's a solid color material.Children.Add(diffuse); //if (!isFinal) //{ EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent); material.Children.Add(selectionEmissive); selectionEmissives.Add(selectionEmissive); //} geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetCircle2D(cylinderSegments, transformGroup, transformGroup); retVal.Children.Add(geometry); } #endregion #region Glass Cover geometry = new GeometryModel3D(); material = new MaterialGroup(); if (isFinal) { material.Children.Add(new DiffuseMaterial(new SolidColorBrush(cameraLensColor))); // no need to add these to this.MaterialBrushes (those are only for editing) material.Children.Add(cameraLensSpecular); } else { //NOTE: Not using the world color, because that's for final. The editor has a HAL9000 eye, and this is a glass plate Color color = Color.FromArgb(26, 255, 255, 255); diffuse = new DiffuseMaterial(new SolidColorBrush(color)); materialBrushes.Add(new MaterialColorProps(diffuse, color)); material.Children.Add(diffuse); specular = new SpecularMaterial(new SolidColorBrush(Color.FromArgb(224, 255, 255, 255)), 95d); materialBrushes.Add(new MaterialColorProps(specular)); material.Children.Add(specular); EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent); material.Children.Add(selectionEmissive); selectionEmissives.Add(selectionEmissive); } geometry.Material = material; //NOTE: The position handed to the camera pool is the center of this camera. So need to leave the back material null, or it would //be like taking pictures with the lens cap on //geometry.BackMaterial = material; List <TubeRingBase> rings = new List <TubeRingBase>(); rings.Add(new TubeRingRegularPolygon(0, false, 1, 1, false)); rings.Add(new TubeRingDome(.15, false, domeSegments)); geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, false, transformGroup); retVal.Children.Add(geometry); #endregion #region Silver Ring if (!isFinal) { geometry = new GeometryModel3D(); material = new MaterialGroup(); Color color = Color.FromRgb(90, 90, 90); diffuse = new DiffuseMaterial(new SolidColorBrush(color)); materialBrushes.Add(new MaterialColorProps(diffuse, color)); material.Children.Add(diffuse); specular = new SpecularMaterial(Brushes.White, 100d); materialBrushes.Add(new MaterialColorProps(specular)); material.Children.Add(specular); //if (!isFinal) //{ EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent); material.Children.Add(selectionEmissive); selectionEmissives.Add(selectionEmissive); //} geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetRing(cylinderSegments, .97, 1.03, .05, transformGroup); retVal.Children.Add(geometry); } #endregion #region Back Cover geometry = new GeometryModel3D(); material = new MaterialGroup(); diffuse = new DiffuseMaterial(new SolidColorBrush(cameraBase)); materialBrushes.Add(new MaterialColorProps(diffuse, cameraBase)); material.Children.Add(diffuse); specular = cameraBaseSpecular; materialBrushes.Add(new MaterialColorProps(specular)); material.Children.Add(specular); if (!isFinal) { EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent); material.Children.Add(selectionEmissive); selectionEmissives.Add(selectionEmissive); } geometry.Material = material; geometry.BackMaterial = material; rings = new List <TubeRingBase>(); rings.Add(new TubeRingDome(0, false, domeSegments)); rings.Add(new TubeRingRegularPolygon(1.5, false, 1, 1, false)); transformGroup = new Transform3DGroup(); transformGroup.Children.Add(new TranslateTransform3D(0, 0, 1.65 / -2d)); transformGroup.Children.Add(scaleTransformLocal); geometry.Geometry = UtilityWPF.GetMultiRingedTube(cylinderSegments, rings, true, false, transformGroup); retVal.Children.Add(geometry); #endregion // Transform retVal.Transform = transform; // Exit Function return(retVal); }
/// <summary> /// Applies all the local shader parameters before drawing any primitives. /// </summary> protected internal override void BeginApplyLocalParameters(DrawingContext3D context, MaterialGroup material) { if (shadowMapParameter == null) return; var light = context.DirectionalLight; if (light.ShadowMap == null) return; var texture = light.ShadowMap.Texture; if (texture == null) return; shadowMapParameter.SetValue(texture); shadowMapSizeParameter.SetValue(new Vector2(1.0f / texture.Width, 1.0f / texture.Height)); lightViewProjectionParameter.SetValue(light.ShadowFrustum.Matrix); shadowColorParameter.SetValue(ShadowColor); context.graphics.SamplerStates[shadowMapSamplerIndex] = SamplerState.PointClamp; }
private Model3DGroup Initialize_Environment(List <string> modelsNames) { try { ModelImporter import = new ModelImporter(); joints = new List <Joint>(); foreach (string modelName in modelsNames) { var materialGroup = new MaterialGroup(); Color mainColor = Colors.White; EmissiveMaterial emissMat = new EmissiveMaterial(new SolidColorBrush(mainColor)); DiffuseMaterial diffMat = new DiffuseMaterial(new SolidColorBrush(mainColor)); SpecularMaterial specMat = new SpecularMaterial(new SolidColorBrush(mainColor), 200); materialGroup.Children.Add(emissMat); materialGroup.Children.Add(diffMat); materialGroup.Children.Add(specMat); var link = import.Load(basePath + modelName); GeometryModel3D model = link.Children[0] as GeometryModel3D; model.Material = materialGroup; model.BackMaterial = materialGroup; joints.Add(new Joint(link)); } RA.Children.Add(joints[0].model); RA.Children.Add(joints[1].model); RA.Children.Add(joints[2].model); RA.Children.Add(joints[3].model); RA.Children.Add(joints[4].model); RA.Children.Add(joints[5].model); RA.Children.Add(joints[6].model); RA.Children.Add(joints[7].model); RA.Children.Add(joints[8].model); RA.Children.Add(joints[9].model); RA.Children.Add(joints[10].model); #if IRB6700 RA.Children.Add(joints[11].model); RA.Children.Add(joints[12].model); RA.Children.Add(joints[13].model); RA.Children.Add(joints[14].model); RA.Children.Add(joints[15].model); RA.Children.Add(joints[16].model); RA.Children.Add(joints[17].model); RA.Children.Add(joints[18].model); RA.Children.Add(joints[19].model); #endif #if IRB6700 Color cableColor = Colors.DarkSlateGray; changeModelColor(joints[6], cableColor); changeModelColor(joints[7], cableColor); changeModelColor(joints[8], cableColor); changeModelColor(joints[9], cableColor); changeModelColor(joints[10], cableColor); changeModelColor(joints[11], cableColor); changeModelColor(joints[12], cableColor); changeModelColor(joints[13], cableColor); changeModelColor(joints[14], Colors.Gray); changeModelColor(joints[15], Colors.Red); changeModelColor(joints[16], Colors.Red); changeModelColor(joints[17], Colors.Red); changeModelColor(joints[18], Colors.Gray); changeModelColor(joints[19], Colors.Gray); joints[0].angleMin = -180; joints[0].angleMax = 180; joints[0].rotAxisX = 0; joints[0].rotAxisY = 0; joints[0].rotAxisZ = 1; joints[0].rotPointX = 0; joints[0].rotPointY = 0; joints[0].rotPointZ = 0; joints[1].angleMin = -100; joints[1].angleMax = 60; joints[1].rotAxisX = 0; joints[1].rotAxisY = 1; joints[1].rotAxisZ = 0; joints[1].rotPointX = 348; joints[1].rotPointY = -243; joints[1].rotPointZ = 775; joints[2].angleMin = -90; joints[2].angleMax = 90; joints[2].rotAxisX = 0; joints[2].rotAxisY = 1; joints[2].rotAxisZ = 0; joints[2].rotPointX = 347; joints[2].rotPointY = -376; joints[2].rotPointZ = 1923; joints[3].angleMin = -180; joints[3].angleMax = 180; joints[3].rotAxisX = 1; joints[3].rotAxisY = 0; joints[3].rotAxisZ = 0; joints[3].rotPointX = 60; joints[3].rotPointY = 0; joints[3].rotPointZ = 2125; joints[4].angleMin = -115; joints[4].angleMax = 115; joints[4].rotAxisX = 0; joints[4].rotAxisY = 1; joints[4].rotAxisZ = 0; joints[4].rotPointX = 1815; joints[4].rotPointY = 0; joints[4].rotPointZ = 2125; joints[5].angleMin = -180; joints[5].angleMax = 180; joints[5].rotAxisX = 1; joints[5].rotAxisY = 0; joints[5].rotAxisZ = 0; joints[5].rotPointX = 2008; joints[5].rotPointY = 0; joints[5].rotPointZ = 2125; #else changeModelColor(joints[6], Colors.Red); changeModelColor(joints[7], Colors.Black); changeModelColor(joints[8], Color.Black); changeModelColor(joints[9], Colors.Black); changeModelColor(joints[10], Colors.Gray); RA.Children.Add(joints[0].model); RA.Children.Add(joints[1].model); RA.Children.Add(joints[2].model); RA.Children.Add(joints[3].model); RA.Children.Add(joints[4].model); RA.Children.Add(joints[5].model); RA.Children.Add(joints[6].model); RA.Children.Add(joints[7].model); RA.Children.Add(joints[8].model); RA.Children.Add(joints[9].model); RA.Children.Add(joints[10].model); joints[0].angleMin = -180; joints[0].angleMax = 180; joints[0].rotAxisX = 0; joints[0].rotAxisY = 0; joints[0].rotAxisZ = 1; joints[0].rotPointX = 0; joints[0].rotPointY = 0; joints[0].rotPointZ = 0; joints[1].angleMin = -100; joints[1].angleMax = 60; joints[1].rotAxisX = 0; joints[1].rotAxisY = 1; joints[1].rotAxisZ = 0; joints[1].rotPointX = 175; joints[1].rotPointY = -200; joints[1].rotPointZ = 500; joints[2].angleMin = -90; joints[2].angleMax = 90; joints[2].rotAxisX = 0; joints[2].rotAxisY = 1; joints[2].rotAxisZ = 0; joints[2].rotPointX = 190; joints[2].rotPointY = -700; joints[2].rotPointZ = 1595; joints[3].angleMin = -180; joints[3].angleMax = 180; joints[3].rotAxisX = 1; joints[3].rotAxisY = 0; joints[3].rotAxisZ = 0; joints[3].rotPointX = 400; joints[3].rotPointY = 0; joints[3].rotPointZ = 1765; joints[4].angleMin = -115; joints[4].angleMax = 115; joints[4].rotAxisX = 0; joints[4].rotAxisY = 1; joints[4].rotAxisZ = 0; joints[4].rotPointX = 1405; joints[4].rotPointY = 50; joints[4].rotPointZ = 1765; joints[5].angleMin = -180; joints[5].angleMax = 180; joints[5].rotAxisX = 1; joints[5].rotAxisY = 0; joints[5].rotAxisZ = 0; joints[5].rotPointX = 1405; joints[5].rotPointY = 0; joints[5].rotPointZ = 1765; #endif } catch (Exception e) { MessageBox.Show("Exception Error:" + e.StackTrace); } return(RA); }
private void ProcessGXCommand(MaterialGroup matgroup, byte cmd, ref uint pos) { VertexList vtxlist = null; if (matgroup.m_Geometry.Count > 0) vtxlist = matgroup.m_Geometry[matgroup.m_Geometry.Count - 1]; System.IO.StreamWriter sw = null; if (lolol) sw = new System.IO.StreamWriter(System.IO.File.Open("hurrdurr.txt", System.IO.FileMode.Append)); // if (((cmd & 0xF0) == 0x10) && (cmd != 0x14)) // throw new Exception(String.Format("MATRIX COMMAND {0:X2}", cmd)); switch (cmd) { // nop case 0x00: break; // matrix commands case 0x10: pos += 4; break; case 0x11: break; case 0x12: pos += 4; break; case 0x13: pos += 4; break; // matrix restore (used for animation) case 0x14: { uint param = m_File.Read32(pos); pos += 4; m_CurVertex.m_MatrixID = param & 0x1F; } break; // more matrix commands case 0x15: break; case 0x16: pos += 64; break; case 0x17: pos += 48; break; case 0x18: pos += 64; break; case 0x19: pos += 48; break; case 0x1A: pos += 36; break; case 0x1B: pos += 12; break; case 0x1C: pos += 12; break; // set color case 0x20: { uint raw = m_File.Read32(pos); pos += 4; byte red = (byte)((raw << 3) & 0xF8); byte green = (byte)((raw >> 2) & 0xF8); byte blue = (byte)((raw >> 7) & 0xF8); byte alpha = (byte)((matgroup.m_PolyAttribs >> 13) & 0xF8); alpha |= (byte)(alpha >> 5); m_CurVertex.m_Color = Color.FromArgb(alpha, red, green, blue); if (lolol) sw.Write(String.Format("COLOR {0}\n", m_CurVertex.m_Color)); } break; // normal case 0x21: { uint param = m_File.Read32(pos); pos += 4; short x = (short)((param << 6) & 0xFFC0); short y = (short)((param >> 4) & 0xFFC0); short z = (short)((param >> 14) & 0xFFC0); m_CurVertex.m_Normal.X = (float)x / 512.0f; m_CurVertex.m_Normal.Y = (float)y / 512.0f; m_CurVertex.m_Normal.Z = (float)z / 512.0f; } break; // texcoord case 0x22: { uint param = m_File.Read32(pos); pos += 4; short s = (short)(param & 0xFFFF); short t = (short)(param >> 16); m_CurVertex.m_TexCoord.X = (float)s / 16.0f; m_CurVertex.m_TexCoord.Y = (float)t / 16.0f; Vector2 texsize = new Vector2((float)matgroup.m_Texture.m_Width, (float)matgroup.m_Texture.m_Height); if (lolol) sw.Write(String.Format("TEXCOORD {0} (TEXSIZE {1} SCALE {2} TRANS {3})\n", m_CurVertex.m_TexCoord, texsize, matgroup.m_TexCoordScale, matgroup.m_TexCoordTrans)); Vector2.Add(ref m_CurVertex.m_TexCoord, ref matgroup.m_TexCoordTrans, out m_CurVertex.m_TexCoord); Vector2.Multiply(ref m_CurVertex.m_TexCoord, ref matgroup.m_TexCoordScale, out m_CurVertex.m_TexCoord); /* if ((matgroup.m_TexParams & 0xC0000000) != 0) { m_CurVertex.m_TexCoord.Y += matgroup.m_Texture.m_Height; }*/ //Vector2 texsize = new Vector2((float)matgroup.m_Texture.m_Width, (float)matgroup.m_Texture.m_Height); Vector2.Divide(ref m_CurVertex.m_TexCoord, ref texsize, out m_CurVertex.m_TexCoord); // s = s*matrix[0] + t*matrix[4] + matrix[8]/16 + matrix[12]/16 // t = s*matrix[1] + t*matrix[5] + matrix[9]/16 + matrix[13]/16 // s = s*sscale + 1/16*(strans*sscale) // t = t*tscale + 1/16*(ttrans*tscale) } break; // define vertex case 0x23: { uint param1 = m_File.Read32(pos); pos += 4; uint param2 = m_File.Read32(pos); pos += 4; short x = (short)(param1 & 0xFFFF); short y = (short)(param1 >> 16); short z = (short)(param2 & 0xFFFF); m_CurVertex.m_Position.X = ((float)x / 4096.0f) * m_ScaleFactor; m_CurVertex.m_Position.Y = ((float)y / 4096.0f) * m_ScaleFactor; m_CurVertex.m_Position.Z = ((float)z / 4096.0f) * m_ScaleFactor; vtxlist.m_VertexList.Add(m_CurVertex); if (lolol) sw.Write(String.Format("VERTEX {0}\n", m_CurVertex.m_Position)); } break; case 0x24: { uint param = m_File.Read32(pos); pos += 4; short x = (short)((param << 6) & 0xFFC0); short y = (short)((param >> 4) & 0xFFC0); short z = (short)((param >> 14) & 0xFFC0); m_CurVertex.m_Position.X = ((float)x / 4096.0f) * m_ScaleFactor; m_CurVertex.m_Position.Y = ((float)y / 4096.0f) * m_ScaleFactor; m_CurVertex.m_Position.Z = ((float)z / 4096.0f) * m_ScaleFactor; vtxlist.m_VertexList.Add(m_CurVertex); if (lolol) sw.Write(String.Format("VERTEX {0}\n", m_CurVertex.m_Position)); } break; case 0x25: { uint param = m_File.Read32(pos); pos += 4; short x = (short)(param & 0xFFFF); short y = (short)(param >> 16); m_CurVertex.m_Position.X = ((float)x / 4096.0f) * m_ScaleFactor; m_CurVertex.m_Position.Y = ((float)y / 4096.0f) * m_ScaleFactor; vtxlist.m_VertexList.Add(m_CurVertex); if (lolol) sw.Write(String.Format("VERTEX {0}\n", m_CurVertex.m_Position)); } break; case 0x26: { uint param = m_File.Read32(pos); pos += 4; short x = (short)(param & 0xFFFF); short z = (short)(param >> 16); m_CurVertex.m_Position.X = ((float)x / 4096.0f) * m_ScaleFactor; m_CurVertex.m_Position.Z = ((float)z / 4096.0f) * m_ScaleFactor; vtxlist.m_VertexList.Add(m_CurVertex); if (lolol) sw.Write(String.Format("VERTEX {0}\n", m_CurVertex.m_Position)); } break; case 0x27: { uint param = m_File.Read32(pos); pos += 4; short y = (short)(param & 0xFFFF); short z = (short)(param >> 16); m_CurVertex.m_Position.Y = ((float)y / 4096.0f) * m_ScaleFactor; m_CurVertex.m_Position.Z = ((float)z / 4096.0f) * m_ScaleFactor; vtxlist.m_VertexList.Add(m_CurVertex); if (lolol) sw.Write(String.Format("VERTEX {0}\n", m_CurVertex.m_Position)); } break; case 0x28: { uint param = m_File.Read32(pos); pos += 4; short x = (short)((param << 6) & 0xFFC0); short y = (short)((param >> 4) & 0xFFC0); short z = (short)((param >> 14) & 0xFFC0); m_CurVertex.m_Position.X += (((float)x / 262144.0f) * m_ScaleFactor); m_CurVertex.m_Position.Y += (((float)y / 262144.0f) * m_ScaleFactor); m_CurVertex.m_Position.Z += (((float)z / 262144.0f) * m_ScaleFactor); vtxlist.m_VertexList.Add(m_CurVertex); if (lolol) sw.Write(String.Format("VERTEX {0}\n", m_CurVertex.m_Position)); } break; case 0x29: pos += 4; break; case 0x2A: pos += 4; break; case 0x2B: pos += 4; break; // lighting commands case 0x30: pos += 4; break; case 0x31: pos += 4; break; case 0x32: pos += 4; break; case 0x33: pos += 4; break; case 0x34: pos += 128; break; // Begin vertex list case 0x40: { uint param = m_File.Read32(pos); pos += 4; vtxlist = new VertexList(); matgroup.m_Geometry.Add(vtxlist); vtxlist.m_PolyType = param & 0x3; vtxlist.m_VertexList = new List<Vertex>(); if (lolol) sw.Write(String.Format("BEGIN {0}\n", param)); } break; // End vertex list (dummy) case 0x41: if (lolol) sw.Write("END\n"); break; // misc. case 0x50: pos += 4; break; case 0x60: pos += 4; break; case 0x70: pos += 12; break; case 0x71: pos += 8; break; case 0x72: pos += 4; break; default: throw new Exception(String.Format("Unknown GX command {0:X2} in BMD file", cmd)); } if (lolol) sw.Close(); }
/// <summary> /// Creates the text material. /// </summary> /// <param name="items">The items.</param> /// <param name="createElement">The create element.</param> /// <param name="background">The background.</param> /// <param name="elementMap">The element map.</param> /// <param name="elementPositions">The element positions.</param> /// <returns>Material.</returns> public static Material CreateTextMaterial( IEnumerable <TextItem> items, Func <string, FrameworkElement> createElement, Brush background, out Dictionary <string, FrameworkElement> elementMap, out Dictionary <FrameworkElement, Rect> elementPositions) { var panel = new WrapPanel(); elementMap = new Dictionary <string, FrameworkElement>(); foreach (var item in items) { if (elementMap.ContainsKey(item.Text)) { continue; } var e = createElement(item.Text); elementMap[item.Text] = e; panel.Children.Add(e); } int pw = OptimizeSize(panel, 1024); var ph = (int)Math.Min(pw, panel.ActualHeight); elementPositions = new Dictionary <FrameworkElement, Rect>(); foreach (FrameworkElement element in panel.Children) { var loc = element.TranslatePoint(new Point(0, 0), panel); double x = (int)Math.Floor(loc.X); double y = (int)Math.Floor(loc.Y); double x2 = (int)Math.Ceiling(loc.X + element.RenderSize.Width); double y2 = (int)Math.Ceiling(loc.Y + element.RenderSize.Height); elementPositions[element] = new Rect(x / pw, y / ph, (x2 - x) / pw, (y2 - y) / ph); } // Create the bitmap var rtb = new RenderTargetBitmap(pw, ph, 96, 96, PixelFormats.Pbgra32); rtb.Render(panel); rtb.Freeze(); var ib = new ImageBrush(rtb) { Stretch = Stretch.Fill, ViewboxUnits = BrushMappingMode.RelativeToBoundingBox, Viewbox = new Rect(0, 0, 1, 1), ViewportUnits = BrushMappingMode.Absolute, Viewport = new Rect(0, 0, 1, 1), TileMode = TileMode.None, AlignmentX = AlignmentX.Left, AlignmentY = AlignmentY.Top }; if (background != null && !background.Equals(Brushes.Transparent)) { var mg = new MaterialGroup(); mg.Children.Add(new DiffuseMaterial(Brushes.Black)); mg.Children.Add(new EmissiveMaterial(ib)); return(mg); } return(new DiffuseMaterial(ib) { Color = Colors.White }); }
private ModelVisual3D ConvertMDL(MDL.MDLFile _mdlFile) { ModelVisual3D newmodel = new ModelVisual3D(); Model3DGroup model = new Model3DGroup(); List<MDL.MDLObject> meshes = new List<MDL.MDLObject>(); if (_mdlFile.RootObject.Count(x => x.type == MDL.MDLType.mdl_group) > 0) { meshes = _mdlFile.RootObject.Where(x => x.type == MDL.MDLType.mdl_group).First().childrens.Where(x => x.type == MDL.MDLType.mdl_mesh).ToList(); } else { meshes = _mdlFile.RootObject.Where(x => x.type == MDL.MDLType.mdl_mesh).ToList(); } IOrderedEnumerable<MDL.MDLObject> orderedMeshes = meshes.OrderBy(x => -x.mesh.nfaces); for (int itemindex = 0; itemindex < orderedMeshes.Count(); itemindex++) { MDL.MDLObject item = meshes[itemindex]; if (item.lodval < 1 || orderedMeshes.Count() == 1 ) { MeshGeometry3D mesh = new MeshGeometry3D(); for (int i = 0; i < item.mesh.vertices.Count(); i++) { mesh.Positions.Add(new Point3D(item.mesh.vertices[i].x, item.mesh.vertices[i].y, item.mesh.vertices[i].z)); mesh.TextureCoordinates.Add(new Point(item.mesh.vertices[i].mx, item.mesh.vertices[i].my)); Vector3D normal = new Vector3D(item.mesh.vertices[i].nx, item.mesh.vertices[i].ny, item.mesh.vertices[i].nz); mesh.Normals.Add(normal); } _bounds = mesh.Bounds; for (int i = item.mesh.faces.Count() - 1; i > -1; i--) { mesh.TriangleIndices.Add(item.mesh.faces[i]); } if (_textures.Count > 0) 0 && item.textidx > -1) { ImageBrush ib = new ImageBrush(); int textureIndex = item.textidx; if (textureIndex < 0) textureIndex = 0; ib.ImageSource = loadBitmap(_textures[textureIndex]); Material diffuse1 = new DiffuseMaterial(ib); Material spec1 = new SpecularMaterial(ib, 40); MaterialGroup matGroup = new MaterialGroup(); matGroup.Children.Add(diffuse1); matGroup.Children.Add(spec1); GeometryModel3D gmodel = new GeometryModel3D(mesh, matGroup); model.Children.Add(gmodel); } else { Material material = new DiffuseMaterial(new SolidColorBrush(Colors.Gray)); GeometryModel3D gmodel = new GeometryModel3D(mesh, material); model.Children.Add(gmodel); } } }
public static VitesseDecoupeLaser Find(this IEntityProvider<VitesseDecoupeLaser, string> entityProvider,int code,MaterialGroup matiere,double epaisseur,GazDecoupe gaz) { return entityProvider.Find(code.ToString(), matiere.ToString(), epaisseur.ToString(), gaz.ToString()); }
private static void LoadModel3d(Model3DGroup myModel, string filename) { var contentPath = ToolboxUpdater.GetApplicationContentPath(); var tagData = MyModel.LoadCustomModelData(filename); //var model = new MyModelImporter(); //model.ImportData(filename); Dictionary <string, VRage.Import.MyModelDummy> dummies = null; VRageMath.PackedVector.Byte4[] normals = null; VRageMath.PackedVector.HalfVector2[] texCoords0 = null; //VRageMath.PackedVector.Byte4[] binormals = null; //VRageMath.PackedVector.Byte4[] tangents = null; //VRageMath.PackedVector.HalfVector2[] texCoords1 = null; VRageMath.PackedVector.HalfVector4[] vertices = null; List <VRage.Import.MyMeshPartInfo> meshParts = null; //float specularShininess = 0; float specularPower = 0; //VRage.Import.MyModelInfo modelInfo = null; foreach (var kvp in tagData) { if (kvp.Key == MyImporterConstants.TAG_DUMMIES) { dummies = (Dictionary <string, VRage.Import.MyModelDummy>)kvp.Value; } if (kvp.Key == MyImporterConstants.TAG_VERTICES) { vertices = (VRageMath.PackedVector.HalfVector4[])kvp.Value; } if (kvp.Key == MyImporterConstants.TAG_MESH_PARTS) { meshParts = (List <VRage.Import.MyMeshPartInfo>)kvp.Value; } //if (kvp.Key == MyImporterConstants.TAG_MODEL_INFO) modelInfo = (VRage.Import.MyModelInfo)kvp.Value; //if (kvp.Key == MyImporterConstants.TAG_SPECULAR_SHININESS) specularShininess = (float)kvp.Value; if (kvp.Key == MyImporterConstants.TAG_SPECULAR_POWER) { specularPower = (float)kvp.Value; } if (kvp.Key == MyImporterConstants.TAG_NORMALS) { normals = (VRageMath.PackedVector.Byte4[])kvp.Value; } if (kvp.Key == MyImporterConstants.TAG_TEXCOORDS0) { texCoords0 = (VRageMath.PackedVector.HalfVector2[])kvp.Value; } //if (kvp.Key == MyImporterConstants.TAG_BINORMALS) binormals = (VRageMath.PackedVector.Byte4[])kvp.Value; //if (kvp.Key == MyImporterConstants.TAG_TANGENTS) tangents = (VRageMath.PackedVector.Byte4[])kvp.Value; //if (kvp.Key == MyImporterConstants.TAG_TEXCOORDS1) texCoords1 = (VRageMath.PackedVector.HalfVector2[])kvp.Value; } foreach (var meshPart in meshParts) { GeometryModel3D geomentryModel = new GeometryModel3D(); myModel.Children.Add(geomentryModel); MeshGeometry3D meshGeometery = new MeshGeometry3D(); geomentryModel.Geometry = meshGeometery; #region mesh parts meshGeometery.Normals = new Vector3DCollection(); meshGeometery.Positions = new Point3DCollection(); meshGeometery.TextureCoordinates = new PointCollection(); meshGeometery.TriangleIndices = new Int32Collection(); for (var i = 0; i < normals.Length; i++) { meshGeometery.Normals.Add(VRage.Import.VF_Packer.UnpackNormal(ref normals[i]).ToVector3D()); } foreach (var vertex in vertices) { var vector = vertex.ToVector4(); meshGeometery.Positions.Add(new Point3D(vector.W * vector.X, vector.W * vector.Y, vector.W * vector.Z)); } // http://blogs.msdn.com/b/danlehen/archive/2005/11/06/489627.aspx //var texTransform = MeshHelper.TransformVector(new Vector3D(0, 0, 0), -90, 90, 0); //Transform="scale(1,-1) translate(0,1)" foreach (var vertex in texCoords0) { meshGeometery.TextureCoordinates.Add(vertex.ToVector2().ToPoint()); //var point = vertex.ToVector2().ToPoint(); //meshGeometery.TextureCoordinates.Add(new Point(point.X, ((point.Y + 0) * +1) + 0)); } //foreach (var index in meshPart.m_indices) //{ // meshGeometery.TriangleIndices.Add(index); //} // Flip the indicides so the textures are on the Outside, not the inside. for (var i = 0; i < meshPart.m_indices.Count; i += 3) { try { meshGeometery.TriangleIndices.Add(meshPart.m_indices[i + 2]); meshGeometery.TriangleIndices.Add(meshPart.m_indices[i + 1]); meshGeometery.TriangleIndices.Add(meshPart.m_indices[i + 0]); } catch { break; } } #endregion if (meshPart.m_MaterialDesc != null) { #region filenames var diffuseTextureName = meshPart.m_MaterialDesc.Textures.FirstOrDefault().Value; var directoryName = Path.GetDirectoryName(diffuseTextureName); var textureName = Path.GetFileNameWithoutExtension(diffuseTextureName); var textureExt = Path.GetExtension(diffuseTextureName); if (textureName.LastIndexOf(C_POSTFIX_DIFFUSE) == (textureName.Length - 2)) { textureName = textureName.Substring(0, textureName.Length - 2); } if (textureName.LastIndexOf(C_POSTFIX_DIFFUSE_EMISSIVE) == (textureName.Length - 3)) { textureName = textureName.Substring(0, textureName.Length - 3); } if (textureName.LastIndexOf(C_POSTFIX_MASK_EMISSIVE) == (textureName.Length - 3)) { textureName = textureName.Substring(0, textureName.Length - 3); } var maskTextureFile = Path.Combine(Path.Combine(contentPath, directoryName), textureName + C_POSTFIX_MASK_EMISSIVE + textureExt); var diffuseTextureFile = Path.Combine(Path.Combine(contentPath, directoryName), textureName + C_POSTFIX_DIFFUSE_EMISSIVE + textureExt); var specularTextureFile = Path.Combine(Path.Combine(contentPath, directoryName), textureName + C_POSTFIX_NORMAL_SPECULAR + textureExt); #endregion // Jan.Nekvapil: // HSV in color mask isnt absolute value, as you can see ingame in Color Picker, Hue is absolute and Saturation with Value are just offsets to texture values. var ambient = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF); var diffuseColor = meshPart.m_MaterialDesc.DiffuseColor.ToSandboxMediaColor(); //var specular = meshPart.m_MaterialDesc.SpecularColor.ToSandboxMediaColor(); var diffuseBrush = new SolidColorBrush(diffuseColor); var colorBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0x00)); // method in memory source //var defaultImage = SEToolbox.ImageLibrary.ImageTextureUtil.CreateImage(Path.Combine(contentPath, meshPart.m_MaterialDesc.DiffuseTextureName)); //var defaultImageBrush = defaultImage == null ? null : new ImageBrush(defaultImage) { ViewportUnits = BrushMappingMode.Absolute }; // method file //var imageBitmap = SEToolbox.ImageLibrary.ImageTextureUtil.CreateBitmap(textureFile); //var tempFile = Path.Combine(@"C:\temp", Path.GetFileNameWithoutExtension(textureFile) + ".png"); //ImageTextureUtil.WriteImage(imageBitmap, tempFile); //var imageBrush = new ImageBrush(new BitmapImage(new Uri(tempFile, UriKind.Absolute))); //MaterialGroup myBackMatGroup = new MaterialGroup(); //myBackMatGroup.Children.Add(new DiffuseMaterial() { AmbientColor = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), Brush = diffuseImageBrush, Color = diffuseColor }); //myBackMatGroup.Children.Add(new SpecularMaterial() { Brush = maskImageBrush, Color = specular, SpecularPower = specularPower }); //geomentryModel.BackMaterial = myBackMatGroup; MaterialGroup myMatGroup = new MaterialGroup(); if (File.Exists(maskTextureFile)) { var cubeColor = Color.FromArgb(255, 159, 68, 68); //var diffuseTextureImage = SEToolbox.ImageLibrary.ImageTextureUtil.CreateImage(maskTextureFile, false); //var diffuseImageBrush = diffuseTextureImage == null ? null : new ImageBrush(diffuseTextureImage) { ViewportUnits = BrushMappingMode.Absolute }; //myMatGroup.Children.Add(new DiffuseMaterial() { Brush = diffuseImageBrush, Color = diffuseColor, AmbientColor = ambient }); myMatGroup.Children.Add(new DiffuseMaterial() { Brush = new SolidColorBrush(cubeColor), Color = cubeColor, AmbientColor = ambient }); var maskTextureImage = SEToolbox.ImageLibrary.ImageTextureUtil.CreateImage(maskTextureFile, false, new MaskPixelEffect()); var maskImageBrush = maskTextureImage == null ? null : new ImageBrush(maskTextureImage) { ViewportUnits = BrushMappingMode.Absolute }; myMatGroup.Children.Add(new DiffuseMaterial() { Brush = maskImageBrush, Color = diffuseColor, AmbientColor = ambient }); //myMatGroup.Children.Add(new EmissiveMaterial() { Brush = maskImageBrush, Color = diffuseColor }); //myMatGroup.Children.Add(new SpecularMaterial() { Brush = specularImageBrush, Color = specular, SpecularPower = specularPower }); var emissiveTextureImage = SEToolbox.ImageLibrary.ImageTextureUtil.CreateImage(maskTextureFile, false, new EmissivePixelEffect(0)); var emissiveImageBrush = emissiveTextureImage == null ? null : new ImageBrush(emissiveTextureImage) { ViewportUnits = BrushMappingMode.Absolute }; myMatGroup.Children.Add(new EmissiveMaterial() { Brush = emissiveImageBrush, Color = diffuseColor }); } else { var diffuseTextureImage = SEToolbox.ImageLibrary.ImageTextureUtil.CreateImage(diffuseTextureFile, true); var diffuseImageBrush = diffuseTextureImage == null ? null : new ImageBrush(diffuseTextureImage) { ViewportUnits = BrushMappingMode.Absolute }; myMatGroup.Children.Add(new DiffuseMaterial() { Brush = diffuseImageBrush, Color = diffuseColor, AmbientColor = ambient }); var emissiveTextureImage = SEToolbox.ImageLibrary.ImageTextureUtil.CreateImage(diffuseTextureFile, false, new EmissivePixelEffect(0)); var emissiveImageBrush = emissiveTextureImage == null ? null : new ImageBrush(emissiveTextureImage) { ViewportUnits = BrushMappingMode.Absolute }; //myMatGroup.Children.Add(new EmissiveMaterial() { Brush = emissiveImageBrush, Color = diffuseColor }); myMatGroup.Children.Add(new EmissiveMaterial() { Brush = emissiveImageBrush, Color = Color.FromArgb(0x00, 0xFF, 0xFF, 0xFF) }); } if (File.Exists(specularTextureFile)) { //new NormalMaterial() Normal maps? var specularTextureImage = SEToolbox.ImageLibrary.ImageTextureUtil.CreateImage(specularTextureFile); var specularImageBrush = specularTextureImage == null ? null : new ImageBrush(specularTextureImage) { ViewportUnits = BrushMappingMode.Absolute }; myMatGroup.Children.Add(new SpecularMaterial() { Brush = specularImageBrush, SpecularPower = specularPower }); } geomentryModel.Material = myMatGroup; } else { // No material assigned. MaterialGroup myMatGroup = new MaterialGroup(); var cubeColor = Color.FromArgb(255, 159, 68, 68); var ambient = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF); var diffuseColor = Color.FromArgb(255, 159, 68, 68); var colorBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0x00)); myMatGroup.Children.Add(new DiffuseMaterial() { Brush = new SolidColorBrush(cubeColor), Color = cubeColor, AmbientColor = ambient }); myMatGroup.Children.Add(new DiffuseMaterial() { Brush = colorBrush, Color = diffuseColor, AmbientColor = ambient }); geomentryModel.Material = myMatGroup; } foreach (var dummy in dummies) { foreach (var data in dummy.Value.CustomData) { if (data.Key == "file") { var newfilename = Path.Combine(Path.GetDirectoryName(filename), data.Value + ".mwm"); LoadModel3d(myModel, newfilename); } } } } }
private Model3DGroup CreateModel(bool isFinal) { const double PLATEHEIGHT = .1d; const double PLATEHEIGHTHALF = PLATEHEIGHT * .5d; const double PLATEHEIGHTQUARTER = PLATEHEIGHT * .25d; Model3DGroup retVal = new Model3DGroup(); GeometryModel3D geometry; MaterialGroup material; DiffuseMaterial diffuse; SpecularMaterial specular; #region Main Box geometry = new GeometryModel3D(); material = new MaterialGroup(); diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.AmmoBox_Color)); this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.AmmoBox_Color)); material.Children.Add(diffuse); specular = WorldColors.AmmoBox_Specular; this.MaterialBrushes.Add(new MaterialColorProps(specular)); material.Children.Add(specular); if (!isFinal) { EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent); material.Children.Add(selectionEmissive); this.SelectionEmissives.Add(selectionEmissive); } geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-.5d + PLATEHEIGHTQUARTER, (-.5d + PLATEHEIGHTQUARTER) * RATIOY, -.5d * RATIOZ), new Point3D(.5d - PLATEHEIGHTQUARTER, (.5d - PLATEHEIGHTQUARTER) * RATIOY, .5d * RATIOZ)); retVal.Children.Add(geometry); #endregion #region Plates for (int cntr = -1; cntr <= 1; cntr++) { geometry = new GeometryModel3D(); material = new MaterialGroup(); diffuse = new DiffuseMaterial(new SolidColorBrush(WorldColors.AmmoBoxPlate_Color)); this.MaterialBrushes.Add(new MaterialColorProps(diffuse, WorldColors.AmmoBoxPlate_Color)); material.Children.Add(diffuse); specular = WorldColors.AmmoBoxPlate_Specular; this.MaterialBrushes.Add(new MaterialColorProps(specular)); material.Children.Add(specular); if (!isFinal) { EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent); material.Children.Add(selectionEmissive); this.SelectionEmissives.Add(selectionEmissive); } geometry.Material = material; geometry.BackMaterial = material; double z = (.5d - PLATEHEIGHT + PLATEHEIGHTQUARTER) * cntr; geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-.5d, -.5d * RATIOY, (z - PLATEHEIGHTHALF) * RATIOZ), new Point3D(.5d, .5d * RATIOY, (z + PLATEHEIGHTHALF) * RATIOZ)); retVal.Children.Add(geometry); } #endregion // Transform retVal.Transform = GetTransformForGeometry(isFinal); // Exit Function return(retVal); }
private static Model3D GetDoubleArrow(Axis axis, DiffuseMaterial diffuse, SpecularMaterial specular, double cylinderRadius, double cylinderHeight, double coneRadius, double coneHeight, double coneOffset) { // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(diffuse); materials.Children.Add(specular); Model3DGroup retVal = new Model3DGroup(); #region cylinder // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, cylinderRadius, cylinderHeight); retVal.Children.Add(geometry); #endregion #region cone + // Geometry Model geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetCone_AlongX(10, coneRadius, coneHeight); Transform3DGroup transform = new Transform3DGroup(); // rotate needs to be added before translate //transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(Math3D.GetRandomVectorSpherical(_rand, 10), Math3D.GetNearZeroValue(_rand, 360d)))); transform.Children.Add(new TranslateTransform3D(new Vector3D(coneOffset, 0, 0))); geometry.Transform = transform; retVal.Children.Add(geometry); #endregion #region cone - // Geometry Model geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetCone_AlongX(10, coneRadius, coneHeight); transform = new Transform3DGroup(); // rotate needs to be added before translate transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 180))); transform.Children.Add(new TranslateTransform3D(new Vector3D(-coneOffset, 0, 0))); geometry.Transform = transform; retVal.Children.Add(geometry); #endregion retVal.Transform = GetTransform(axis, true); // Exit Function return(retVal); }
public BMD(NitroFile file) { m_File = file; m_FileName = file.m_Name; /* if (m_File.m_ID == 741) lolol = true; else*/ lolol = false; // Keep a list of pointers so it's easier to add/remove entries, space etc. m_PointerList = new List<PointerReference>(); m_ScaleFactor = (float)(1 << (int)m_File.Read32(0x0)); // ModelChunk refers to Bone m_NumModelChunks = m_File.Read32(0x04); m_ModelChunksOffset = m_File.Read32(0x08); AddPointer(0x08); for (int i = 0; i < m_NumModelChunks; i++) { AddPointer((uint)(m_ModelChunksOffset + (i * 64) + 0x04)); AddPointer((uint)(m_ModelChunksOffset + (i * 64) + 0x34)); AddPointer((uint)(m_ModelChunksOffset + (i * 64) + 0x38)); } // PolyChunk refers to Display List m_NumPolyChunks = m_File.Read32(0x0C); m_PolyChunksOffset = m_File.Read32(0x10); AddPointer(0x10); for (int i = 0; i < m_NumPolyChunks; i++) { // Offset to Display List within Display List entries AddPointer((uint)(m_PolyChunksOffset + (i * 8) + 4)); // Offsets within the Display List 16 byte headers AddPointer(m_File.Read32((uint)(m_PolyChunksOffset + (i * 8) + 4)) + 0x04); AddPointer(m_File.Read32((uint)(m_PolyChunksOffset + (i * 8) + 4)) + 0x0C); } m_NumTexChunks = m_File.Read32(0x14); m_TexChunksOffset = m_File.Read32(0x18); m_TextureIDs = new Dictionary<string, uint>(); AddPointer(0x18); for (int i = 0; i < m_NumTexChunks; i++) { AddPointer((uint)(m_TexChunksOffset + (i * 20) + 0)); AddPointer((uint)(m_TexChunksOffset + (i * 20) + 4)); m_TextureIDs.Add(m_File.ReadString(m_File.Read32((uint)(m_TexChunksOffset + (20 * i))), 0), (uint)i); } m_NumPalChunks = m_File.Read32(0x1C); m_PalChunksOffset = m_File.Read32(0x20); m_PaletteIDs = new Dictionary<string, uint>(); AddPointer(0x20); for (int i = 0; i < m_NumPalChunks; i++) { AddPointer((uint)(m_PalChunksOffset + (i * 16) + 0)); AddPointer((uint)(m_PalChunksOffset + (i * 16) + 4)); m_PaletteIDs.Add(m_File.ReadString(m_File.Read32((uint)(m_PalChunksOffset + (16 * i))), 0), (uint)i); } m_NumMatChunks = m_File.Read32(0x24); m_MatChunksOffset = m_File.Read32(0x28); AddPointer(0x28); for (int i = 0; i < m_NumMatChunks; i++) { AddPointer((uint)(m_MatChunksOffset + (i * 48) + 0)); } m_BoneMapOffset = m_File.Read32(0x2C); AddPointer(0x2C); m_Textures = new Dictionary<string, Texture>(); m_ModelChunks = new ModelChunk[m_NumModelChunks]; for (uint c = 0; c < m_NumModelChunks; c++) { ModelChunk mdchunk = new ModelChunk(this); m_ModelChunks[c] = mdchunk; uint mdchunkoffset = m_ModelChunksOffset + (c * 64); mdchunk.m_ID = m_File.Read32(mdchunkoffset); mdchunk.m_Name = m_File.ReadString(m_File.Read32(mdchunkoffset + 0x04), 0); // transforms part { int xscale = (int)m_File.Read32(mdchunkoffset + 0x10); int yscale = (int)m_File.Read32(mdchunkoffset + 0x14); int zscale = (int)m_File.Read32(mdchunkoffset + 0x18); short xrot = (short)m_File.Read16(mdchunkoffset + 0x1C); short yrot = (short)m_File.Read16(mdchunkoffset + 0x1E); short zrot = (short)m_File.Read16(mdchunkoffset + 0x20); int xtrans = (int)m_File.Read32(mdchunkoffset + 0x24); int ytrans = (int)m_File.Read32(mdchunkoffset + 0x28); int ztrans = (int)m_File.Read32(mdchunkoffset + 0x2C); mdchunk.m_Scale = new Vector3((float)xscale / 4096.0f, (float)yscale / 4096.0f, (float)zscale / 4096.0f); mdchunk.m_Rotation = new Vector3(((float)xrot * (float)Math.PI) / 2048.0f, ((float)yrot * (float)Math.PI) / 2048.0f, ((float)zrot * (float)Math.PI) / 2048.0f); mdchunk.m_Translation = new Vector3((float)xtrans / 4096.0f, (float)ytrans / 4096.0f, (float)ztrans / 4096.0f); mdchunk.m_Transform = Helper.SRTToMatrix(mdchunk.m_Scale, mdchunk.m_Rotation, mdchunk.m_Translation); // Used when exporting bones mdchunk.m_20_12Scale = new uint[] { (uint)xscale, (uint)yscale, (uint)zscale }; mdchunk.m_4_12Rotation = new ushort[] { (ushort)xrot, (ushort)yrot, (ushort)zrot }; mdchunk.m_20_12Translation = new uint[] { (uint)xtrans, (uint)ytrans, (uint)ztrans }; // if the chunk has a parent, apply the parent's transform to the chunk's transform. // we don't need to go further than one level because the paren't transform already // went through its parents' transforms. short parent_offset = (short)m_File.Read16(mdchunkoffset + 0x8); if (parent_offset < 0) { int parentchunkid = (int)(c + parent_offset); Matrix4.Mult(ref mdchunk.m_Transform, ref m_ModelChunks[parentchunkid].m_Transform, out mdchunk.m_Transform); } mdchunk.m_ParentOffset = parent_offset; } // If 0x0A is set to 1 the bone has children, if 0 it doesn't mdchunk.m_HasChildren = (m_File.Read16(mdchunkoffset + 0x0A) == 1); mdchunk.m_SiblingOffset = (short)(m_File.Read16(mdchunkoffset + 0x0C)); uint flags = m_File.Read32(mdchunkoffset + 0x3C); mdchunk.m_Billboard = ((flags & 0x1) == 0x1); uint numpairs = m_File.Read32(mdchunkoffset + 0x30); uint matlist = m_File.Read32(mdchunkoffset + 0x34); uint polylist = m_File.Read32(mdchunkoffset + 0x38); mdchunk.m_MatGroups = new MaterialGroup[numpairs]; for (uint i = 0; i < numpairs; i++) { MaterialGroup matgroup = new MaterialGroup(); mdchunk.m_MatGroups[i] = matgroup; byte matID = m_File.Read8(matlist + i); byte polyID = m_File.Read8(polylist + i); uint mchunkoffset = (uint)(m_MatChunksOffset + (matID * 48)); matgroup.m_ID = matID; matgroup.m_Name = m_File.ReadString(m_File.Read32(mchunkoffset), 0); uint texid = m_File.Read32(mchunkoffset + 0x04); uint palid = m_File.Read32(mchunkoffset + 0x08); matgroup.m_TexParams = m_File.Read32(mchunkoffset + 0x20); matgroup.m_PolyAttribs = m_File.Read32(mchunkoffset + 0x24); matgroup.m_DifAmbColors = m_File.Read32(mchunkoffset + 0x28); matgroup.m_SpeEmiColors = m_File.Read32(mchunkoffset + 0x2C); if ((matgroup.m_PolyAttribs & 0x30) == 0x10) matgroup.m_TexEnvMode = TextureEnvMode.Decal; else matgroup.m_TexEnvMode = TextureEnvMode.Modulate; switch (matgroup.m_PolyAttribs & 0xC0) { case 0x00: matgroup.m_CullMode = CullFaceMode.FrontAndBack; break; case 0x40: matgroup.m_CullMode = CullFaceMode.Front; break; case 0x80: matgroup.m_CullMode = CullFaceMode.Back; break; } matgroup.m_DiffuseColor = Helper.BGR15ToColor((ushort)matgroup.m_DifAmbColors); matgroup.m_AmbientColor = Helper.BGR15ToColor((ushort)(matgroup.m_DifAmbColors >> 16)); matgroup.m_SpecularColor = Helper.BGR15ToColor((ushort)matgroup.m_SpeEmiColors); matgroup.m_EmissionColor = Helper.BGR15ToColor((ushort)(matgroup.m_SpeEmiColors >> 16)); switch (matgroup.m_TexParams >> 30) { case 0: matgroup.m_TexCoordScale = new Vector2(1.0f, 1.0f); matgroup.m_TexCoordTrans = new Vector2(0.0f, 0.0f); break; case 1: { int sscale = (int)m_File.Read32(mchunkoffset + 0x0C); int tscale = (int)m_File.Read32(mchunkoffset + 0x10); int strans = (int)m_File.Read32(mchunkoffset + 0x18); int ttrans = (int)m_File.Read32(mchunkoffset + 0x1C); matgroup.m_TexCoordScale = new Vector2((float)sscale / 4096.0f, (float)tscale / 4096.0f); matgroup.m_TexCoordTrans = new Vector2((float)strans / 4096.0f, (float)ttrans / 4096.0f); //matgroup.m_TexCoordTrans = new Vector2(0.0f, 16.0f); /*System.Windows.Forms.MessageBox.Show(String.Format("textransform: scale:{0} trans:{1} rot:{2:X8}", matgroup.m_TexCoordScale, matgroup.m_TexCoordTrans, m_File.Read32(mchunkoffset + 0x1C)));*/ } break; case 2: goto case 1; case 3: goto case 1; default: break; // throw new Exception(String.Format("BMD: unsupported texture coord transform mode {0}", matgroup.m_TexParams >> 30)); } if (texid != 0xFFFFFFFF) { matgroup.m_Texture = ReadTexture(texid, palid); matgroup.m_TexParams |= matgroup.m_Texture.m_Params; } else matgroup.m_Texture = null; uint pchunkoffset = m_File.Read32((uint)(m_PolyChunksOffset + (polyID * 8) + 4)); uint dloffset = m_File.Read32(pchunkoffset + 0x0C); uint dlsize = m_File.Read32(pchunkoffset + 0x08); uint numbones = m_File.Read32(pchunkoffset); uint bonesoffset = m_File.Read32(pchunkoffset + 0x04); matgroup.m_BoneIDs = new ushort[numbones]; for (uint b = 0; b < numbones; b++) { byte idx1 = m_File.Read8(bonesoffset + b); matgroup.m_BoneIDs[b] = m_File.Read16((uint)(m_BoneMapOffset + (2 * idx1))); } matgroup.m_Geometry = new List<VertexList>(); m_CurVertex.m_Position = new Vector3(0, 0, 0); m_CurVertex.m_TexCoord = new Vector2(0, 0); if ((matgroup.m_DifAmbColors & 0x8000) == 0x8000) { byte alpha = (byte)((matgroup.m_PolyAttribs >> 13) & 0xF8); alpha |= (byte)(alpha >> 5); matgroup.m_Alpha = alpha; m_CurVertex.m_Color = Color.FromArgb(alpha, matgroup.m_DiffuseColor); } else m_CurVertex.m_Color = Color.Black; m_CurVertex.m_MatrixID = 0; uint dlend = dloffset + dlsize; for (uint pos = dloffset; pos < dlend; ) { byte cmd1 = m_File.Read8(pos++); byte cmd2 = m_File.Read8(pos++); byte cmd3 = m_File.Read8(pos++); byte cmd4 = m_File.Read8(pos++); ProcessGXCommand(matgroup, cmd1, ref pos); ProcessGXCommand(matgroup, cmd2, ref pos); ProcessGXCommand(matgroup, cmd3, ref pos); ProcessGXCommand(matgroup, cmd4, ref pos); } } } foreach (ModelChunk mdchunk in m_ModelChunks) { foreach (MaterialGroup matgroup in mdchunk.m_MatGroups) { matgroup.m_BoneMatrices = new Matrix4[matgroup.m_BoneIDs.Length]; for (uint b = 0; b < matgroup.m_BoneIDs.Length; b++) matgroup.m_BoneMatrices[b] = m_ModelChunks[matgroup.m_BoneIDs[b]].m_Transform; } } }
private Model3D GetModel() { const double SIZE = 4; Model3DGroup retVal = new Model3DGroup(); GeometryModel3D geometry; MaterialGroup material; var rhomb = UtilityWPF.GetRhombicuboctahedron(SIZE, SIZE, SIZE); TriangleIndexed[] triangles; #region X,Y,Z spikes double thickness = .2; double length = SIZE * 1.5; retVal.Children.Add(new BillboardLine3D() { Color = UtilityWPF.ColorFromHex("80" + ChaseColors.X), IsReflectiveColor = false, Thickness = thickness, FromPoint = new Point3D(0, 0, 0), ToPoint = new Point3D(length, 0, 0) }.Model); retVal.Children.Add(new BillboardLine3D() { Color = UtilityWPF.ColorFromHex("80" + ChaseColors.Y), IsReflectiveColor = false, Thickness = thickness, FromPoint = new Point3D(0, 0, 0), ToPoint = new Point3D(0, length, 0) }.Model); retVal.Children.Add(new BillboardLine3D() { Color = UtilityWPF.ColorFromHex("80" + ChaseColors.Z), IsReflectiveColor = false, Thickness = thickness, FromPoint = new Point3D(0, 0, 0), ToPoint = new Point3D(0, 0, length) }.Model); #endregion #region X plates geometry = new GeometryModel3D(); material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("80" + ChaseColors.X)))); material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("70DCE01D")), 5)); geometry.Material = material; geometry.BackMaterial = material; triangles = rhomb.Squares_Orth. SelectMany(o => o). Where(o => o.IndexArray.All(p => Math1D.IsNearValue(Math.Abs(o.AllPoints[p].X * 2), SIZE))). ToArray(); geometry.Geometry = UtilityWPF.GetMeshFromTriangles_IndependentFaces(triangles); retVal.Children.Add(geometry); #endregion #region Y plates geometry = new GeometryModel3D(); material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("80" + ChaseColors.Y)))); material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("702892BF")), 3)); geometry.Material = material; geometry.BackMaterial = material; triangles = rhomb.Squares_Orth. SelectMany(o => o). Where(o => o.IndexArray.All(p => Math1D.IsNearValue(Math.Abs(o.AllPoints[p].Y * 2), SIZE))). ToArray(); geometry.Geometry = UtilityWPF.GetMeshFromTriangles_IndependentFaces(triangles); retVal.Children.Add(geometry); #endregion #region Z plates geometry = new GeometryModel3D(); material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("80" + ChaseColors.Z)))); material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("B0CF1919")), 17)); geometry.Material = material; geometry.BackMaterial = material; triangles = rhomb.Squares_Orth. SelectMany(o => o). Where(o => o.IndexArray.All(p => Math1D.IsNearValue(Math.Abs(o.AllPoints[p].Z * 2), SIZE))). ToArray(); geometry.Geometry = UtilityWPF.GetMeshFromTriangles_IndependentFaces(triangles); retVal.Children.Add(geometry); #endregion #region Base geometry = new GeometryModel3D(); material = new MaterialGroup(); material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("305B687A")))); material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("507E827A")), 12)); geometry.Material = material; geometry.BackMaterial = material; triangles = UtilityCore.Iterate( rhomb.Squares_Diag.SelectMany(o => o), rhomb.Triangles ).ToArray(); geometry.Geometry = UtilityWPF.GetMeshFromTriangles_IndependentFaces(triangles); retVal.Children.Add(geometry); #endregion return(retVal); }
private static Visual3D GetAxisVisual() { const double AXIS_QUARTER = AXIS_HALF / 2; const int AXIS_SEGMENTS = 15; Model3DGroup group = new Model3DGroup(); #region Axis Up // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(UtilityWPF.GetUnlitMaterial(UtilityWPF.ColorFromHex("202020"))); // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetCone_AlongX(AXIS_SEGMENTS, AXIS_RADIUS, AXIS_HALF); Transform3DGroup transform = new Transform3DGroup(); transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), -90))); transform.Children.Add(new TranslateTransform3D(0, 0, AXIS_QUARTER)); geometry.Transform = transform; group.Children.Add(geometry); #endregion #region Axis Down // Material materials = new MaterialGroup(); materials.Children.Add(UtilityWPF.GetUnlitMaterial(UtilityWPF.ColorFromHex("F0F0F0"))); // Geometry Model geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetCone_AlongX(AXIS_SEGMENTS, AXIS_RADIUS, AXIS_HALF); transform = new Transform3DGroup(); transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90))); transform.Children.Add(new TranslateTransform3D(0, 0, -AXIS_QUARTER)); geometry.Transform = transform; group.Children.Add(geometry); #endregion #region Circle // Material materials = new MaterialGroup(); materials.Children.Add(UtilityWPF.GetUnlitMaterial(UtilityWPF.ColorFromHex("999"))); // Geometry Model geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetTorus(70, 10, CIRCLE_MINORRADIUS, CIRCLE_MAJORRADIUS); group.Children.Add(geometry); #endregion ModelVisual3D visual = new ModelVisual3D(); visual.Content = group; return(visual); }