示例#1
0
        public void Prepare(bool generateDefaultLight = true, bool generateDefaultCamera = true)
        {
            meshes = MeshesList.ToArray();
            sounds = SoundsList.ToArray();

            materials        = MaterialsList.ToArray();
            multiMaterials   = MultiMaterialsList.ToArray();
            shadowGenerators = ShadowGeneratorsList.ToArray();
            skeletons        = SkeletonsList.ToArray();
            if (MorphTargetManagersList.Count > 0)
            {
                morphTargetManagers = MorphTargetManagersList.ToArray();
            }

            if (CamerasList.Count == 0 && generateDefaultCamera)
            {
                var camera = new BabylonCamera {
                    name = "Default camera", id = Guid.NewGuid().ToString()
                };

                // Default camera init gives infinit values
                // Indeed, float.MaxValue - float.MinValue always leads to infinity
                var distanceVector = MaxVector - MinVector;
                var midPoint       = MinVector + distanceVector / 2;
                camera.target   = midPoint.ToArray();
                camera.position = (midPoint + distanceVector).ToArray();

                var distance = distanceVector.Length();
                camera.speed = distance / 50.0f;
                camera.maxZ  = distance * 4f;

                camera.minZ = distance < 100.0f ? 0.1f : 1.0f;

                CamerasList.Add(camera);
            }

            if (LightsList.Count == 0 && generateDefaultLight)
            {
                var light = new BabylonLight
                {
                    name        = "Default light",
                    id          = Guid.NewGuid().ToString(),
                    type        = 3,
                    groundColor = new float[] { 0, 0, 0 },
                    direction   = new[] { 0, 1.0f, 0 },
                    intensity   = 1
                };

                LightsList.Add(light);
            }

            cameras = (CamerasList.Count > 0) ? CamerasList.ToArray() : null;
            lights  = (LightsList.Count > 0) ? LightsList.ToArray() : null;

            if (activeCameraID == null && CamerasList.Count > 0)
            {
                activeCameraID = CamerasList[0].id;
            }
        }
示例#2
0
        private void FileOpen(string[] Files, bool MergeMode)
        {
            if (!MergeMode)
            {
                Renderer.DeleteAll();

                Renderer.Lights.Add(new Light()
                {
                    Ambient         = new Color4(0.1f, 0.1f, 0.1f, 1.0f),
                    Diffuse         = new Color4(0.9f, 0.9f, 0.9f, 1.0f),
                    Specular0       = new Color4(0.8f, 0.8f, 0.8f, 1.0f),
                    Specular1       = new Color4(0.4f, 0.4f, 0.4f, 1.0f),
                    TwoSidedDiffuse = true,
                    Enabled         = true
                });

                ResetTransforms();

                Scene = FileIO.Merge(Files, Renderer);

                if (Scene != null)
                {
                    TextureManager.Textures = Scene.Textures;
                    ModelsList.Bind(Scene.Models);
                    TexturesList.Bind(Scene.Textures);
                    CamerasList.Bind(Scene.Cameras);
                    LightsList.Bind(Scene.Lights);
                    SklAnimsList.Bind(Scene.SkeletalAnimations);
                    MatAnimsList.Bind(Scene.MaterialAnimations);
                    VisAnimsList.Bind(Scene.VisibilityAnimations);
                    CamAnimsList.Bind(Scene.CameraAnimations);
                    LUTsList.Bind(Scene.LUTs);

                    Animator.Enabled     = false;
                    LblAnimSpeed.Text    = string.Empty;
                    LblAnimLoopMode.Text = string.Empty;
                    AnimSeekBar.Value    = 0;
                    AnimSeekBar.Maximum  = 0;
                    AnimGrp.Frame        = 0;
                    AnimGrp.FramesCount  = 0;

                    if (Scene.Models.Count > 0)
                    {
                        ModelsList.Select(0);
                    }
                    else
                    {
                        UpdateTransforms();
                    }
                }
            }
            else
            {
                Scene = FileIO.Merge(Files, Renderer, Scene);
            }
        }
示例#3
0
        public void Prepare()
        {
            scenes[0].Prepare();

            // Do not export empty arrays
            if (NodesList.Count > 0)
            {
                nodes = NodesList.ToArray();
                NodesList.ForEach(node => node.Prepare());
            }
            if (CamerasList.Count > 0)
            {
                cameras = CamerasList.ToArray();
            }
            if (BuffersList.Count > 0)
            {
                buffers = BuffersList.ToArray();
            }
            if (BufferViewsList.Count > 0)
            {
                bufferViews = BufferViewsList.ToArray();
            }
            if (AccessorsList.Count > 0)
            {
                accessors = AccessorsList.ToArray();
            }
            if (MeshesList.Count > 0)
            {
                meshes = MeshesList.ToArray();
            }
            if (MaterialsList.Count > 0)
            {
                materials = MaterialsList.ToArray();
            }
            if (TexturesList.Count > 0)
            {
                textures = TexturesList.ToArray();
            }
            if (ImagesList.Count > 0)
            {
                images = ImagesList.ToArray();
            }
            if (SamplersList.Count > 0)
            {
                samplers = SamplersList.ToArray();
            }
            if (AnimationsList.Count > 0)
            {
                animations = AnimationsList.ToArray();
                AnimationsList.ForEach(animation => animation.Prepare());
            }
            if (SkinsList.Count > 0)
            {
                skins = SkinsList.ToArray();
            }
        }
示例#4
0
 private void AddNearCameras(List <AssetsDetailsViewDTO> Cameras)
 {
     Application.Current.Dispatcher.Invoke(() =>
     {
         foreach (var camera in Cameras)
         {
             CamerasList.Add(camera);
         }
     });
 }
示例#5
0
        private void FileOpen(string[] Files, bool MergeMode)
        {
            if (!MergeMode)                     //if not merging in a model
            {
                Renderer.DeleteAll();           //clear existing meshes

                Renderer.Lights.Add(new Light() //add a new light to the {scene/renderer}
                {
                    Ambient         = new Color4(0.1f, 0.1f, 0.1f, 1.0f),
                    Diffuse         = new Color4(0.9f, 0.9f, 0.9f, 1.0f),
                    Specular0       = new Color4(0.8f, 0.8f, 0.8f, 1.0f),
                    Specular1       = new Color4(0.4f, 0.4f, 0.4f, 1.0f),
                    TwoSidedDiffuse = true,
                    Enabled         = true
                });

                ResetTransforms();

                Scene = FileIO.Merge(Files, Renderer);

                TextureManager.Textures = Scene.Textures;

                ModelsList.Bind(Scene.Models);
                TexturesList.Bind(Scene.Textures);
                CamerasList.Bind(Scene.Cameras);
                LightsList.Bind(Scene.Lights);
                SklAnimsList.Bind(Scene.SkeletalAnimations);
                MatAnimsList.Bind(Scene.MaterialAnimations);
                VisAnimsList.Bind(Scene.VisibilityAnimations);
                CamAnimsList.Bind(Scene.CameraAnimations);

                Animator.Enabled     = false;
                LblAnimSpeed.Text    = string.Empty;
                LblAnimLoopMode.Text = string.Empty;
                AnimSeekBar.Value    = 0;
                AnimSeekBar.Maximum  = 0;
                AnimGrp.Frame        = 0;
                AnimGrp.FramesCount  = 0;

                if (Scene.Models.Count > 0)
                {
                    //TODO: if not moving camera on model select, move camera to default pos here
                    ModelsList.Select(0);
                }
                else
                {
                    UpdateTransforms();
                }
            }
            else
            {
                Scene = FileIO.Merge(Files, Renderer, Scene);
            }
        }
示例#6
0
        public void Prepare(bool generateDefaultLight = true)
        {
            meshes = MeshesList.ToArray();

            materials        = MaterialsList.ToArray();
            multiMaterials   = MultiMaterialsList.ToArray();
            shadowGenerators = ShadowGeneratorsList.ToArray();
            skeletons        = SkeletonsList.ToArray();

            if (CamerasList.Count == 0)
            {
                var camera = new BabylonCamera {
                    name = "Default camera", id = Guid.NewGuid().ToString()
                };

                var distanceVector = MaxVector - MinVector;
                var midPoint       = MinVector + distanceVector / 2;
                camera.target   = midPoint.ToArray();
                camera.position = (midPoint + distanceVector).ToArray();

                var distance = distanceVector.Length();
                camera.speed = distance / 50.0f;
                camera.maxZ  = distance * 4f;

                camera.minZ = distance < 100.0f ? 0.1f : 1.0f;

                CamerasList.Add(camera);
            }

            if (LightsList.Count == 0 && generateDefaultLight)
            {
                var light = new BabylonLight {
                    name = "Default light", id = Guid.NewGuid().ToString()
                };

                var midPoint = MinVector + (MaxVector - MinVector) / 2;
                light.type     = 0;
                light.position = (midPoint + (MaxVector - MinVector)).ToArray();

                light.diffuse  = new Vector3(1, 1, 1).ToArray();
                light.specular = new Vector3(1, 1, 1).ToArray();

                LightsList.Add(light);
            }

            cameras = CamerasList.ToArray();
            lights  = LightsList.ToArray();

            if (activeCameraID == null)
            {
                activeCameraID = CamerasList[0].id;
            }
        }
        private void AddNearCameras(List <AssetsViewDTO> Cameras)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                foreach (var camera in Cameras)
                {
                    if (camera.ItemCategoryId != null && camera.ItemStatusId != null)
                    {
                        camera.ItemImage = SOPHelper.GetAssetImageUrl((AssetTypesEnum)camera.ItemCategoryId, (AssetStatusEnum)camera.ItemStatusId);
                    }

                    camera.ImgCheckedSource = "../images/false.png";

                    CamerasList.Add(camera);
                }
            });
        }
示例#8
0
        public void Prepare()
        {
            scenes[0].Prepare();

            // Do not export empty arrays
            if (NodesList.Count > 0)
            {
                nodes = NodesList.ToArray();
                NodesList.ForEach(node => node.Prepare());
            }
            if (CamerasList.Count > 0)
            {
                cameras = CamerasList.ToArray();
            }
            if (BuffersList.Count > 0)
            {
                buffers = BuffersList.ToArray();
            }
            if (BufferViewsList.Count > 0)
            {
                bufferViews = BufferViewsList.ToArray();
            }
            if (AccessorsList.Count > 0)
            {
                accessors = AccessorsList.ToArray();
            }
            if (MeshesList.Count > 0)
            {
                meshes = MeshesList.ToArray();
            }
            if (MaterialsList.Count > 0)
            {
                materials = MaterialsList.ToArray();
            }
            if (TexturesList.Count > 0)
            {
                textures = TexturesList.ToArray();
            }
            if (ImagesList.Count > 0)
            {
                images = ImagesList.ToArray();
            }
            if (SamplersList.Count > 0)
            {
                samplers = SamplersList.ToArray();
            }
            if (AnimationsList.Count > 0)
            {
                var animationsList = new List <GLTFAnimation>();
                AnimationsList.ForEach(animation =>
                {
                    animation.Prepare();
                    // Exclude empty animations
                    if (animation.channels != null)
                    {
                        animationsList.Add(animation);
                    }
                });
                if (animationsList.Count > 0)
                {
                    animations = animationsList.ToArray();
                }
            }
            if (SkinsList.Count > 0)
            {
                skins = SkinsList.ToArray();
            }
            if (extensionsUsed != null && extensionsUsed.Count == 0)
            {
                extensionsUsed = null;
            }
            if (extensionsRequired != null && extensionsRequired.Count == 0)
            {
                extensionsRequired = null;
            }
        }