Ejemplo n.º 1
0
        private void RecreateRenderData()
        {
            if (Mesh?.GetAsset() != null)
            {
                CRenderScene scene = CRenderer.Instance.ActiveScene;
                if (m_renderNode != null)
                {
                    scene.UnregisterRenderNode(m_renderNode);
                }

                if (m_overrideMaterial != null)
                {
                    m_renderNode = new CMeshRenderNode(this, Mesh, null, m_transform);
                    m_renderNode.SetMaterialOverride(m_overrideMaterial);
                }
                else
                {
                    m_renderNode = new CMeshRenderNode(this, Mesh, MaterialAsset, m_transform);
                }
                scene.RegisterRenderNode(m_renderNode);
            }
            else
            {
                if (m_renderNode != null)
                {
                    CRenderer.Instance.ActiveScene.UnregisterRenderNode(m_renderNode);
                }
            }
        }
Ejemplo n.º 2
0
        private void RecreateRenderData(float deltaTime)
        {
            if (Model == null)
            {
                CRenderScene scene = CRenderer.Instance.ActiveScene;
                for (int i = 0; i < m_renderNodes.Length; i++)
                {
                    scene.UnregisterRenderNode(m_renderNodes[i]);
                }

                return;
            }

            CModelAsset modelAsset = Model.GetAsset();

            if (modelAsset != null && modelAsset.IsLoaded)
            {
                CRenderScene scene = CRenderer.Instance.ActiveScene;
                for (int i = 0; i < m_renderNodes.Length; i++)
                {
                    scene.UnregisterRenderNode(m_renderNodes[i]);
                }

                int meshCount = modelAsset.MeshChildren.Count;
                m_renderNodes = new CMeshRenderNode[meshCount];
                m_overrideMaterials.SetMinSize(meshCount);
                m_materialAssets.SetMinSize(meshCount);
                for (int i = 0; i < meshCount; i++)
                {
                    Transform childTransform = new Transform();
                    childTransform.SetFromMatrix(modelAsset.MeshChildren[i].relativeTransform);
                    childTransform.Parent = m_transform;
                    CMeshRenderNode newRenderNode;
                    if (m_overrideMaterials[i] != null)
                    {
                        newRenderNode = new CMeshRenderNode(this, modelAsset.MeshChildren[i].meshAsset, null, childTransform);
                        newRenderNode.SetMaterialOverride(m_overrideMaterials[i]);
                    }
                    else
                    {
                        newRenderNode = new CMeshRenderNode(this, modelAsset.MeshChildren[i].meshAsset, m_materialAssets[i], childTransform);
                    }
                    m_renderNodes[i] = newRenderNode;
                    scene.RegisterRenderNode(newRenderNode);
                }

                m_updateRenderDataScope?.Disconnect();
                m_updateRenderDataScope = null;
            }
        }
        public bool TryExecute(Device device, DeviceContext deviceContext, CRenderScene scene)
        {
            if (!m_sourceAsset.IsLoaded)
            {
                return(false);
            }

            for (int i = 0; i < m_sourceAsset.MeshChildren.Count; i++)
            {
                SMeshChild meshChild      = m_sourceAsset.MeshChildren[i];
                Transform  childTransform = new Transform();
                childTransform.SetFromMatrix(in meshChild.relativeTransform);
                childTransform.Parent = m_modelTransform;

                CMeshRenderNode renderNode = new CMeshRenderNode(m_outer, meshChild.meshAsset, null, childTransform);
                if (meshChild.meshAsset.GetAsset().IsLoaded)
                {
                    renderNode.TryCreateResources();
                }
                scene.RegisterRenderNode(renderNode);
            }

            return(true);
        }