예제 #1
0
        public MainViewModel()
        {
            EffectsManager = new DefaultEffectsManager();
            Camera         = new OrthographicCamera()
            {
                Position = new Point3D(0, 0, -5), LookDirection = new Vector3D(0, 0, 5), UpDirection = new Vector3D(0, 1, 0)
            };
            LoadTeapotCommand = new RelayCommand((o) => { Load(0); });
            LoadSkullCommand  = new RelayCommand((o) => { Load(1); });
            LoadCloudCommand  = new RelayCommand((o) => { Load(2); });
            LoadBeetleCommand = new RelayCommand((o) => { Load(3); });
            var builder = new MeshBuilder();

            //builder.AddBox(new Vector3(0, 0, 0), 2, 2, 0.001);
            builder.AddSphere(Vector3.Zero, 0.1);
            builder.AddBox(Vector3.UnitX, 0.2, 0.2, 0.2);
            MeshModel    = builder.ToMesh();
            MeshMaterial = PhongMaterials.Yellow;

            var lineBuilder = new LineBuilder();

            lineBuilder.AddLine(Vector3.Zero, Vector3.UnitX * 1.5f);
            lineBuilder.AddLine(Vector3.Zero, Vector3.UnitY * 1.5f);
            lineBuilder.AddLine(Vector3.Zero, Vector3.UnitZ * 1.5f);
            AxisModel        = lineBuilder.ToLineGeometry3D();
            AxisModel.Colors = new Color4Collection(AxisModel.Positions.Count);
            AxisModel.Colors.Add(Colors.Red.ToColor4());
            AxisModel.Colors.Add(Colors.Red.ToColor4());
            AxisModel.Colors.Add(Colors.Green.ToColor4());
            AxisModel.Colors.Add(Colors.Green.ToColor4());
            AxisModel.Colors.Add(Colors.Blue.ToColor4());
            AxisModel.Colors.Add(Colors.Blue.ToColor4());
            AxisModelMaterial = new LineArrowHeadMaterial()
            {
                Color = Colors.White, ArrowSize = 0.05
            };
            //Load(0);
        }
예제 #2
0
        public MainViewModel()
        {            // titles
            this.Title     = "DynamicTexture Demo";
            this.SubTitle  = "WPF & SharpDX";
            EffectsManager = new DefaultEffectsManager();
            this.Camera    = new HelixToolkit.Wpf.SharpDX.PerspectiveCamera
            {
                Position      = new Point3D(10, 10, 10),
                LookDirection = new Vector3D(-10, -10, -10),
                UpDirection   = new Vector3D(0, 1, 0)
            };
            this.Light1Color       = Colors.White;
            this.Light1Direction   = new Vector3D(-10, -10, -10);
            this.AmbientLightColor = Colors.Black;

            var b2 = new MeshBuilder(true, true, true);

            b2.AddSphere(new Vector3(0f, 0f, 0f), 4, 64, 64);
            this.Model      = b2.ToMeshGeometry3D();
            Model.IsDynamic = true;
            this.InnerModel = new MeshGeometry3D()
            {
                Indices            = Model.Indices,
                Positions          = Model.Positions,
                Normals            = Model.Normals,
                TextureCoordinates = Model.TextureCoordinates,
                Tangents           = Model.Tangents,
                BiTangents         = Model.BiTangents,
                IsDynamic          = true
            };

            var image = TextureModel.Create(new System.Uri(@"test.png", System.UriKind.RelativeOrAbsolute).ToString());

            this.ModelMaterial = new PhongMaterial
            {
                AmbientColor      = Colors.Gray.ToColor4(),
                DiffuseColor      = Colors.White.ToColor4(),
                SpecularColor     = Colors.White.ToColor4(),
                SpecularShininess = 100f,
                DiffuseAlphaMap   = image,
                DiffuseMap        = TextureModel.Create(new System.Uri(@"TextureCheckerboard2.dds", System.UriKind.RelativeOrAbsolute).ToString()),
                NormalMap         = TextureModel.Create(new System.Uri(@"TextureCheckerboard2_dot3.dds", System.UriKind.RelativeOrAbsolute).ToString()),
            };

            this.InnerModelMaterial = new PhongMaterial
            {
                AmbientColor      = Colors.Gray.ToColor4(),
                DiffuseColor      = new Color4(0.75f, 0.75f, 0.75f, 1.0f),
                SpecularColor     = Colors.White.ToColor4(),
                SpecularShininess = 100f,
                DiffuseAlphaMap   = image,
                DiffuseMap        = TextureModel.Create(new System.Uri(@"TextureNoise1.jpg", System.UriKind.RelativeOrAbsolute).ToString()),
                NormalMap         = ModelMaterial.NormalMap
            };


            initialPosition = Model.Positions;
            initialIndicies = Model.Indices;
            #region Point Model
            PointModel = new PointGeometry3D()
            {
                IsDynamic = true, Positions = Model.Positions
            };
            int count  = PointModel.Positions.Count;
            var colors = new Color4Collection(count);
            for (int i = 0; i < count / 2; ++i)
            {
                colors.Add(new Color4(0, 1, 1, 1));
            }
            for (int i = 0; i < count / 2; ++i)
            {
                colors.Add(new Color4(0, 0, 0, 0));
            }
            PointModel.Colors = colors;
            #endregion

            #region Line Model
            LineModel = new LineGeometry3D()
            {
                IsDynamic = true, Positions = new Vector3Collection(PointModel.Positions)
            };
            LineModel.Positions.Add(Vector3.Zero);
            var indices = new IntCollection(count * 2);
            for (int i = 0; i < count; ++i)
            {
                indices.Add(count);
                indices.Add(i);
            }
            LineModel.Indices = indices;
            colors            = new Color4Collection(LineModel.Positions.Count);
            for (int i = 0; i < count; ++i)
            {
                colors.Add(new Color4((float)i / count, 1 - (float)i / count, 0, 1));
            }
            colors.Add(Colors.Blue.ToColor4());
            LineModel.Colors = colors;
            LineMaterial     = new LineArrowHeadMaterial()
            {
                Color = Colors.White, Thickness = 0.5, ArrowSize = 0.02
            };
            #endregion
            var token = cts.Token;
            Task.Run(() =>
            {
                while (!token.IsCancellationRequested)
                {
                    Timer_Tick();
                    Task.Delay(16).Wait();
                }
            }, token);
            //timer.Interval = TimeSpan.FromMilliseconds(16);
            //timer.Tick += Timer_Tick;
            //timer.Start();
        }