Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the radar behavior
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            this.screenplay = this.EntityManager.Find("ScreenplayManager").FindComponent <ScreenplayManager>();

            foreach (var fighter in this.screenplay.FighterList)
            {
                if (fighter.State == FighterState.Player)
                {
                    continue;
                }

                Transform3D   radarTickTransform;
                BasicMaterial radarTickMaterial;
                Entity        radarTick = new Entity()
                                          .AddComponent(radarTickTransform = new Transform3D())
                                          .AddComponent(new Model("Content/Models/Hud/HudRadarTick.FBX"))
                                          .AddComponent(new ModelRenderer())
                                          .AddComponent(new MaterialsMap(radarTickMaterial = new BasicMaterial("Content/Textures/Hud/RadarTick.png", typeof(CockpitAdditiveLayer))
                {
                    DiffuseColor = colors[(int)fighter.State]
                }))
                ;

                radarTick.Enabled = false;

                this.Owner.AddChild(radarTick);
                this.radarTicks.Add(radarTickTransform);
                this.radarTickMaterials.Add(radarTickMaterial);
            }
        }
Ejemplo n.º 2
0
        public IEnumerator VolumeWhenVideoCreatedWithUserInScene()
        {
            // We disable SceneController monobehaviour to avoid its current scene id update
            sceneController.enabled = false;

            // Set current scene with this scene's id
            CommonScriptableObjects.sceneID.Set(scene.sceneData.id);

            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");

            yield return(videoTexture.routine);

            DecentralandEntity ent1    = TestHelpers.CreateSceneEntity(scene);
            BasicMaterial      ent1Mat = TestHelpers.SharedComponentCreate <BasicMaterial, BasicMaterial.Model>(scene, CLASS_ID.BASIC_MATERIAL, new BasicMaterial.Model()
            {
                texture = videoTexture.id
            });

            TestHelpers.SharedComponentAttach(ent1Mat, ent1);
            yield return(ent1Mat.routine);

            BoxShape ent1Shape = TestHelpers.SharedComponentCreate <BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, new BoxShape.Model());

            yield return(ent1Shape.routine);

            TestHelpers.SharedComponentAttach(ent1Shape, ent1);
            yield return(new WaitForAllMessagesProcessed());

            // Check the volume
            Assert.AreEqual(videoTexture.GetVolume(), videoTexture.texturePlayer.volume);
        }
Ejemplo n.º 3
0
        public CommandSet <VisualizerControl.Visualizer> Initialization()
        {
            int counter = 0;
            var set     = new VisualizerCommandSet();

            foreach (var projectile in projectiles)
            {
                // Start it off in the right place
                var obj = new ObjectPrototype(projectile.Shape, new BasicMaterial(projectile.Color, .05, .3),
                                              projectile.Position, new Vector3D(projectile.Size, projectile.Size, projectile.Size));

                set.AddCommand(new AddObject(obj, counter++));
            }

            foreach (var tetrahedron in gravStruct.GetTetrahedra())
            {
                var newShape = new Tetrahedron3D(ConvertToVector3D(tetrahedron.Points[0]),
                                                 ConvertToVector3D(tetrahedron.Points[1]), ConvertToVector3D(tetrahedron.Points[2]),
                                                 ConvertToVector3D(tetrahedron.Points[3]));
                var newMaterial = new BasicMaterial(ConvertColor(tetrahedron.Color), tetrahedron.Fresnel, tetrahedron.Roughness);
                var newobj      = new ObjectPrototype(newShape, newMaterial);

                set.AddCommand(new AddObject(newobj, counter++));
            }

            return(set);
        }
Ejemplo n.º 4
0
        public IEnumerator VideoTextureIsAttachedAndDetachedCorrectly()
        {
            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");

            yield return(videoTexture.routine);

            Assert.IsTrue(videoTexture.attachedMaterials.Count == 0, "DCLVideoTexture started with attachedMaterials != 0");

            BasicMaterial mat2 = TestHelpers.SharedComponentCreate <BasicMaterial, BasicMaterial.Model>
                                     (scene, CLASS_ID.BASIC_MATERIAL,
                                     new BasicMaterial.Model
            {
                texture = videoTexture.id
            });

            yield return(mat2.routine);

            Assert.IsTrue(videoTexture.attachedMaterials.Count == 1, $"did DCLVideoTexture attach to material? {videoTexture.attachedMaterials.Count} expected 1");

            // TEST: DCLVideoTexture detach on material disposed
            mat2.Dispose();
            Assert.IsTrue(videoTexture.attachedMaterials.Count == 0, $"did DCLVideoTexture detach from material? {videoTexture.attachedMaterials.Count} expected 0");

            videoTexture.Dispose();

            yield return(null);

            Assert.IsTrue(videoTexture.texture == null, "DCLVideoTexture didn't dispose correctly?");
        }
Ejemplo n.º 5
0
    public IEnumerator NotDestroySharedTextureWhenDisposed()
    {
        DCLTexture texture =
            TestHelpers.CreateDCLTexture(scene, Utils.GetTestsAssetsPath() + "/Images/atlas.png");

        yield return(texture.routine);

        BasicMaterial mat = TestHelpers.CreateEntityWithBasicMaterial(scene,
                                                                      new BasicMaterial.Model
        {
            texture   = texture.id,
            alphaTest = 1,
        },
                                                                      out DecentralandEntity entity1);

        yield return(mat.routine);

        BasicMaterial mat2 = TestHelpers.CreateEntityWithBasicMaterial(scene,
                                                                       new BasicMaterial.Model
        {
            texture   = texture.id,
            alphaTest = 1,
        },
                                                                       out DecentralandEntity entity2);

        yield return(mat2.routine);

        TestHelpers.SharedComponentDispose(mat);
        Assert.IsTrue(texture.texture != null, "Texture should persist because is used by the other material!!");
    }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes the radar behavior
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            this.screenplay = this.EntityManager.Find("ScreenplayManager").FindComponent<ScreenplayManager>();

            foreach (var fighter in this.screenplay.FighterList)
            {
                if (fighter.State == FighterState.Player)
                {
                    continue;
                }

                Transform3D radarTickTransform;
                BasicMaterial radarTickMaterial;
                Entity radarTick = new Entity()
                .AddComponent(radarTickTransform = new Transform3D())
                .AddComponent(new Model("Content/Models/Hud/HudRadarTick.FBX"))
                .AddComponent(new ModelRenderer())
                .AddComponent(new MaterialsMap(radarTickMaterial = new BasicMaterial("Content/Textures/Hud/RadarTick.png", typeof(CockpitAdditiveLayer))
                    {
                        DiffuseColor = colors[(int)fighter.State]
                    }))
                ;

                radarTick.Enabled = false;

                this.Owner.AddChild(radarTick);
                this.radarTicks.Add(radarTickTransform);
                this.radarTickMaterials.Add(radarTickMaterial);
            }
        }
Ejemplo n.º 7
0
        public IEnumerator VideoTextureVisibleStateIsSetCorrectlyWhenEntityIsRemoved()
        {
            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");

            yield return(videoTexture.routine);

            DecentralandEntity ent1    = TestHelpers.CreateSceneEntity(scene);
            BasicMaterial      ent1Mat = TestHelpers.SharedComponentCreate <BasicMaterial, BasicMaterial.Model>(scene, CLASS_ID.BASIC_MATERIAL, new BasicMaterial.Model()
            {
                texture = videoTexture.id
            });

            TestHelpers.SharedComponentAttach(ent1Mat, ent1);
            yield return(ent1Mat.routine);

            BoxShape ent1Shape = TestHelpers.SharedComponentCreate <BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, new BoxShape.Model());

            yield return(ent1Shape.routine);

            TestHelpers.SharedComponentAttach(ent1Shape, ent1);
            yield return(new WaitForAllMessagesProcessed());

            Assert.IsTrue(videoTexture.isVisible, "DCLVideoTexture should be visible");

            scene.RemoveEntity(ent1.entityId, true);
            yield return(new WaitForAllMessagesProcessed());

            Assert.IsTrue(!videoTexture.isVisible, "DCLVideoTexture should not be visible ");
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Update model effect
        /// </summary>
        /// <param name="meshEffect">An effect</param>
        protected virtual void UpdateModelEffects(Effect meshEffect)
        {
            if (meshEffect is BasicEffect)
            {
                var effect = meshEffect as BasicEffect;

                if (_material == null)
                {
                    effect.LightingEnabled = true;

                    // Mesh color light
                    effect.AmbientLightColor = Color.White.ToVector3();
                    effect.DiffuseColor      = Color.White.ToVector3();
                    effect.EmissiveColor     = Color.White.ToVector3() * 0.5f;
                    effect.SpecularColor     = Color.Black.ToVector3();
                    effect.Alpha             = 1;
                }
                else
                {
                    BasicMaterial material = (BasicMaterial)_material;

                    if (material != null)
                    {
                        UpdateEffect(effect, material);
                    }
                }
            }
        }
Ejemplo n.º 9
0
    public IEnumerator DefaultMissingValuesPropertyOnUpdate()
    {
        // 1. Create component with non-default configs
        BasicMaterial basicMaterialComponent =
            TestHelpers.SharedComponentCreate <BasicMaterial, BasicMaterial.Model>(scene, CLASS_ID.BASIC_MATERIAL,
                                                                                   new BasicMaterial.Model
        {
            alphaTest = 1f
        });

        yield return(basicMaterialComponent.routine);

        // 2. Check configured values
        Assert.AreEqual(1f, basicMaterialComponent.model.alphaTest);

        // 3. Update component with missing values

        scene.SharedComponentUpdate(basicMaterialComponent.id, JsonUtility.ToJson(new BasicMaterial.Model {
        }));

        yield return(basicMaterialComponent.routine);

        // 4. Check defaulted values
        Assert.AreEqual(0.5f, basicMaterialComponent.model.alphaTest);
    }
Ejemplo n.º 10
0
        /// <summary>
        /// Update the current effect. This method will change.
        /// </summary>
        /// <param name="effect"></param>
        /// <param name="material"></param>
        private void UpdateEffect(BasicEffect effect, BasicMaterial material)
        {
            effect.Alpha             = material.AlphaColor;
            effect.AmbientLightColor = material.AmbientColor * material.AmbientIntensity;
            effect.DiffuseColor      = material.DiffuseColor * material.DiffuseIntensity;
            effect.EmissiveColor     = material.EmissiveColor * material.EmissiveIntensity;
            effect.FogColor          = material.FogColor;
            effect.FogEnabled        = material.EnableFog;
            effect.FogStart          = material.FogStart;
            effect.FogEnd            = material.FogEnd;
            effect.LightingEnabled   = true;

            if (material.EnableDefaultLighting)
            {
                effect.EnableDefaultLighting();
            }

            effect.PreferPerPixelLighting = material.EnabledPerPixelLighting;
            effect.SpecularColor          = material.SpecularColor * material.SpecularIntensity;
            effect.VertexColorEnabled     = material.EnableVertexColor;


            SceneLight light = (SceneLight)material.Light;

            if (light != null)
            {
                StockMaterial.UpdateLighting(effect, light);
                effect.AmbientLightColor *= light.AmbientColor * light.AmbientIntensity;
            }
        }
Ejemplo n.º 11
0
        public IEnumerator VideoTextureReplaceOtherTextureCorrectly()
        {
            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");

            yield return(videoTexture.routine);

            Assert.IsTrue(videoTexture.attachedMaterials.Count == 0, "DCLVideoTexture started with attachedMaterials != 0");

            DCLTexture dclTexture = TestHelpers.CreateDCLTexture(
                scene,
                Utils.GetTestsAssetsPath() + "/Images/atlas.png",
                DCLTexture.BabylonWrapMode.CLAMP,
                FilterMode.Bilinear);

            yield return(dclTexture.routine);

            BasicMaterial mat = TestHelpers.SharedComponentCreate <BasicMaterial, BasicMaterial.Model>
                                    (scene, CLASS_ID.BASIC_MATERIAL,
                                    new BasicMaterial.Model
            {
                texture = dclTexture.id
            });

            yield return(mat.routine);

            yield return(TestHelpers.SharedComponentUpdate <BasicMaterial, BasicMaterial.Model>(mat, new BasicMaterial.Model()
            {
                texture = videoTexture.id
            }));

            Assert.IsTrue(videoTexture.attachedMaterials.Count == 1, $"did DCLVideoTexture attach to material? {videoTexture.attachedMaterials.Count} expected 1");
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets material used by the model.
        /// </summary>
        /// <returns>An array of material used by the model.</returns>
        public BaseMaterial[] GetModelMaterial()
        {
            List <BaseMaterial> materials = new List <BaseMaterial>();
            BaseMaterial        material  = null;

            foreach (ModelMesh mesh in _model.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    material = new BasicMaterial();

                    var effect = part.Effect as BasicEffect;

                    if (effect != null)
                    {
                        material.Texture = effect.Texture;
                        material.Effect  = effect;
                    }

                    materials.Add(material);
                }
            }

            return(materials.ToArray());
        }
Ejemplo n.º 13
0
    public IEnumerator WorkCorrectlyWhenAttachedBeforeShape()
    {
        DecentralandEntity entity = TestHelpers.CreateSceneEntity(scene);

        DCLTexture dclTexture = TestHelpers.CreateDCLTexture(
            scene,
            Utils.GetTestsAssetsPath() + "/Images/atlas.png",
            DCLTexture.BabylonWrapMode.CLAMP,
            FilterMode.Bilinear);

        yield return(dclTexture.routine);

        BasicMaterial mat = TestHelpers.SharedComponentCreate <BasicMaterial, BasicMaterial.Model>
                                (scene, CLASS_ID.BASIC_MATERIAL,
                                new BasicMaterial.Model
        {
            texture   = dclTexture.id,
            alphaTest = 0.5f
        });

        yield return(mat.routine);

        TestHelpers.SharedComponentAttach(mat, entity);

        SphereShape shape = TestHelpers.SharedComponentCreate <SphereShape, SphereShape.Model>(scene,
                                                                                               CLASS_ID.SPHERE_SHAPE,
                                                                                               new SphereShape.Model {
        });

        TestHelpers.SharedComponentAttach(shape, entity);

        Assert.IsTrue(entity.meshRootGameObject != null);
        Assert.IsTrue(entity.meshRootGameObject.GetComponent <MeshRenderer>() != null);
        Assert.AreEqual(entity.meshRootGameObject.GetComponent <MeshRenderer>().sharedMaterial, mat.material);
    }
        public void Create(RenderControl render)
        {
            // 随便构造些点
            float offset = 10.0f;

            for (int ii = 0; ii < 10; ++ii)
            {
                for (int jj = 0; jj < ii; ++jj)
                {
                    mPoints.Add(new Vector3(jj * offset, 100, ii * offset));
                }
            }


            mMotionTrail = new ParticleSceneNode((uint)mPoints.Count, ColorTable.Green, 3.0f);

            mCurrentIdx = 0;

            render.ShowSceneNode(mMotionTrail);

            var lineMaterial = BasicMaterial.Create("myline");

            lineMaterial.SetColor(ColorTable.Hex(0xFF0000));
            var line = GeometryBuilder.CreateLine(Vector3.Zero, new Vector3(1, 0, 0));

            mLineNode = new PrimitiveSceneNode(line, lineMaterial);
            mLineNode.SetTransform(MakeTransform(mStart, mPoints[0]));
            mLineNode.RequstUpdate();
            render.ShowSceneNode(mLineNode);
        }
Ejemplo n.º 15
0
        public IEnumerator VideoTextureVisibleStateIsSetCorrectly()
        {
            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");

            yield return(videoTexture.routine);

            DecentralandEntity ent1    = TestHelpers.CreateSceneEntity(scene);
            BasicMaterial      ent1Mat = TestHelpers.SharedComponentCreate <BasicMaterial, BasicMaterial.Model>(scene, CLASS_ID.BASIC_MATERIAL, new BasicMaterial.Model()
            {
                texture = videoTexture.id
            });

            TestHelpers.SharedComponentAttach(ent1Mat, ent1);
            yield return(ent1Mat.routine);

            BoxShape ent1Shape = TestHelpers.SharedComponentCreate <BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, new BoxShape.Model());

            yield return(ent1Shape.routine);

            TestHelpers.SharedComponentAttach(ent1Shape, ent1);
            yield return(null); //a frame to wait DCLVideoTexture update

            Assert.IsTrue(videoTexture.isVisible, "DCLVideoTexture should be visible");

            yield return(TestHelpers.SharedComponentUpdate <BoxShape, BoxShape.Model>(ent1Shape, new BoxShape.Model()
            {
                visible = false
            }));

            yield return(null); //a frame to wait DCLVideoTexture update

            Assert.IsTrue(!videoTexture.isVisible, "DCLVideoTexture should not be visible ");
        }
Ejemplo n.º 16
0
        public override void Run(RenderControl render)
        {
            // 1. Make face with a hole.
            var c1 = SketchBuilder.MakeCircle(GP.Origin(), 30, GP.DZ());
            var c2 = SketchBuilder.MakeCircle(GP.Origin(), 100, GP.DZ());

            var face  = SketchBuilder.MakePlanarFace(c2);
            var face2 = SketchBuilder.MakePlanarFace(c1);
            var shape = BooleanTool.Cut(face, face2);
            //render.ShowShape(shape, ColorTable.Blue);

            var faces = shape.GetChildren(EnumTopoShapeType.Topo_FACE);

            // 2. Hatch the face.
            foreach (var item in faces)
            {
                HatchHatcher hh = new HatchHatcher(item);
                hh.Build();
                var material = BasicMaterial.Create("line");
                material.SetColor(new Vector3(0.5f, 0.5f, 1.0f));
                var node = hh.Create(material);

                // 3. Show the hatching lines.
                render.ShowSceneNode(node);
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Updates the behavior. Place each radar ticks
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update(TimeSpan gameTime)
        {
            for (int i = 0; i < this.radarTicks.Count; i++)
            {
                var         fighter          = this.screenplay.FighterList[i];
                Transform3D fighterTransform = fighter.Transform;
                Transform3D radarTransform   = this.radarTicks[i];

                Vector3 distance       = fighterTransform.Position - this.transform.Position;
                float   distanceLength = distance.Length();

                if (distanceLength < radarRange)
                {
                    BasicMaterial material = radarTickMaterials[i];
                    if (!radarTransform.Owner.Enabled)
                    {
                        radarTransform.Owner.Enabled = true;
                    }

                    float lerp = distanceLength / radarRange;

                    float atenuationColor = (lerp < decay) ? 1 : 1 - ((lerp - decay) / decayInv);

                    Color color = this.colors[(int)fighter.State] * atenuationColor;

                    radarTransform.LocalPosition = (distance / radarRange) * radarSize;
                    material.DiffuseColor        = color;
                }
                else if (radarTransform.Owner.Enabled)
                {
                    radarTransform.Owner.Enabled = false;
                }
            }
        }
        public override void Run(RenderControl renderer)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "IGES (*.igs;*.iges)|*.igs;*.iges|STEP (*.stp;*.step)|*.stp;*.step|Brep (*.brep)|*.brep";
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var shape = ShapeIO.Open(dialog.FileName);

            if (shape == null)
            {
                return;
            }

            var bs = new BufferShape(shape, null, null, 0);

            bs.Build();

            // 1. Compute
            var holeExp = new HoleExplor();

            if (!holeExp.Initialize(bs))
            {
                return;
            }
            var dir = holeExp.ComputeDirection();

            holeExp.Compute(dir);

            var defaultMaterial = MeshPhongMaterial.Create("face-x");

            defaultMaterial.SetFaceSide(EnumFaceSide.DoubleSide);
            bs.SetFaceMaterial(defaultMaterial);


            // 2. Set hole faces with red color
            var material = BasicMaterial.Create("hole-face");

            material.SetFaceSide(EnumFaceSide.DoubleSide);
            material.SetColor(new Vector3(0.5f, 0, 0));
            var holeNumber = holeExp.GetHoleCount();

            for (uint ii = 0; ii < holeNumber; ++ii)
            {
                var faceIDs = holeExp.GetHoleFaces(ii);
                foreach (var faceIdx in faceIDs)
                {
                    bs.SetFaceMaterial(faceIdx, material);
                }
            }

            // 2. Show the faces
            var shapeNode = new BrepSceneNode(bs);

            renderer.ShowSceneNode(shapeNode);
        }
Ejemplo n.º 19
0
 public YnBillboard(string textureName, float width, float height)
 {
     _material = new BasicMaterial(textureName);
     _rotation = new Vector3(-MathHelper.PiOver2, 0, MathHelper.Pi);
     _width    = width;
     _height   = height;
     _isFixed  = true;
 }
Ejemplo n.º 20
0
 public void UpgradeCraft(BasicMaterial mat)
 {
     if (Inventory.inventory.Gold >= mat.UpgradeCurrentPrice)
     {
         Inventory.inventory.Gold -= mat.UpgradeCurrentPrice;
         mat.UpgradeCurrentPrice   = (int)(mat.upgradeMultiplicator * mat.UpgradeCurrentPrice);
         mat.timePerUnit           = (float)(mat.timePerUnit / 1.2);
     }
 }
Ejemplo n.º 21
0
        public BasicShaderName( int worldCount, int lightCount, BasicMaterial material )
        {
            BasicLayer[] layers = material.Layers;

            int texCount = (layers.Length <= 3) ? layers.Length : 3;
            // bool texAnim = material.UseTexAnim;

            bool a_useTexAnim = false;
            // basic
            int a_lightCount = 0;
            LightingType a_lightType = LightingType.kLIGHTING_NONE;
            NormalMapType a_normalMapType = NormalMapType.kNORMALMAP_NONE;
            if( material.LightEnable != 0 ){
            a_lightCount = lightCount;
            a_lightType = LightingType.kLIGHTING_FLAGMENT;
            a_normalMapType = NormalMapType.kNORMALMAP_NONE;
            }

            int[] texCoords = { 0, 0, 0 };
            TexType[] texTypes = { 0, 0, 0 };
            TexBlendFunc[] texBlendFuncs = { 0, 0, 0 };
            int layerCount = (layers.Length <= 3) ? layers.Length : 3;
            for( int i = 0; i < layerCount; i++ ){
            BasicLayer layer = layers[ i ];

            // ここが無駄
            if( (TexType)layer.TexType != TexType.kTEXTYPE_NONE ){
                if( (TexType)layer.TexType == TexType.kTEXTYPE_VERTEXNORMAL ){
                    a_normalMapType = NormalMapType.kNORMALMAP_VERTEX;
                }else if( (TexType)layer.TexType == TexType.kTEXTYPE_IMAGENORMALL ){
                    a_normalMapType = NormalMapType.kNORMALMAP_IMAGE;
                }
            }
            texCoords[ i ] = layer.TexCoord;
            texTypes[ i ] = (TexType)layer.TexType;
            texBlendFuncs[ i ] = (TexBlendFunc)layer.TexBlendFunc;
            if( layer.TexAnimBoneIdx >= 0 ){
                a_useTexAnim = true;
            }
            }

            this.Set(
                 worldCount,
                 material.VertexColorEnable != 0,
                 texCount,
                 a_useTexAnim,
                 a_lightCount,
                 a_lightType,
                 a_normalMapType,
                 texCoords,
                 texTypes,
                 texBlendFuncs,
                 material.AlphaThreshold > 0.0f
                 );
        }
Ejemplo n.º 22
0
        public void SurfaceDrawTest()
        {
            var material = new BasicMaterial(GraphicsDevice);
            var surface  = new Surface(GraphicsDevice, new Heightmap(1, 2, 2), 2);
            var context  = new DrawingContext(GraphicsDevice);

            foreach (var patch in surface.Patches)
            {
                patch.Draw(context, material);
            }
        }
Ejemplo n.º 23
0
        public BasicBody(IDynamicBody dynamics, IElectroMag eMProps, BasicMaterial material, IEdgeIntersector collisionShape, IVolume shape, IOverlapable boundVolume)
        {
            Dynamics       = dynamics;
            EMProps        = eMProps;
            Material       = material;
            CollisionShape = collisionShape;
            Shape          = shape;
            BoundVolume    = boundVolume;

            Dynamics.FrameFinished += (sender, e) => FrameFinished?.Invoke(sender, e);
        }
Ejemplo n.º 24
0
        public static BasicMaterial CreateEntityWithBasicMaterial(ParcelScene scene, BasicMaterial.Model model, Vector3 position,
                                                                  out DecentralandEntity entity)
        {
            InstantiateEntityWithShape <BoxShape, BoxShape.Model>(scene, DCL.Models.CLASS_ID.BOX_SHAPE, position,
                                                                  out entity);
            BasicMaterial material =
                SharedComponentCreate <BasicMaterial, BasicMaterial.Model>(scene, CLASS_ID.BASIC_MATERIAL, model);

            SharedComponentAttach(material, entity);
            return(material);
        }
Ejemplo n.º 25
0
    public IEnumerator ProcessCastShadowProperty_False()
    {
        BasicMaterial basicMaterialComponent = TestHelpers.CreateEntityWithBasicMaterial(scene, new BasicMaterial.Model
        {
            alphaTest   = 1f,
            castShadows = false
        }, out DecentralandEntity entity);

        yield return(basicMaterialComponent.routine);

        Assert.AreEqual(false, basicMaterialComponent.model.castShadows);
        Assert.AreEqual(ShadowCastingMode.Off, entity.meshRootGameObject.GetComponent <MeshRenderer>().shadowCastingMode);
    }
    public IEnumerator ProcessCastShadowProperty_True()
    {
        BasicMaterial basicMaterialComponent = TestHelpers.CreateEntityWithBasicMaterial(scene, new BasicMaterial.Model
        {
            alphaTest   = 1f,
            castShadows = true
        }, out IDCLEntity entity);

        yield return(basicMaterialComponent.routine);

        Assert.AreEqual(true, basicMaterialComponent.GetModel().castShadows);
        Assert.AreEqual(ShadowCastingMode.On, entity.meshRootGameObject.GetComponent <MeshRenderer>().shadowCastingMode);
    }
Ejemplo n.º 27
0
        private void CreateCube3D()
        {
            Entity cube = new Entity("Cube")
                          .AddComponent(new Transform3D())
                          .AddComponent(Model.CreateCube())
                          .AddComponent(new MaterialsMap(new BasicMaterial("Content/crate.jpg")))
                          .AddComponent(new ModelRenderer());


            this.cubeTransform = cube.FindComponent <Transform3D>();
            this.cubeMaterial  = (BasicMaterial)cube.FindComponent <MaterialsMap>().DefaultMaterial;

            EntityManager.Add(cube);
        }
        internal static async Task <Multipatch> MakeFishnetRingMultiPatchAsync(Polygon inputPoly)
        {
            Envelope envPoly  = inputPoly.Extent;
            var      interval = GetFishnetIntervalDistance(envPoly);

            var mColor      = System.Windows.Media.Colors.LightCyan;
            var materialRed = new BasicMaterial
            {
                Color     = mColor,
                EdgeColor = mColor,
                EdgeWidth = 0
            };
            // create the multipatchBuilderEx object
            var mpb = new MultipatchBuilderEx();
            // create a list of patch objects
            var patches = new List <Patch>();
            var first   = true;

            for (var dX = envPoly.XMin; dX < envPoly.XMax + interval; dX += interval)
            {
                for (var dY = envPoly.YMin; dY < envPoly.YMax + interval; dY += interval)
                {
                    var cutEnv = EnvelopeBuilder.CreateEnvelope(dX, dY, dX + interval, dY + interval,
                                                                envPoly.SpatialReference);
                    if (GeometryEngine.Instance.Intersects(cutEnv, inputPoly))
                    {
                        var addPolygonPart = GeometryEngine.Instance.Clip(inputPoly, cutEnv) as Polygon;
                        if (addPolygonPart.Area < 0)
                        {
                            System.Diagnostics.Debug.WriteLine($@"area: {addPolygonPart.Area}");
                        }
                        var result = await Module1.CurrentMapView.Map.GetZsFromSurfaceAsync(addPolygonPart);

                        if (result.Status == SurfaceZsResultStatus.Ok)
                        {
                            addPolygonPart = GeometryEngine.Instance.Move(result.Geometry, 0, 0, Module1.Elevation) as Polygon;
                        }
                        var patch = mpb.MakePatch(first ? esriPatchType.FirstRing : esriPatchType.Ring);
                        first = false;
                        patch.InsertPoints(0, addPolygonPart.Points);
                        patch.Material = materialRed;
                        patches.Add(patch);
                    }
                }
            }      // assign the patches to the multipatchBuilder
            mpb.Patches = patches;
            // call ToGeometry to get the multipatch
            return(mpb.ToGeometry() as Multipatch);
        }
Ejemplo n.º 29
0
        public BoxMesh()
        {
            _builder = new BoxBuilder(10, 10, 10);
            _mat     = BasicMaterial.CreateDefaultMaterial("boxMaterial");

            //VertexPositionColor[] vertexes = new VertexPositionColor[_builder.Vertices.Length];
            //for (int i = 0; i < vertexes.Length; i++)
            //{
            //    vertexes[i] = new VertexPositionColor(_builder.Vertices[i].Position, new Color4(1, 1, 0, 0));
            //}
            var device = GraphicDeviceFactory.Device;

            _vb = device.CreateVertexBuffer(data: _builder.Vertices);
            _ib = device.CreateIndexBuffer(data: _builder.Indices);

            _mat.Diffuse           = new Vector3(1, 1, 1);
            _mat.DiffuseMap        = device.CreateTexture2DFromFile(@"I:\Pictures\lufy.png");
            _mat.SpecularIntensity = 0;
            _mat.EmisiveIntensity  = 0;
            _mat.Alpha             = 1f;
            IsTransparent          = _mat.ContainsTrasparency;

            SetRender <DefaultTechnique, BasicMeshEffect>((box, render) =>
            {
                var effect = render.Effect;

                //effect.Constants.gId = new Vector4(1, 1, 0, 0);
                //effect.U.World = Matrix.Identity;
                //map.World = Matrix.Identity;

                device.PrimitiveTopology = IAPrimitive.TriangleList;
                device.SetVertexBuffer(0, _vb, 0);
                device.SetIndexBuffer(_ib, 0);

                render.Bind(_mat);
                foreach (var pass in effect.Passes(0))
                {
                    effect.Apply(pass);
                    device.DrawIndexed(_builder.Indices.Length, 0, 0);
                }
                effect.EndPasses();
            });
            //.BindWith(new CameraBinding())
            //.BindWith(new MeshMaterialBinding())
            //.BindWith(new LightBinding())
            //.BindWith(new AmbientLightBinding())
            //.BindWith(new PixelClippingBinding());
        }
Ejemplo n.º 30
0
        protected override void CreateResources(ResourceFactory factory)
        {
            var texture = TextureLoader.Load("v:checker").GetAwaiter().GetResult();

            basicMaterial = new BasicMaterial(DrawingContext, texture, true);

            // var shape1 = new Cube(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
            // var shape2 = new Cube(new Vector3(0.8f, 0.8f, 0), new Vector3(1, 1, 1));
            // var shape = shape1.Do(ShapeOperation.Intersect, shape2);

            var shape = new Teapot();

            shapeGeometry = new ShapeGeometry(DrawingContext, shape);

            commandList = factory.CreateCommandList();
        }
        private Multipatch ApplyMaterialsToMultipatch(Multipatch source)
        {
            // create material for the top face patch
            BasicMaterial topFaceMaterial = new BasicMaterial();

            topFaceMaterial.Color               = Color.FromRgb(203, 65, 84);
            topFaceMaterial.Shininess           = 150;
            topFaceMaterial.TransparencyPercent = 50;
            topFaceMaterial.EdgeWidth           = 20;

            // create material for the bottom face patch
            BasicMaterial bottomFaceMaterial = new BasicMaterial();

            bottomFaceMaterial.Color     = Color.FromRgb(203, 65, 84);
            bottomFaceMaterial.EdgeWidth = 20;

            // create material for the sides face
            BasicMaterial sidesFaceMaterial = new BasicMaterial();

            sidesFaceMaterial.Color     = Color.FromRgb(133, 94, 66);
            sidesFaceMaterial.Shininess = 0;
            sidesFaceMaterial.EdgeWidth = 20;


            // create a builder using the source multipatch
            var cubeMultipatchBuilderEx = new MultipatchBuilderEx(source);

            // set material to the top face patch
            var topFacePatch = cubeMultipatchBuilderEx.Patches[0];

            topFacePatch.Material = topFaceMaterial;

            // set material to the bottom face patch
            var bottomFacePatch = cubeMultipatchBuilderEx.Patches[1];

            bottomFacePatch.Material = bottomFaceMaterial;

            // set material to the sides face patch
            var sidesFacePatch = cubeMultipatchBuilderEx.Patches[2];

            sidesFacePatch.Material = sidesFaceMaterial;

            // create the geometry
            Multipatch cubeMultipatchWithMaterials = cubeMultipatchBuilderEx.ToGeometry() as Multipatch;

            return(cubeMultipatchWithMaterials);
        }
Ejemplo n.º 32
0
        public IEnumerator VideoTextureVisibleStateIsSetCorrectlyWhenAddedToAMaterialNotAttachedToShape()
        {
            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");

            yield return(videoTexture.routine);

            DecentralandEntity ent1    = TestHelpers.CreateSceneEntity(scene);
            BasicMaterial      ent1Mat = TestHelpers.SharedComponentCreate <BasicMaterial, BasicMaterial.Model>(scene, CLASS_ID.BASIC_MATERIAL, new BasicMaterial.Model()
            {
                texture = videoTexture.id
            });

            TestHelpers.SharedComponentAttach(ent1Mat, ent1);
            yield return(ent1Mat.routine);

            Assert.IsTrue(!videoTexture.isVisible, "DCLVideoTexture should not be visible without a shape");
        }
Ejemplo n.º 33
0
        private void CreateCube3D()
        {
            Entity cube = new Entity("Cube")
                 .AddComponent(new Transform3D())
                 .AddComponent(Model.CreateCube())
                 .AddComponent(new MaterialsMap(new BasicMaterial("Content/crate.jpg")))
                 .AddComponent(new ModelRenderer());


            this.cubeTransform = cube.FindComponent<Transform3D>();
            this.cubeMaterial = (BasicMaterial)cube.FindComponent<MaterialsMap>().DefaultMaterial;

            EntityManager.Add(cube);
        }
Ejemplo n.º 34
0
        /// <summary>
        /// Create a BasicMaterial from a "<material>".
        /// <param name="material">The "<material>" element to be converted.</param>
        /// <param name="context"> The current context for the COLLADA Processor</param>
        /// </summary>
        public BasicMaterial CreateBasicMaterial(Model model, Document.Material material)
        {
            Document doc = model.Doc;
            uint textureChannel = 0;

            Dictionary<string, uint> textureBinding = new Dictionary<string, uint>();
            textureBindings[material.id] = textureBinding;
            BasicMaterial materialContent = new BasicMaterial();
            Document.Effect effect = (Document.Effect)doc.dic[material.instanceEffect.Fragment];

            if (effect == null) throw new Exception("cannot find effect#" + material.instanceEffect.Fragment);
            // search common profile with correct asset....
            Document.ProfileCOMMON profile;
            foreach (Document.IProfile tmpProfile in effect.profiles)
            {
                if (tmpProfile is Document.ProfileCOMMON)
                {
                    profile = (Document.ProfileCOMMON)tmpProfile;
                    goto Found;
                }
            }
            throw new Exception("Could not find profile_COMMON in effect" + effect.ToString());
            Found:
            // read params
            // Dictionary<string, string> samplerBind = new Dictionary<string, string>();
            // Dictionary<string, string> imageBind = new Dictionary<string, string>();

            // Read Technique
            Document.SimpleShader shader = ((Document.ProfileCOMMON)profile).technique.shader;

            materialContent.Name = material.name;
            // BasicShader only accept texture for the diffuse channel
            if (shader.diffuse is Document.Texture)
            {
                string sampler = ((Document.Texture)shader.diffuse).texture;
                string surface;
                string image;
                if (profile.newParams.ContainsKey(sampler))
                {
                    surface = ((Document.Sampler2D)profile.newParams[sampler].param).source;
                    image = ((Document.Surface)profile.newParams[surface].param).initFrom;
                }
                else
                {
                    image = sampler;
                    // TODO: emit serious warning - invalid content
                }
                // now find image
                string imagePath = ((Document.Image)doc.dic[image]).init_from.Uri.LocalPath;
                // here associate 1 texture binding per texture in material
                textureBinding[((Document.Texture)shader.diffuse).texcoord] = textureChannel++;
                materialContent.Texture = imagePath;
            }
            else if (shader.diffuse is Document.Color)
            {
                Document.Color color = (Document.Color)shader.diffuse;
                // TODO: manage color[3] in transparency
                materialContent.DiffuseColor = new Vector3(color[0], color[1], color[2]);
            }
            if (shader.ambient is Document.Texture)
            {
                // Basic Material does not accept texture on ambient channel
                COLLADAUtil.Log("Ambient channel not supported in BasicMaterial.");
                /*
                string sampler = ((Document.Texture)shader.ambient).texture;
                string surface = ((Document.Sampler2D)profile.newParams[sampler].param).source;
                string image = ((Document.Surface)profile.newParams[surface].param).initFrom;
                // now find image
                string imagePath = ((Document.Image)doc.dic[image]).init_from.Uri.LocalPath;
                // here associate 1 texture binding per texture in material
                textureBinding[((Document.Texture)shader.ambient).texcoord] = textureChannel++;
                materialContent.Texture = new ExternalReference<TextureContent>(imagePath);
                 */

            }
            else if (shader.ambient is Document.Color)
            {
                // XNA BasicMaterial has no ambient
                COLLADAUtil.Log("Ambient channel not supported in BasicMaterial.");
            }
            if (shader.emission is Document.Texture)
            {
                // XNA BasicMaterial does not accept texture for emmision
                COLLADAUtil.Log("BasicMaterial does not accept texture for emmision.");
                /*
                string sampler = ((Document.Texture)shader.emission).texture;
                string surface = ((Document.Sampler2D)profile.newParams[sampler].param).source;
                string image = ((Document.Surface)profile.newParams[surface].param).initFrom;
                // now find image
                string imagePath = ((Document.Image)doc.dic[image]).init_from.Uri.LocalPath;
                // here associate 1 texture binding per texture in material
                textureBinding[((Document.Texture)shader.emission).texcoord] = textureChannel++;
                materialContent.Texture = new ExternalReference<TextureContent>(imagePath);
                 */
            }
            else if (shader.emission is Document.Color)
            {
                Document.Color color = (Document.Color)shader.emission;
                materialContent.EmissiveColor = new Vector3(color[0], color[1], color[2]);
            }
            if (shader.specular is Document.Texture)
            {
                // XNA BasicMaterial does not accept texture for specular
                COLLADAUtil.Log("BasicMaterial does not accept texture for specular.");
                /*
                string sampler = ((Document.Texture)shader.specular).texture;
                string surface = ((Document.Sampler2D)profile.newParams[sampler].param).source;
                string image = ((Document.Surface)profile.newParams[surface].param).initFrom;
                // now find image
                string imagePath = ((Document.Image)doc.dic[image]).init_from.Uri.LocalPath;
                // here associate 1 texture binding per texture in material
                textureBinding[((Document.Texture)shader.specular).texcoord] = textureChannel++;
                materialContent.Texture = new ExternalReference<TextureContent>(imagePath);
                 */
            }
            else if (shader.specular is Document.Color)
            {
                Document.Color color = (Document.Color)shader.specular;
                materialContent.SpecularColor = new Vector3(color[0], color[1], color[2]);
                if (shader.shininess is Document.Float)
                    materialContent.SpecularPower = ((Document.Float)shader.shininess).theFloat;
            }
            if (shader.transparency is Document.Texture)
            {
                // XNA Basic Shader does not accept a texture for the transparency channel
                COLLADAUtil.Log("BasicMaterial does not accept texture for transparency channel.");
                /*
                string sampler = ((Document.Texture)shader.transparency).texture;
                string surface = ((Document.Sampler2D)profile.newParams[sampler].param).source;
                string image = ((Document.Surface)profile.newParams[surface].param).initFrom;
                // now find image
                string imagePath = ((Document.Image)doc.dic[image]).init_from.Uri.LocalPath;
                // here associate 1 texture binding per texture in material
                textureBinding[((Document.Texture)shader.transparency).texcoord] = textureChannel++;
                materialContent.Texture = new ExternalReference<TextureContent>(imagePath);
                 */
            }
            else if (shader.transparency is Document.Float)
            {
                materialContent.Alpha = ((Document.Float)shader.transparency).theFloat;
            }

            return materialContent;
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Initializes the shockwave behavior
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            this.material = this.materials.DefaultMaterial as BasicMaterial;
        }