예제 #1
0
        public override async Task <Entity> CreateEntity(EntityHierarchyItemViewModel parent)
        {
            var model = await PickupAsset(parent.Editor.Session, new[] { typeof(IModelAsset) });

            if (model is null)
            {
                return(null);
            }

            var name      = ComputeNewName(parent, model.Name);
            var component = new ModelComponent {
                Model = ContentReferenceHelper.CreateReference <Model>(model)
            };
            var instancingComponent = new InstancingComponent();

            return(await CreateEntityWithComponent(name, component, instancingComponent));
        }
        public override Task <Entity> CreateEntity(EntityHierarchyItemViewModel parent)
        {
            var name = ComputeNewName(parent, "Smoke particle system");

            var component = new ParticleSystemComponent();
            var emitter   = new ParticleEmitter {
                ParticleLifetime = new Vector2(1, 2)
            };


            // 20 Particle per second
            var spawner = new SpawnerPerSecond {
                SpawnCount = 20
            };

            emitter.Spawners.Add(spawner);

            // Size
            var randSize = new InitialSizeSeed {
                RandomSize = new Vector2(0.35f, 0.55f)
            };

            emitter.Initializers.Add(randSize);

            // Position
            var randPos = new InitialPositionSeed
            {
                PositionMin = new Vector3(-0.2f, 0, -0.2f),
                PositionMax = new Vector3(0.2f, 0, 0.2f)
            };

            emitter.Initializers.Add(randPos);

            // Velocity
            var randVel = new InitialVelocitySeed
            {
                VelocityMin = new Vector3(-0.5f, 1f, -0.5f),
                VelocityMax = new Vector3(0.5f, 3, 0.5f)
            };

            emitter.Initializers.Add(randVel);

            component.ParticleSystem.Emitters.Add(emitter);

            return(CreateEntityWithComponent(name, component));
        }
예제 #3
0
        /// <inheritdoc />
        protected override bool CanAddOrInsert(EntityHierarchyItemViewModel parent, SceneViewModel asset, AddChildModifiers modifiers, int index, out string message, params object[] messageArgs)
        {
            var currentRoot = parent.Owner as SceneRootViewModel;

            // Note: scene are inserted after all entities
            if (currentRoot == null || index < currentRoot.EntityCount)
            {
                message = "Can only add a scene to another scene";
                return(false);
            }
            if (!currentRoot.SceneAsset.CanBeParentOf(asset, out message, true))
            {
                return(false);
            }
            message = "Add to this scene";
            return(true);
        }
예제 #4
0
        public override Task <Entity> CreateEntity(EntityHierarchyItemViewModel parent)
        {
            var slotId       = default(SceneCameraSlotId);
            var gameSettings = parent.Asset.ServiceProvider.Get <GameSettingsProviderService>().CurrentGameSettings;

            if (gameSettings != null)
            {
                var assetFinder = (IAssetFinder)parent.Asset.Session;
                var compositor  = assetFinder.FindAssetFromProxyObject(gameSettings.GraphicsCompositor)?.Asset as GraphicsCompositorAsset;
                slotId = compositor?.Cameras.FirstOrDefault()?.ToSlotId() ?? default(SceneCameraSlotId);
            }
            var name      = ComputeNewName(parent, "Camera");
            var component = new CameraComponent
            {
                Projection = CameraProjectionMode.Perspective,
                Slot       = slotId,
            };

            return(CreateEntityWithComponent(name, component));
        }
예제 #5
0
        public override async Task <Entity> CreateEntity(EntityHierarchyItemViewModel parent)
        {
            var skybox = await PickupAsset(parent.Editor.Session, new[] { typeof(SkyboxAsset) });

            if (skybox == null)
            {
                return(null);
            }
            var skyboxAsset = (SkyboxAsset)skybox.Asset;

            var name           = ComputeNewName(parent, "Skybox light");
            var lightComponent = new LightComponent {
                Type = new LightSkybox {
                    Skybox = ContentReferenceHelper.CreateReference <Skybox>(skybox)
                }
            };
            var skyboxComponent = new BackgroundComponent {
                Texture = skyboxAsset.CubeMap
            };

            return(await CreateEntityWithComponent(name, lightComponent, skyboxComponent));
        }
예제 #6
0
        /// <inheritdoc />
        protected override void ApplyPolicy(EntityHierarchyItemViewModel parent, IReadOnlyCollection <SceneViewModel> assets, int index, Vector3 position)
        {
            var currentRoot  = parent.Owner as SceneRootViewModel;
            var currentScene = currentRoot?.Asset as SceneViewModel;

            if (currentScene == null)
            {
                return;
            }

            // Note: scene are inserted after all entities
            index -= currentRoot.EntityCount;
            // Get common "root" scenes (in case we are trying to drop two scenes that are already part of the same hierarchy.
            var commonRoots = GetCommonRoots(assets);

            // Move the scenes in two steps: first remove all, then insert all
            foreach (var scene in commonRoots)
            {
                // Some of the scenes we're moving might already be children of the current scene, let's count for their removal in the insertion index.
                var rootIndex = currentScene.Children.IndexOf(scene);
                if (rootIndex >= 0 && rootIndex < index)
                {
                    --index;
                }

                scene.Parent?.Children.Remove(scene);
            }
            foreach (var scene in commonRoots)
            {
                currentScene.Children.Insert(index, scene);
                currentRoot.ChildScenes[index].Offset = position;
                // Make sure the scene is loaded
                currentRoot.ChildScenes[index].RequestLoading(true).Forget();
                ++index;
            }
        }
        public override Task <Entity> CreateEntity(EntityHierarchyItemViewModel parent)
        {
            var name = ComputeNewName(parent, "Ribbon particle system");

            var component = new ParticleSystemComponent();
            var emitter   = new ParticleEmitter {
                ParticleLifetime = new Vector2(2, 2)
            };


            // 30 Particles per second
            var spawner = new SpawnerPerSecond {
                SpawnCount = 30
            };

            emitter.Spawners.Add(spawner);

            // Ribbon
            var ribbonShape = new ShapeBuilderRibbon
            {
                SmoothingPolicy         = SmoothingPolicy.Best,
                Segments                = 15,
                TextureCoordinatePolicy = TextureCoordinatePolicy.Stretched,
                TexCoordsFactor         = 1f
            };

            emitter.ShapeBuilder = ribbonShape;

            // Velocity
            var randVel = new InitialVelocitySeed
            {
                VelocityMin = new Vector3(-0.15f, 3f, -0.15f),
                VelocityMax = new Vector3(0.15f, 3, 0.15f)
            };

            emitter.Initializers.Add(randVel);

            // Spawn Order
            var initialOrder = new InitialSpawnOrder();

            emitter.Initializers.Add(initialOrder);

            // Size by Lifetime
            var sizeCurve = new ComputeAnimationCurveFloat();
            var key0      = new AnimationKeyFrame <float>
            {
                Key   = 0,
                Value = 0.1f
            };
            var key1 = new AnimationKeyFrame <float>
            {
                Key   = 0.9f,
                Value = 0f
            };

            sizeCurve.KeyFrames.Add(key0);
            sizeCurve.KeyFrames.Add(key1);

            var sizeAnimation = new UpdaterSizeOverTime {
                SamplerMain = { Curve = sizeCurve }
            };

            emitter.Updaters.Add(sizeAnimation);

            emitter.SortingPolicy = EmitterSortingPolicy.ByOrder;

            component.ParticleSystem.Emitters.Add(emitter);

            return(CreateEntityWithComponent(name, component));
        }
예제 #8
0
 public abstract Task <Entity> CreateEntity(EntityHierarchyItemViewModel parent);
예제 #9
0
 public static string ComputeNewName([NotNull] EntityHierarchyItemViewModel parent, [NotNull] string baseName)
 {
     // We do not generate unique names for entities anymore, it is not useful at all.
     //return NamingHelper.ComputeNewName(baseName, parent.Children.OfType<EntityViewModel>(), x => x.Name);
     return(baseName);
 }