public H3DMaterialWrapper(BCH bch, H3DModelWrapper model, H3DMaterial mat) : base() { ParentModel = model; ParentBCH = bch; Material = mat; ImageKey = "material"; SelectedImageKey = "material"; ReloadMaterial(); }
private void AddNodeGroup <T>(H3DDict <T> SubSections, BCHGroupNode Folder) where T : SPICA.Formats.Common.INamed { if (SubSections == null || SubSections.Count == 0) { return; } Nodes.Add(Folder); if (Folder.Type == BCHGroupType.Textures) { PluginRuntime.bchTexContainers.Add(Folder); } for (int i = 0; i < SubSections?.Count; i++) { var section = SubSections[i] as SPICA.Formats.Common.INamed; switch (Folder.Type) { case BCHGroupType.Models: var CMDLWrapper = new H3DModelWrapper((H3DModel)section, this); Folder.AddNode(CMDLWrapper); break; case BCHGroupType.SkeletalAnim: var CSKAWrapper = new H3DSkeletalAnimWrapper((H3DAnimation)section, this); Folder.AddNode(CSKAWrapper); break; case BCHGroupType.Textures: { var wrapper = new H3DTextureWrapper((H3DTexture)section, this); wrapper.ImageKey = "texture"; wrapper.SelectedImageKey = "texture"; Folder.AddNode(wrapper); Textures.Add(wrapper); } break; default: Folder.AddNode(new Toolbox.Library.NodeWrappers.STGenericWrapper(SubSections[i].Name)); break; } } }
public H3DMeshWrapper(BCH bch, H3DModelWrapper parentModel, H3DMesh mesh) : base() { ParentBCH = bch; ParentModel = parentModel; Mesh = mesh; ImageKey = "mesh"; SelectedImageKey = "mesh"; MaterialIndex = Mesh.MaterialIndex; foreach (var subMesh in mesh.SubMeshes) { STGenericPolygonGroup group = new STGenericPolygonGroup(); for (int i = 0; i < subMesh.Indices.Length; i++) { group.faces.Add(subMesh.Indices[i]); } group.PrimativeType = STPrimitiveType.Triangles; /* switch (subMesh.PrimitiveMode) * { * case SPICA.PICA.Commands.PICAPrimitiveMode.Triangles: * group.PrimativeType = STPrimitiveType.Triangles; * break; * case SPICA.PICA.Commands.PICAPrimitiveMode.TriangleStrip: * group.PrimativeType = STPrimitiveType.TrangleStrips; * break; * }*/ PolygonGroups.Add(group); } var vertices = mesh.GetVertices(); List <ushort> boneIndices = new List <ushort>(); foreach (var subMesh in mesh.SubMeshes) { if (subMesh.BoneIndicesCount > 0) { boneIndices.AddRange(subMesh.BoneIndices.ToArray()); } } for (int v = 0; v < vertices.Length; v++) { Vertex vertex = new Vertex(); vertex.pos = ConvertVector3(vertices[v].Position); vertex.nrm = ConvertVector3(vertices[v].Normal); vertex.tan = ConvertVector4(vertices[v].Tangent); vertex.uv0 = ConvertVector2(vertices[v].TexCoord0); vertex.uv1 = ConvertVector2(vertices[v].TexCoord1); vertex.uv2 = ConvertVector2(vertices[v].TexCoord2); vertex.col = ConvertVector4(vertices[v].Color); //Flip UVs vertex.uv0 = new Vector2(vertex.uv0.X, 1 - vertex.uv0.Y); if (boneIndices.Count > 0) { /* if (vertices[v].Indices.b0 != -1) vertex.boneIds.Add(boneIndices[vertices[v].Indices.b0]); * if (vertices[v].Indices.b1 != -1) vertex.boneIds.Add(boneIndices[vertices[v].Indices.b1]); * if (vertices[v].Indices.b2 != -1) vertex.boneIds.Add(boneIndices[vertices[v].Indices.b2]); * if (vertices[v].Indices.b3 != -1) vertex.boneIds.Add(boneIndices[vertices[v].Indices.b3]);*/ if (mesh.Skinning == H3DMeshSkinning.Rigid) { int index = boneIndices[vertices[v].Indices.b0]; vertex.pos = Vector3.TransformPosition(vertex.pos, parentModel.Skeleton.Renderable.bones[index].Transform); // vertex.nrm = Vector3.TransformNormal(vertex.nrm, parentModel.Skeleton.Renderable.bones[index].Transform); } /* vertex.boneWeights.Add(vertices[v].Weights.w0); * vertex.boneWeights.Add(vertices[v].Weights.w1); * vertex.boneWeights.Add(vertices[v].Weights.w2); * vertex.boneWeights.Add(vertices[v].Weights.w3);*/ } this.vertices.Add(vertex); } }