ZAM3Dが生成するXAMLをC#で実装すると


インラインモデルは、こんな感じ。
image 
        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);
        }

コメントを残す

以下に詳細を記入するか、アイコンをクリックしてログインしてください。

WordPress.com ロゴ

WordPress.com アカウントを使ってコメントしています。 ログアウト / 変更 )

Twitter 画像

Twitter アカウントを使ってコメントしています。 ログアウト / 変更 )

Facebook の写真

Facebook アカウントを使ってコメントしています。 ログアウト / 変更 )

Google+ フォト

Google+ アカウントを使ってコメントしています。 ログアウト / 変更 )

%s と連携中


%d人のブロガーが「いいね」をつけました。