Пример #1
0
        private static void PrepareModel(
            this NJObject obj,
            List <RenderMesh> opaque,
            List <RenderMesh> transparent,
            BufferingBridge buffer,
            Camera cam,
            NJObject activeObj,
            Matrix4?parentWorld,
            bool weighted)
        {
            Matrix4 world = obj.LocalMatrix;

            if (parentWorld.HasValue)
            {
                world *= parentWorld.Value;
            }

            if (obj.Attach != null && obj.Attach.MeshData.Length > 0)
            {
                // if a model is weighted, then the buffered vertex positions/normals will have to be set to world space, which means that world and normal matrix should be identities
                if (weighted)
                {
                    buffer.LoadToCache(obj.Attach.MeshData, world, obj == activeObj);
                }
                else if (!buffer.IsBuffered(obj.Attach.MeshData[0]))
                {
                    buffer.LoadToCache(obj.Attach.MeshData, null, false);
                }

                RenderMatrices matrices = weighted ? new(cam.ViewMatrix * cam.ProjectionMatrix) : new(world, world *cam.ViewMatrix *cam.ProjectionMatrix);

                var meshes = obj.Attach.GetDisplayMeshes();

                if (meshes.opaque.Length > 0)
                {
                    opaque.Add(new RenderMesh(meshes.opaque, matrices));
                }

                if (meshes.transparent.Length > 0)
                {
                    transparent.Add(new RenderMesh(meshes.transparent, matrices));
                }
            }

            for (int i = 0; i < obj.ChildCount; i++)
            {
                obj[i].PrepareModel(opaque, transparent, buffer, cam, activeObj, world, weighted);
            }
        }
Пример #2
0
 public RenderMesh(BufferMesh[] meshes, RenderMatrices matrices)
 {
     this.meshes   = meshes;
     this.matrices = matrices;
 }