internal void Render(IRenderer renderer, GcmfRenderContext context) { foreach (GcmfTriangleStrip strip in Items) { strip.Render(renderer, context); } }
/// <summary> /// Render this Gcmf object using the given renderer. /// </summary> public void Render(IRenderer renderer) { GcmfRenderContext context = new GcmfRenderContext(this); // Set up the default transform matrix indexes in the context // Those may get patched later in each triangle mesh // Note that those are not re-set for every mesh! // The specific indexes set on one mesh may affect the next meshes Array.Copy(TransformMatrixDefaultIdxs, context.TransformMatrixIdxs, 8); // Set up the materials required to render each mesh for (int i = 0; i < Materials.Count; i++) { Materials[i].Render(renderer, i); } // Render each mesh for (int i = 0; i < Meshes.Count; i++) { renderer.BeginObject(string.Format("Mesh{0}", i)); Meshes[i].RenderInternal(renderer, context); renderer.EndObject(); } // Clean up the materials in order to have a clean ground for the next object renderer.ClearMaterialList(); }
internal void Render(IRenderer renderer, GcmfRenderContext context) { // Convert GcmfVertex list to ModelVertex list ModelVertex[] modelVertices = new ModelVertex[Items.Count]; for (int i = 0; i < Items.Count; i++) { GcmfVertex gcmfVtx = Items[i]; // Copy the data from the GCMF vertex to the ModelVertex ModelVertex modelVtx = new ModelVertex() { Position = gcmfVtx.Position, Normal = gcmfVtx.Normal, VertexColor = gcmfVtx.VertexColor, PrimaryTexCoord = gcmfVtx.PrimaryTexCoord }; // Apply transformation matrices to the vertex if (gcmfVtx.TransformMatrixRef != null && gcmfVtx.TransformMatrixRef.Value != 0) { if (gcmfVtx.TransformMatrixRef.Value > 24 || (gcmfVtx.TransformMatrixRef % 3) != 0) { throw new InvalidGmaFileException("Invalid TransformMatrixRef for the transform matrix rendering."); } int rIdx = (gcmfVtx.TransformMatrixRef.Value / 3) - 1; if (context.TransformMatrixIdxs[rIdx] == byte.MaxValue) { throw new InvalidGmaFileException("The transform matrix associated to the matrix reference is not defined."); } // Transform the position and normal vectors according to the transform matrix GcmfTransformMatrix tMtx = context.Gcmf.TransformMatrices[context.TransformMatrixIdxs[rIdx]]; modelVtx.Position = tMtx.TransformPosition(modelVtx.Position); if (modelVtx.Normal != null) { modelVtx.Normal = tMtx.TransformNormal(modelVtx.Normal.Value); } } modelVertices[i] = modelVtx; } // Write triangle strip renderer.WriteTriangleStrip(modelVertices); }
/// <summary> /// This is the same as render(), but it skips the material setup step, /// so when rendering all triangle meshes, they only need to be set up once. /// </summary> internal void RenderInternal(IRenderer renderer, GcmfRenderContext context) { /* * if (Layer == GcmfTriangleMeshLayer.Layer1) * { * GL.Disable(EnableCap.Blend); * GL.DepthMask(true); * } * else * { * GL.DepthMask(false); * GL.Enable(EnableCap.Blend); * GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); * } */ // Set up the renderer according to the render flags set renderer.SetTwoSidedFaces((RenderFlags & RenderFlag.TwoSided) != 0); // Very rarely a mesh with a material id set to 0xFFFF ((ushort)-1) is seen. // I believe this is just a that it didn't have a material assigned. if (PrimaryMaterialIdx != ushort.MaxValue) { renderer.BindMaterial(PrimaryMaterialIdx); } else { renderer.UnbindMaterial(); } // Patch the non-null default transformation matrix indexes (for obj1) // with the specific indexes set for this mesh for (int i = 0; i < TransformMatrixSpecificIdxsObj1.Length; i++) { if (TransformMatrixSpecificIdxsObj1[i] != byte.MaxValue) { context.TransformMatrixIdxs[i] = TransformMatrixSpecificIdxsObj1[i]; } } renderer.SetFrontFaceDirection(FrontFaceDirection.Ccw); Obj1StripsCcw.Render(renderer, context); renderer.SetFrontFaceDirection(FrontFaceDirection.Cw); Obj1StripsCw.Render(renderer, context); // Patch the non-null default transformation matrix indexes (for obj2) // with the specific indexes set for this mesh for (int i = 0; i < TransformMatrixSpecificIdxsObj2.Length; i++) { if (TransformMatrixSpecificIdxsObj2[i] != byte.MaxValue) { context.TransformMatrixIdxs[i] = TransformMatrixSpecificIdxsObj2[i]; } } renderer.SetFrontFaceDirection(FrontFaceDirection.Ccw); Obj2StripsCcw.Render(renderer, context); renderer.SetFrontFaceDirection(FrontFaceDirection.Cw); Obj2StripsCw.Render(renderer, context); }