Esempio n. 1
0
        private async Task<Model3DGroup> LoadAsync(string model3DPath, bool freeze)
        {
            return await Task.Factory.StartNew(() =>
            {
                var mi = new ModelImporter();
                
                if (freeze)
                {
                    // Alt 1. - freeze the model 
                    return mi.Load(model3DPath, null, true);
                }

                // Alt. 2 - create the model on the UI dispatcher
                return mi.Load(model3DPath, this.dispatcher);
            });
        }
        public void LoadModel(string path, bool transformYup, double scale)
        {
            var importer = new ModelImporter();
            var mod = importer.Load(path);

            if (mod == null || mod.Children.Count == 0)
                return;

            var model = (mod.Children[0] as GeometryModel3D);
            if (model == null)
                return;

            var mesh = model.Geometry as MeshGeometry3D;
            if (mesh == null)
                return;

            var transform = new Transform3DGroup();
            if (transformYup)
                transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90)));
            transform.Children.Add(new ScaleTransform3D(scale, scale, scale));

            for (int i = 0; i < mesh.Positions.Count; i++)
                mesh.Positions[i] = transform.Transform(mesh.Positions[i]);

            ScaleHeightOnly = false;
            Geometry = mesh;
        }
 /// <summary>
 /// Called when the source or default material changed.
 /// </summary>
 protected virtual void SourceChanged()
 {
     var importer = new ModelImporter { DefaultMaterial = this.DefaultMaterial };
     this.Visual3DModel = this.Source != null ? importer.Load(this.Source) : null;
     this.OnModelLoaded();
 }