1 |
インラインモデルは、こんな感じ。 |
1 |
<a href="http://uchukamen.files.wordpress.com/2009/01/image5b55d.png" rel="WLPP"><img title="image" style="display:inline;border-width:0;" height="244" alt="image" src="http://uchukamen.files.wordpress.com/2009/01/image5b55d.png?w=280" width="229" border="0" /></a> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
private void Sample2() { this.viewPort3D1.Name = "ZAM3DViewport3D"; viewPort3D1.ClipToBounds = true; viewPort3D1.Width = 400; viewPort3D1.Height = 300; PerspectiveCamera camera = new PerspectiveCamera(); camera.FarPlaneDistance = 10f; camera.LookDirection = new Vector3D(2.05609, -1.21509, -2.52021); camera.UpDirection = new Vector3D(0f, 1f, 0f); camera.NearPlaneDistance = 2f; camera.Position = new Point3D(-2.05609,1.21509,2.52021); camera.FieldOfView = 39f; viewPort3D1.Camera = camera; ModelVisual3D modelVisual3D = new ModelVisual3D(); Model3DGroup model3DGroup = new Model3DGroup(); modelVisual3D.Content = model3DGroup; Transform3DGroup transform3DGroup = new Transform3DGroup(); TranslateTransform3D translateTransform3D = new TranslateTransform3D(0f, 0f, 0f); ScaleTransform3D scaleTransform3D = new ScaleTransform3D(1f, 1f, 1f); AxisAngleRotation3D axisAngleRotation3D = new AxisAngleRotation3D(new Vector3D(0f, 1f, 0f), 0f); RotateTransform3D rotateTransform3D = new RotateTransform3D(); rotateTransform3D.Rotation = axisAngleRotation3D; transform3DGroup.Children.Add(translateTransform3D); transform3DGroup.Children.Add(scaleTransform3D); transform3DGroup.Children.Add(rotateTransform3D); model3DGroup.Transform = transform3DGroup; ////// AmbientLight ambientLight = new AmbientLight(Color.FromRgb(0x33, 0x33, 0x33)); model3DGroup.Children.Add(ambientLight); DirectionalLight directionalLight1 = new DirectionalLight(Colors.White, new Vector3D(-0.6f, -0.5f, -0.6f)); model3DGroup.Children.Add(directionalLight1); DirectionalLight directionalLight2 = new DirectionalLight(Colors.White, new Vector3D(0.6f, -0.5f, -0.6f)); model3DGroup.Children.Add(directionalLight2); ////// Model3DGroup model3DGroupBox = new Model3DGroup(); Transform3DGroup transform3DGroupBox = new Transform3DGroup(); TranslateTransform3D translateTransform3DBox = new TranslateTransform3D(0f, 0f, 0f); ScaleTransform3D scaleTransform3DBox = new ScaleTransform3D(1f, 1f, 1f); AxisAngleRotation3D axisAngleRotation3DBox = new AxisAngleRotation3D(new Vector3D(0f, 1f, 0f), 0f); RotateTransform3D rotateTransform3DBox = new RotateTransform3D(); rotateTransform3DBox.Rotation = axisAngleRotation3DBox; TranslateTransform3D translateTransform3DBox2 = new TranslateTransform3D(0,0,0); transform3DGroupBox.Children.Add(translateTransform3DBox); transform3DGroupBox.Children.Add(scaleTransform3DBox); transform3DGroupBox.Children.Add(rotateTransform3DBox); transform3DGroupBox.Children.Add(translateTransform3DBox2); model3DGroupBox.Transform = transform3DGroupBox; ///// GeometryModel3D geometryModel3D = new GeometryModel3D(); MaterialGroup materialGroup = new MaterialGroup(); DiffuseMaterial diffuseMaterial = new DiffuseMaterial(); diffuseMaterial.Brush = new SolidColorBrush(Color.FromRgb(0xd3, 0xc8, 0xad)); materialGroup.Children.Add(diffuseMaterial); SpecularMaterial specularMaterial = new SpecularMaterial(); specularMaterial.SpecularPower = 93f; specularMaterial.Brush = new SolidColorBrush(Color.FromRgb(0x33, 0x33, 0x33)); materialGroup.Children.Add(specularMaterial); geometryModel3D.Material = materialGroup; //// GeometryModel3D geometryModel3DBack = new GeometryModel3D(); MaterialGroup materialGroupBack = new MaterialGroup(); DiffuseMaterial diffuseMaterialBack = new DiffuseMaterial(); diffuseMaterialBack.Brush = new SolidColorBrush(Color.FromRgb(0xd3, 0xc8, 0xad)); geometryModel3DBack.Material = materialGroupBack; materialGroupBack.Children.Add(diffuseMaterialBack); SpecularMaterial specularMaterialBack = new SpecularMaterial(); specularMaterialBack.Brush = new SolidColorBrush(Color.FromRgb(0x33, 0x33, 0x33)); specularMaterialBack.SpecularPower = 93f; materialGroupBack.Children.Add(specularMaterialBack); geometryModel3D.BackMaterial = materialGroupBack; //// MeshGeometry3D meshGeometry3D = new MeshGeometry3D(); TypeConverter i32ColConv = TypeDescriptor.GetConverter(typeof(Int32Collection)); meshGeometry3D.TriangleIndices = (Int32Collection)i32ColConv.ConvertFromString("0,1,2 2,3,0 4,5,6 6,7,4 8,9,10 10,11,8 12,13,14 14,15,12 16,17,18 18,19,16 20,21,22 22,23,20"); TypeConverter vector3DColConv = TypeDescriptor.GetConverter(typeof(Vector3DCollection)); meshGeometry3D.Normals = (Vector3DCollection)vector3DColConv.ConvertFromString("0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,1 0,0,1 0,0,1 0,0,1 0,-1,0 0,-1,0 0,-1,0 0,-1,0 1,0,0 1,0,0 1,0,0 1,0,0 0,1,0 0,1,0 0,1,0 0,1,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0 "); TypeConverter point3DColConv = TypeDescriptor.GetConverter(typeof(Point3DCollection)); meshGeometry3D.Positions = (Point3DCollection)point3DColConv.ConvertFromString("-0.5,-0.5,-0.5 -0.5,0.5,-0.5 0.5,0.5,-0.5 0.5,-0.5,-0.5 -0.5,-0.5,0.5 0.5,-0.5,0.5 0.5,0.5,0.5 -0.5,0.5,0.5 -0.5,-0.5,-0.5 0.5,-0.5,-0.5 0.5,-0.5,0.5 -0.5,-0.5,0.5 0.5,-0.5,-0.5 0.5,0.5,-0.5 0.5,0.5,0.5 0.5,-0.5,0.5 0.5,0.5,-0.5 -0.5,0.5,-0.5 -0.5,0.5,0.5 0.5,0.5,0.5 -0.5,0.5,-0.5 -0.5,-0.5,-0.5 -0.5,-0.5,0.5 -0.5,0.5,0.5 "); geometryModel3D.Geometry = meshGeometry3D; model3DGroupBox.Children.Add(geometryModel3D); //// model3DGroup.Children.Add(model3DGroupBox); modelVisual3D.Content = model3DGroup; this.viewPort3D1.Children.Add(modelVisual3D); } |