Example #1
0
        void SetHilight(bool hilight, StaticModel mesh, Color color, uint?materialIndex = null)
        {
            //hilight all materials
            if (materialIndex == null)
            {
                for (uint i = 0; i < 10; i++)
                {
                    var mat = mesh.GetMaterial(i);
                    if (mat == null)
                    {
                        break;
                    }

                    SetHilightMaterial(hilight, mesh, mat, i, color);
                }
            }

            //hilight the specific material
            else
            {
                var material = mesh.GetMaterial(materialIndex.Value);
                if (material == null)
                {
                    return;
                }

                SetHilightMaterial(hilight, mesh, material, materialIndex.Value, color);
            }
        }
Example #2
0
        public static void HideBoundingAreas(Node node)
        {
            if (node == null)
            {
                return;
            }

            // jos node on joku collision type, piilota se
            if (node.Name.Contains("_CB") ||
                node.Name.Contains("_CS") ||
                node.Name.Contains("_CS") ||
                node.Name.Contains("_CM"))
            {
                StaticModel m = node.GetComponent <StaticModel>();
                if (m != null)
                {
                    m.GetMaterial().SetTechnique(0, Main.Instance.ResourceCache.GetTechnique("Techniques/NoTextureUnlitAlpha.xml"), 0, 0);
                    m.GetMaterial().SetShaderParameter("MatDiffColor", new Color(0, 0, 0, 0));
                }
            }

            var children = node.Children;

            for (int i = 0; i < children.Count; i++)
            {
                Node nnode = children[i];
                HideBoundingAreas(nnode);
            }
        }
Example #3
0
 void SetHilight(bool hilight, StaticModel mesh, Color color)
 {
     for (uint i = 0; i < 5; i++)
     {
         var mat = mesh.GetMaterial(i);
         if (mat == null)
         {
             break;
         }
         var matCopy = mat.Clone(mat.Name + "_hilight");
         matCopy.SetShaderParameter("MatDiffColor", hilight ? color : Urho.Color.White);
         mesh.SetMaterial(i, matCopy);
     }
 }
Example #4
0
        public override void OnSurfaceAddedOrUpdated(SpatialMeshInfo surface, Model generatedModel)
        {
            bool        isNew       = false;
            StaticModel staticModel = null;
            Node        node        = environmentNode.GetChild(surface.SurfaceId, false);

            if (node != null)
            {
                isNew       = false;
                staticModel = node.GetComponent <StaticModel>();
            }
            else
            {
                isNew       = true;
                node        = environmentNode.CreateChild(surface.SurfaceId);
                staticModel = node.CreateComponent <StaticModel>();
            }

            node.Position     = surface.BoundsCenter;
            node.Rotation     = surface.BoundsRotation;
            staticModel.Model = generatedModel;

            Material mat;
            Color    startColor;
            Color    endColor = new Color(0.8f, 0.8f, 0.8f);

            if (isNew)
            {
                startColor = Color.Blue;
                mat        = Material.FromColor(endColor);
                staticModel.SetMaterial(mat);
            }
            else
            {
                startColor = Color.Red;
                mat        = staticModel.GetMaterial(0);
            }

            mat.FillMode = wireframe ? FillMode.Wireframe : FillMode.Solid;
            var specColorAnimation = new ValueAnimation();

            specColorAnimation.SetKeyFrame(0.0f, startColor);
            specColorAnimation.SetKeyFrame(1.5f, endColor);
            mat.SetShaderParameterAnimation("MatDiffColor", specColorAnimation, WrapMode.Once, 1.0f);
        }
Example #5
0
    private void ReplaceTexture()
    {
        StaticModel model = Node.GetComponent<StaticModel>(true);
        if (model != null)
        {
            ResourceCache cache = GetSubsystem<ResourceCache>();
            Texture2D texture = cache.GetResource<Texture2D>(texturePath);
            Material material = model.GetMaterial(0);
            if (texture != null && material != null)
            {
                if (instanceMaterial)
                {
                    Material materialClone = material.Clone();
                    model.SetMaterial(0, materialClone);
                    material = materialClone;
                }

                material.SetTexture(TextureUnit.TU_DIFFUSE, texture);
            }
        }
    }
Example #6
0
 public void SetTechnique(string name)
 {
     model.GetMaterial().SetTechnique(0, Main.Instance.ResourceCache.GetTechnique("Techniques/" + name), 0, 0);
 }