protected override void OnFree(bool isManual)
        {
            base.OnFree(isManual);

            if (m_Mesh != null)
            {
                m_Mesh.Dispose();
                m_Mesh = null;
            }
        }
 internal SoftMeshRenderer(Vector3 pos, Vector3 up, Vector3 lookAt, Mesh mesh) : base()
 {
     this.Position = pos;
     this.Up       = up;
     this.LookAt   = lookAt;
     this.m_Type   = SoftRenderObjType.MeshRender;
     if (mesh != null)
     {
         m_Mesh = new SoftMesh(mesh);
     }
 }
示例#3
0
        public bool RenderMesh(SoftMesh mesh, Matrix4x4 objToWorld, RenderPassMode passMode)
        {
            if (mesh == null || passMode == null)
            {
                return(false);
            }
            var  subMeshes = mesh.SubMeshes;
            bool ret       = false;

            if (subMeshes != null)
            {
                for (int i = 0; i < subMeshes.Count; ++i)
                {
                    var subMesh = subMeshes[i];
                    if (RenderSubMesh(mesh, subMesh, objToWorld, passMode))
                    {
                        ret = true;
                    }
                }
            }
            return(ret);
        }
示例#4
0
        private bool RenderSubMesh(SoftMesh mesh, SoftSubMesh subMesh, Matrix4x4 objToWorld, RenderPassMode passMode)
        {
            if (subMesh == null || passMode == null)
            {
                return(false);
            }
            var  indexes = subMesh.Indexes;
            var  vertexs = mesh.Vertexs;
            var  colors  = mesh.Colors;
            var  uv1s    = mesh.UV1s;
            bool ret     = false;

            bool    isColorEmpty = colors == null || colors.Count <= 0;
            bool    isUV1Empty   = uv1s == null || uv1s.Count <= 0;
            Color   c1           = Color.white;
            Color   c2           = Color.white;
            Color   c3           = Color.white;
            Vector4 uv1_1        = Vector4.zero;
            Vector4 uv1_2        = Vector4.zero;
            Vector4 uv1_3        = Vector4.zero;

            if (vertexs != null && (isColorEmpty || vertexs.Count == colors.Count) &&
                indexes != null && indexes.Count > 0)
            {
                int triangleCnt = ((int)indexes.Count / 3);
                for (int i = 0; i < triangleCnt; ++i)
                {
                    int     idx   = i * 3;
                    int     index = indexes[idx];
                    Vector3 p1    = vertexs[index];
                    if (!isColorEmpty)
                    {
                        c1 = colors[index];
                    }
                    if (!isUV1Empty)
                    {
                        uv1_1 = uv1s[index];
                    }
                    index = indexes[idx + 1];
                    Vector3 p2 = vertexs[index];
                    if (!isColorEmpty)
                    {
                        c2 = colors[index];
                    }
                    if (!isUV1Empty)
                    {
                        uv1_2 = uv1s[index];
                    }
                    index = indexes[idx + 2];
                    Vector3 p3 = vertexs[index];
                    if (!isColorEmpty)
                    {
                        c3 = colors[index];
                    }
                    if (!isUV1Empty)
                    {
                        uv1_3 = uv1s[index];
                    }
                    Triangle tri = new Triangle(p1, p2, p3);

                    // 三角形转到世界坐标系
                    tri.MulMatrix(objToWorld);
                    // 过CullMode 【注意】根据渲染管线VertexShader中可以任意改变三角形,所以要放到VS后面才行,也就是到MVP坐标系里判断
                    // 不在这里做摄影机剔除,移到VS后面
                    //   if (SoftMath.IsCulled(this, passMode.Cull, tri)) {
                    //       continue;
                    //   }
                    //----

                    TriangleVertex triV = new TriangleVertex(tri, c1, c2, c3, passMode.mainTex);
                    if (!isUV1Empty)
                    {
                        triV.uv1_1 = uv1_1;
                        triV.uv1_2 = uv1_2;
                        triV.uv1_3 = uv1_3;
                    }

                    // 进入VertexShader了, 做顶点变换等
                    m_TrianglesMgr.AddTriangle(triV);
                    ret = true;
                }
            }
            return(ret);
        }