예제 #1
0
        private void UpdateBuffer(bool resetTree = true)
        {
            m_verticesFloat.Clear();
            m_verticesMatrices.Clear();
            m_verticesTextures.Clear();
            m_verticesColors.Clear();
            m_verticesTransparent.Clear();
            m_verticesWrapModes.Clear();
            m_verticesUnlit.Clear();

            if (m_modelNode == null)
            {
                return;
            }

            Vector3 center = Vector3.Zero;
            float   radius = 0;

            List <ModelNode> nodes = null;

            if (m_includeChildren)
            {
                if (m_isNode)
                {
                    nodes = m_modelNode.GetAllNodes(false);
                }
                else
                {
                    nodes = m_modelNode.GetAllNodes();
                }
            }
            else
            {
                nodes = m_modelNode.GetAllNodes(false, false);
            }

            foreach (ModelNode node in nodes)
            {
                Matrix4 modelMatrix = new Matrix4();
                ToOpenTK(ref modelMatrix, node.GetTransformMatrix());

                if (node.HasMesh)
                {
                    if (node.Radius > radius)
                    {
                        radius = node.Radius;
                    }
                    Vector3 c = ToOpenTK(node.Center);
                    c      = Vector3.TransformPosition(c, modelMatrix);
                    center = Vector3.Lerp(center, c, 0.5f);
                }

                if (node.Faces.Count == 0)
                {
                    continue;
                }
                foreach (MeshFace entry in node.Faces)
                {
                    m_verticesFloat.Add(entry.GetFloatArray(node, Vertex.VertexFormat.VertexNormalUVColor));
                    m_verticesMatrices.Add(modelMatrix);
                    m_verticesTextures.Add(entry.TextureIndex);
                    m_verticesColors.Add(Color4.White); //ToOpenTK(entry.StripColor)
                    m_verticesTransparent.Add(entry.Transparent);
                    m_verticesWrapModes.Add((TextureWrapMode)entry.Wrap);
                    m_verticesUnlit.Add(entry.Unlit);
                }
            }
            m_modelCenter = center;
            CreateTextures();
        }