Exemplo n.º 1
0
        /// <summary>
        /// Resolve the dependencies
        /// </summary>
        protected override void ResolveDependencies()
        {
            base.ResolveDependencies();

            MaterialComponent materialComponent = this.Owner.FindComponent <MaterialComponent>();

            if (materialComponent == null)
            {
                MaterialsMap materialsMap = this.Owner.FindComponent <MaterialsMap>();
                if (materialsMap != null)
                {
                    materialsMap.OnComponentInitialized += (s, o) =>
                    {
                        this.material = materialsMap.DefaultMaterial;
                    };
                }
            }
            else
            {
                materialComponent.OnComponentInitialized += (s, o) =>
                {
                    this.material = materialComponent.Material;
                };
            }

            // If the entity is initialized, we need to update the current particle system
            if (this.isInitialized)
            {
                this.LoadParticleSystem();
            }
        }
Exemplo n.º 2
0
        public void ApplyMaterial()
        {
            Owner.RemoveComponent <MaterialsMap>();

            string content = "Content/SmokeParticle.wpk";

            if (currentParticleSystemIndex == 2 ||
                currentParticleSystemIndex == 3)
            {
                content = "Content/WhitePixel.wpk";
            }
            var materials = new MaterialsMap(new BasicMaterial(content, DefaultLayers.Additive)
            {
                VertexColorEnabled = true
            });

            Owner.AddComponent(materials);
        }
Exemplo n.º 3
0
        private void CreateTrajectory(Entity host)
        {
            this.trajectoryDrawable = new Trajectory2DDrawable()
            {
                IsVisible            = false,
                NumberOfPoints       = 70,
                CurveWith            = 6.0f,
                VisibilityPercentage = 1,
            };


            var matsMap = new MaterialsMap()
            {
                DefaultMaterialPath = WaveContent.Materials.TrajectoryMaterial
            };

            matsMap.MaterialsPath.Add("elastic", WaveContent.Materials.ElasticMaterial);
            host.AddComponent(matsMap);

            host.AddComponent(this.trajectoryDrawable);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Refresh the barrel distortion mesh scene
        /// </summary>
        private void RefreshBarrelDistortionScene()
        {
            this.RefreshEyeTextures();

            if (this.isBarrelDistortionEnabled && this.cachedVRMode != VRMode.AttachedMode)
            {
                if (this.barrelDistortionEntity == null)
                {
                    if (this.distortionMesh == null)
                    {
                        var assembly = ReflectionHelper.GetTypeAssembly(typeof(CardboardVRProvider));

                        using (var stream = ResourceLoader.GetEmbeddedResourceStream(assembly, "WaveEngine.Cardboard.BarrelDistortionMesh.wpk"))
                        {
                            this.distortionMesh = this.Assets.LoadAsset <InternalStaticModel>(BarrelDistortionModel, stream);
                        }
                    }

                    if (this.RenderManager.FindLayer(typeof(VRLensLayer)) == null)
                    {
                        this.RenderManager.RegisterLayer(new VRLensLayer(this.RenderManager));
                    }

                    Dictionary <string, Material> materials = new Dictionary <string, Material>();
                    materials.Add("vrMeshLeft", new StandardMaterial()
                    {
                        LightingEnabled = false, Diffuse = this.eyeTextures[0].RenderTarget, LayerType = typeof(VRLensLayer), SamplerMode = AddressMode.LinearClamp
                    });
                    materials.Add("vrMeshRight", new StandardMaterial()
                    {
                        LightingEnabled = false, Diffuse = this.eyeTextures[1].RenderTarget, LayerType = typeof(VRLensLayer), SamplerMode = AddressMode.LinearClamp
                    });

                    MaterialsMap materialsMap = new MaterialsMap(materials);

                    this.barrelDistortionEntity = new Entity("_VRCardboardDistortMesh");

                    Entity distortMeshEntity = new Entity("VRMesh")
                                               .AddComponent(new Transform3D())
                                               .AddComponent(new Model(BarrelDistortionModel))
                                               .AddComponent(materialsMap)
                                               .AddComponent(new ModelRenderer());

                    var vrCamera = new FixedCamera3D("VRDistortCamera", new Vector3(0, 1, 0), Vector3.Zero);
                    var camera   = vrCamera.Entity.FindComponent <Camera3D>();
                    camera.UpVector = -Vector3.UnitZ;
                    camera.SetCustomProjection(Matrix.CreateOrthographic(1, 1, 0.1f, 100));
                    camera.LayerMaskDefaultValue = false;
                    camera.LayerMask.Add(typeof(VRLensLayer), true);

                    this.barrelDistortionEntity.AddChild(distortMeshEntity);
                    this.barrelDistortionEntity.AddChild(vrCamera.Entity);

                    this.EntityManager.Add(this.barrelDistortionEntity);
                }
            }
            else
            {
                if (this.barrelDistortionEntity != null)
                {
                    this.EntityManager.Remove(this.barrelDistortionEntity);
                    this.barrelDistortionEntity = null;
                    var lensLayer = this.RenderManager.FindLayer(typeof(VRLensLayer));
                    if (lensLayer != null)
                    {
                        this.RenderManager.RemoveLayer(lensLayer);
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates the Block.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="color">The color.</param>
        /// <param name="scale">The scale.</param>
        /// <param name="entityType">Type of the entity.</param>
        /// <returns></returns>
        public Entity CreateBlock(Vector3 position, Color color, Vector3 scale, BlockTypeEnum entityType)
        {
            Entity entity = null;

            // Check if there are any block free in the pool of the type we need
            if (this.blockPool[entityType].Count > 0)
            {
                // pop from pool
                entity = this.blockPool[entityType].Pop();

                // Reset visibility and active property
                entity.IsVisible = true;
                entity.IsActive  = true;

                // reset position
                Transform3D transform = entity.FindComponent <Transform3D>();
                transform.Position = position;
                transform.Scale    = scale;

                // IMPORTANT: DO NOT REMOVE!! We need to Refresh boundbox of the model to locate it at right position.
                entity.FindComponent <Model>(false).BoundingBoxRefreshed = true;

                // change color map if needed
                MaterialsMap  materialMap   = entity.FindComponent <MaterialsMap>();
                BasicMaterial basicMaterial = (BasicMaterial)materialMap.DefaultMaterial;
                basicMaterial.DiffuseColor = color;
            }
            else
            {
                // If there are not entities in the pool of the type we need, then we should create one
                Model entityModel = null;

                // It will be better to use FBX models than primitives to optimize (primitives do not share vertexmodel)
                // but we use primitives here
                switch (entityType)
                {
                case BlockTypeEnum.GROUND:
                case BlockTypeEnum.BOX:
                case BlockTypeEnum.SPEEDERBLOCK:
                    entityModel = Model.CreateCube();
                    break;

                case BlockTypeEnum.PYRAMID:
                    entityModel = Model.CreateCone();
                    break;

                default:
                case BlockTypeEnum.EMPTY:
                    // SHOULD NOT HAPPEND, this method NEVER will be called if BlockType is EMPTY... but in case we forgotten this then it's controlled
                    break;
                }

                // Creates the new entity
                if (entityModel != null)
                {
                    entity = new Entity()
                             .AddComponent(new Transform3D()
                    {
                        Position = position, Scale = scale
                    })
                             .AddComponent(new MaterialsMap(new BasicMaterial(color)
                    {
                        LightingEnabled = true, AmbientLightColor = Color.White * 0.25f
                    }))
                             .AddComponent(entityModel)
                             .AddComponent(new BoxCollider())
                             .AddComponent(new ModelRenderer());
                    entity.Tag = entityType.ToString();

                    // DO NOT push in pool here!!, only add to cache on remove!
                    // this.blockPool[entityType].Push(entity);
                }
            }
            return(entity);
        }