Esempio n. 1
0
        private SurfaceModelMesh AddMeshGeometry(ModelMeshReference modelMesh, List <int> indexList, List <VertVNT> vertexList)
        {
            var     geometry        = modelMesh.GetGeometry();
            int     indexOffset     = indexList.Count;
            int     vertexOffset    = vertexList.Count;
            var     triangleIndices = geometry.GetTriangleIndices();
            Vector3 minPos          = new Vector3(9999f);
            Vector3 maxPos          = new Vector3(-9999f);

            indexList.AddRange(triangleIndices);

            foreach (var vertex in geometry.Vertices)
            {
                var glVertex = new VertVNT()
                {
                    Position = vertex.Position.ToGL(),
                    Normal   = vertex.Normal.ToGL(),
                    TexCoord = geometry.IsTextured ? vertex.TexCoord.ToGL() : Vector2.Zero
                };

                minPos = Vector3.ComponentMin(minPos, glVertex.Position);
                maxPos = Vector3.ComponentMax(maxPos, glVertex.Position);
                vertexList.Add(glVertex);
            }

            var model = new SurfaceModelMesh(this, modelMesh, indexOffset, geometry.IndexCount, vertexOffset);

            model.BoundingBox = BBox.FromMinMax(minPos, maxPos);

            MeshModels.Add(model);
            return(model);
        }
Esempio n. 2
0
        private void SetVisibleModelMeshes(bool showLayer1, bool showLayer2)
        {
            foreach (TreeNode modelItem in treeModel.Nodes)
            {
                if (modelItem.Nodes.Count > 0)
                {
                    // Set model meshes check state
                    foreach (TreeNode meshItem in modelItem.Nodes)
                    {
                        ModelMeshReference meshData = (ModelMeshReference)meshItem.Tag;
                        GcmfMesh           mesh     = gma[meshData.ModelIdx].ModelObject.Meshes[meshData.MeshIdx];
                        if (mesh.Layer == GcmfMesh.MeshLayer.Layer1)
                        {
                            treeModel.SetCheckState(meshItem, showLayer1 ? CheckState.Checked : CheckState.Unchecked);
                        }
                        else if (mesh.Layer == GcmfMesh.MeshLayer.Layer2)
                        {
                            treeModel.SetCheckState(meshItem, showLayer2 ? CheckState.Checked : CheckState.Unchecked);
                        }
                    }
                }
                else
                {
                    // For the orphan nodes (models with no meshes, mostly GMA null entries),
                    // unselect them unless we're choosing to show both types of layers
                    treeModel.SetCheckState(modelItem, (showLayer1 && showLayer2) ? CheckState.Checked : CheckState.Unchecked);
                }
            }

            // The model will be updated due to the AfterCheckState event on treeModel
        }
Esempio n. 3
0
        private void UpdateModelDisplay()
        {
            // If no item is selected in the list, hide the display completely
            if (treeModel.SelectedNode == null)
            {
                tlpModelDisplay.Visible = false;
                tlpMeshDisplay.Visible  = false;
                return;
            }

            // Otherwise, extract the ModelTreeItem structure to get the selected model/mesh
            ModelMeshReference modelMeshReference = (ModelMeshReference)treeModel.SelectedNode.Tag;

            if (gma[modelMeshReference.ModelIdx] == null)
            {
                tlpModelDisplay.Visible = false;
                tlpMeshDisplay.Visible  = false;
                return;
            }
            Gcmf model = gma[modelMeshReference.ModelIdx].ModelObject;

            // Show information about the selected model/mesh
            if (modelMeshReference.MeshIdx == -1)
            {
                tlpModelDisplay.Visible = true;
                tlpMeshDisplay.Visible  = false;

                lblModelSectionFlags.Text = string.Format("0x{0:X8}", model.SectionFlags);
                lblModelCenter.Text       = model.BoundingSphereCenter.ToString();
                lblModelRadius.Text       = model.BoundingSphereRadius.ToString();
                lblModelTransformMatrixDefaultReferences.Text = string.Join(",",
                                                                            Array.ConvertAll(model.TransformMatrixDefaultIdxs, b => string.Format("0x{0:X2}", b)));
                lblModelNumTransformMatrices.Text = model.TransformMatrices.Count.ToString();
            }
            else
            {
                GcmfMesh mesh = model.Meshes[modelMeshReference.MeshIdx];

                tlpModelDisplay.Visible = false;
                tlpMeshDisplay.Visible  = true;

                lblMeshRenderFlags.Text          = string.Format("0x{0:X8} ({1})", (uint)mesh.RenderFlags, EnumUtils.GetEnumFlagsString(mesh.RenderFlags));
                lblMeshUnk4.Text                 = string.Format("0x{0:X8}", mesh.Unk4);
                lblMeshUnk8.Text                 = string.Format("0x{0:X8}", mesh.Unk8);
                lblMeshUnkC.Text                 = string.Format("0x{0:X8}", mesh.UnkC);
                lblMeshUnk10.Text                = string.Format("0x{0:X4}", mesh.Unk10);
                lblMeshUnk14.Text                = string.Format("0x{0:X4}", mesh.Unk14);
                lblMeshPrimaryMaterialIdx.Text   = mesh.PrimaryMaterialIdx.ToString();
                lblMeshSecondaryMaterialIdx.Text = mesh.SecondaryMaterialIdx.ToString();
                lblMeshTertiaryMaterialIdx.Text  = mesh.TertiaryMaterialIdx.ToString();
                lblMeshTransformMatrixSpecificReferences.Text = string.Join(",",
                                                                            Array.ConvertAll(mesh.TransformMatrixSpecificIdxsObj1, b => string.Format("0x{0:X2}", b)));
                lblMeshCenter.Text = mesh.BoundingSphereCenter.ToString();
                lblMeshUnk3C.Text  = mesh.Unk3C.ToString();
                lblMeshUnk40.Text  = string.Format("0x{0:X8}", mesh.Unk40);
            }
        }
Esempio n. 4
0
        public SurfaceModelMesh(SurfaceMeshBuffer baseModel, ModelMeshReference meshRef, int startIndex, int indexCount, int startVertex) : base(meshRef)
        {
            MeshReference = meshRef;
            SurfaceModel  = baseModel;
            StartIndex    = startIndex;
            IndexCount    = indexCount;
            StartVertex   = startVertex;

            var baseTransform = meshRef.Transform.ToMatrix().ToGL();

            SetTransform(baseTransform, false);
        }
Esempio n. 5
0
        int GetSelectedModelIdx()
        {
            // If no item is selected in the list, return -1
            if (treeModel.SelectedNode == null)
            {
                return(-1);
            }

            // Otherwise, extract the model/mesh reference structure and get the model index from there
            ModelMeshReference itemData = (ModelMeshReference)treeModel.SelectedNode.Tag;

            return(((ModelMeshReference)treeModel.SelectedNode.Tag).ModelIdx);
        }
Esempio n. 6
0
        protected override void DeserializeFemaleStudModel(FemaleStudModel femaleStudModel, XElement element)
        {
            DeserializePartCullingModel(femaleStudModel, element);

            if (element.HasElement(nameof(FemaleStudModel.ReplacementMeshes), out XElement geomElem))
            {
                foreach (var elem in geomElem.Elements(ModelMeshReference.NODE_NAME))
                {
                    var mesh = new ModelMeshReference();
                    mesh.LoadFromXml(elem);
                    femaleStudModel.ReplacementMeshes.Add(mesh);
                }
            }
        }
Esempio n. 7
0
        private void glControlModel_Paint(object sender, PaintEventArgs e)
        {
            // Reload the model if necessary
            if (reloadOnNextRedraw)
            {
                LoadModel();
                reloadOnNextRedraw = false;
            }

            // Set up OpenGL context
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.Translate(0.0f, 0.0f, -6.0f);
            GL.Rotate(angleY, 1.0f, 0.0f, 0.0f);
            GL.Rotate(angleX, 0.0f, 1.0f, 0.0f);
            GL.Scale(zoomFactor, zoomFactor, zoomFactor);

            // Draw the models/meshes
            foreach (TreeNode modelItem in treeModel.Nodes)
            {
                ModelMeshReference modelRef = (ModelMeshReference)modelItem.Tag;
                if (gma[modelRef.ModelIdx] != null)
                {
                    if (treeModel.GetCheckState(modelItem) == CheckState.Checked)
                    {
                        // Whole item is checked -> Call the display list corresponding to the entire model
                        ctx.CallDisplayList(modelObjects[modelRef.ModelIdx].Value);
                    }
                    else if (treeModel.GetCheckState(modelItem) == CheckState.Indeterminate)
                    {
                        // Only some meshes of the item are checked -> Call the display list corresponding to each mesh
                        foreach (TreeNode meshItem in modelItem.Nodes)
                        {
                            if (treeModel.GetCheckState(meshItem) == CheckState.Checked)
                            {
                                ModelMeshReference meshRef = (ModelMeshReference)meshItem.Tag;
                                ctx.CallDisplayList(modelObjects[meshRef.ModelIdx][meshRef.MeshIdx].Value);
                            }
                        }
                    }
                }
            }

            glControlModel.SwapBuffers();
        }
Esempio n. 8
0
        public override SurfaceComponent DeserializeSurfaceComponent(XElement element)
        {
            SurfaceComponent component = null;
            var componentType          = element.ReadAttribute <ModelComponentType>("Type");

            switch (componentType)
            {
            case ModelComponentType.Part:
                component = new PartModel();
                DeserializePartModel(component as PartModel, element);
                break;

            case ModelComponentType.MaleStud:
                component = new MaleStudModel();
                DeserializeMaleStudModel(component as MaleStudModel, element);
                break;

            case ModelComponentType.FemaleStud:
                component = new FemaleStudModel();
                DeserializeFemaleStudModel(component as FemaleStudModel, element);
                break;

            case ModelComponentType.BrickTube:
                component = new BrickTubeModel();
                DeserializeBrickTubeModel(component as BrickTubeModel, element);
                break;
            }

            if (element.HasElement(nameof(SurfaceComponent.Meshes), out XElement geomElem))
            {
                foreach (var elem in geomElem.Elements(ModelMeshReference.NODE_NAME))
                {
                    var mesh = new ModelMeshReference();
                    mesh.LoadFromXml(elem);
                    component.Meshes.Add(mesh);
                }
            }

            return(component);
        }