Exemplo n.º 1
0
        public void RenderNode(ModelNode node, SlimDX.Matrix transform, VisibilityNode visibilityNode, bool isTransparent)
        {
            if (visibilityNode != null && !visibilityNode.Visible)
            {
                return;
            }

            SlimDX.Matrix localTransform = transform * node.Transform;

            foreach (int subMeshIndex in node.SubMeshIndices)
            {
                SubMesh  subMesh  = SubMeshes[subMeshIndex];
                Mesh     mesh     = Meshes[subMesh.MeshIndex];
                Material material = Materials[subMesh.MaterialIndex];
                //if (material.Visible)
                //{
                if ((material.BlendMode == 0 && !isTransparent) || (material.BlendMode != 0 && isTransparent))
                {
                    mesh.ApplyMaterial(material);
                    mesh.ApplyTransform(localTransform);
                    mesh.ApplyBuffers();
                    mesh.Render(subMesh.indexCount, subMesh.startIndexLocation, subMesh.baseVertexLocation);
                }
                //}
            }

            int n = 0;

            foreach (ModelNode child in node.Nodes)
            {
                RenderNode(child, localTransform, visibilityNode?.Nodes[n], isTransparent);
                n++;
            }
        }
Exemplo n.º 2
0
 public void Render(Matrix transform, VisibilityNode visibilityNode)
 {
     if (SubMeshes.Count > 0)
     {
         RenderNode(Root, transform, visibilityNode, false);
         RenderNode(Root, transform, visibilityNode, true);
     }
 }
Exemplo n.º 3
0
        public void UpdateModel()
        {
            bool           foundResource;
            RenderResource resource;

            if (RenderManager.Instance.Resources.ContainsKey(_resourceName))
            {
                resource      = RenderManager.Instance.Resources[_resourceName];
                foundResource = true;
            }
            else
            {
                resource      = RenderManager.Instance.Resources[""];
                foundResource = false;
            }

            Model newModel = resource.Models[foundResource ? _modelIndex : 0];

            if (Model != newModel)
            {
                Model = newModel;

                Root.Name = Model.Root.Name;
                foreach (ModelNode modelNode in Model.Root.Nodes)
                {
                    VisibilityNode visibilityNode = new VisibilityNode();
                    visibilityNode.Name = modelNode.Name;
                    Root.Nodes.Add(visibilityNode);
                }

                float height = (resource.Name == "") ? GetBoundingSphere().Radius : 0.0f;

                Matrix.RotationYawPitchRoll(
                    _rotation.X,
                    _rotation.Y,
                    _rotation.Z,
                    out Matrix rotationMatrix
                    );

                Transform = rotationMatrix * Matrix.Translation(
                    _position.X,
                    _position.Y + height,
                    _position.Z
                    );
            }
        }
Exemplo n.º 4
0
        public VisibilityNode FindNode(string name, VisibilityNode visibilityNode)
        {
            if (visibilityNode.Name == name)
            {
                return(visibilityNode);
            }

            foreach (VisibilityNode child in visibilityNode.Nodes)
            {
                visibilityNode = FindNode(name, child);
                if (visibilityNode != null)
                {
                    return(visibilityNode);
                }
            }

            return(null);
        }