Exemplo n.º 1
0
        public void Load(H3DModel model, BCH bch)
        {
            Renderable = new STSkeleton();
            bch.DrawableContainer.Drawables.Add(Renderable);

            BcresParent = bch;
            ModelParent = model;

            Text    = "Skeleton";
            Checked = true;

            foreach (var bone in model.Skeleton)
            {
                Renderable.bones.Add(new H3DBoneWrapper(Renderable, bone, bch));
            }

            Nodes.Clear();
            foreach (var bone in Renderable.bones)
            {
                if (bone.Parent == null)
                {
                    Nodes.Add(bone);
                }
            }

            Renderable.update();
            Renderable.reset();
        }
Exemplo n.º 2
0
        public H3DMaterialWrapper(BCH bch, H3DModelWrapper model, H3DMaterial mat) : base()
        {
            ParentModel = model;
            ParentBCH   = bch;
            Material    = mat;

            ImageKey         = "material";
            SelectedImageKey = "material";

            ReloadMaterial();
        }
Exemplo n.º 3
0
        public void LoadModel(H3DModel model, BCH bch)
        {
            BchParent = bch;

            ImageKey         = "model";
            SelectedImageKey = "model";

            Model = model;
            Text  = model.Name;

            var MaterialFolder = new TreeNode("Materials");
            var MeshFolder     = new TreeNode("Meshes");

            Skeleton      = new H3DSkeletonWrapper();
            Skeleton.Text = "Skeleton";
            Checked       = true;

            Nodes.Add(MeshFolder);
            Nodes.Add(MaterialFolder);
            Nodes.Add(Skeleton);

            if (model.Skeleton != null)
            {
                Skeleton.Load(model, bch);
            }

            int Index = 0;

            foreach (var material in model.Materials)
            {
                var matWrapper = new H3DMaterialWrapper(bch, this, material);
                matWrapper.Text = material.Name;
                MaterialFolder.Nodes.Add(matWrapper);
                Materials.Add(matWrapper);
            }

            Index = 0;
            foreach (var mesh in model.Meshes)
            {
                var meshWrapper = new H3DMeshWrapper(bch, this, mesh);

                MeshFolder.Nodes.Add(meshWrapper);
                bch.Renderer.Meshes.Add(meshWrapper);

                if (meshWrapper.Text == string.Empty)
                {
                    meshWrapper.Text = $"mesh_{model.Materials[mesh.MaterialIndex].Name}";
                }
                Meshes.Add(meshWrapper);
            }
        }
        public H3DSkeletalAnimWrapper(H3DAnimation h3dAnim, BCH bch)
        {
            ImageKey         = "anim";
            SelectedImageKey = "anim";

            BCHParent = bch;
            Text      = h3dAnim.Name;

            H3DAnimation         = h3dAnim;
            Animation.FrameCount = h3dAnim.FramesCount;
            Animation.Name       = h3dAnim.Name;
            Animation.Loop       = h3dAnim.AnimationFlags.HasFlag(H3DAnimationFlags.IsLooping);
            foreach (var bone in h3dAnim.Elements)
            {
                Animation.AnimGroups.Add(new H3DBoneAnimGroup(bone));
            }
        }
Exemplo n.º 5
0
        public void Load(H3DBone bone, BCH bch)
        {
            BchParent = bch;
            Checked   = true;

            Bone = bone;
            Text = bone.Name;

            parentIndex  = bone.ParentIndex;
            RotationType = BoneRotationType.Euler;
            Position     = new OpenTK.Vector3(
                bone.Translation.X,
                bone.Translation.Y,
                bone.Translation.Z);
            EulerRotation = new OpenTK.Vector3(
                bone.Rotation.X,
                bone.Rotation.Y,
                bone.Rotation.Z);
            Scale = new OpenTK.Vector3(
                bone.Scale.X,
                bone.Scale.Y,
                bone.Scale.Z);
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
 public H3DTextureWrapper(H3DTexture texture, BCH bch) : base()
 {
     BchParent = bch;
     LoadTexture(texture);
 }
Exemplo n.º 8
0
 public H3DBoneWrapper(STSkeleton skeleton, H3DBone bone, BCH bch) : base(skeleton)
 {
     BchParent = bch;
     Load(bone, bch);
 }
Exemplo n.º 9
0
 public H3DModelWrapper(H3DModel model, BCH bch) : base()
 {
     BchParent = bch;
     LoadModel(model, bch);
 }
Exemplo n.º 10
0
 public H3DSkeletonWrapper(H3DModel model, BCH bch) : base()
 {
     BcresParent = bch;
     Load(model, bch);
 }