Exemplo n.º 1
0
        public static ModelBoneHierarchy CreateDefault()
        {
            var bones = new ModelBone[1];

            bones[0] = new ModelBone(0, null, null, Vector3.Zero, Quaternion.Identity);
            return(new ModelBoneHierarchy("[Default]", bones));
        }
Exemplo n.º 2
0
 internal override void BuildRenderList(
     RenderList renderList,
     Camera camera,
     ModelInstance modelInstance,
     ModelMeshInstance modelMeshInstance,
     ModelBone parentBone,
     in Matrix4x4 modelTransform,
Exemplo n.º 3
0
 internal override void BuildRenderList(
     RenderList renderList,
     Camera camera,
     ModelInstance modelInstance,
     BeforeRenderDelegate[] beforeRender,
     BeforeRenderDelegate[] beforeRenderDepth,
     ModelBone parentBone,
     in Matrix4x4 modelTransform,
Exemplo n.º 4
0
        internal ModelBoneInstance(ModelBone modelBone)
        {
            _modelBone = modelBone;

            AnimatedOffset = Transform.CreateIdentity();

            Visible = true;
        }
Exemplo n.º 5
0
        internal ModelSubObject(string fullName, string name, ModelBone bone, ModelRenderObject renderObject)
        {
            FullName     = fullName;
            Name         = name;
            Bone         = bone;
            RenderObject = renderObject;

            RenderObject.SubObject = this;
        }
Exemplo n.º 6
0
        public ModelMesh(
            GraphicsDevice graphicsDevice,
            string name,
            MeshVertex.Basic[] vertices,
            ushort[] indices,
            Effect effect,
            ModelMeshMaterialPass[] materialPasses,
            bool isSkinned,
            ModelBone parentBone,
            uint numBones,
            BoundingBox boundingBox,
            bool hidden,
            bool cameraOriented)
        {
            Name = name;

            ParentBone = parentBone;
            NumBones   = numBones;

            BoundingBox = boundingBox;

            Skinned = isSkinned;

            Hidden         = hidden;
            CameraOriented = cameraOriented;

            _effect = effect;

            _vertexBuffer = AddDisposable(Buffer <MeshVertex.Basic> .CreateStatic(
                                              graphicsDevice,
                                              vertices,
                                              BufferBindFlags.VertexBuffer));

            _indexBuffer = AddDisposable(Buffer <ushort> .CreateStatic(
                                             graphicsDevice,
                                             indices,
                                             BufferBindFlags.IndexBuffer));

            _meshConstantsBuffer = AddDisposable(new ConstantBuffer <MeshMaterial.MeshConstants>(graphicsDevice));
            _meshConstantsBuffer.Value.SkinningEnabled = isSkinned;
            _meshConstantsBuffer.Value.NumBones        = numBones;
            _meshConstantsBuffer.Update();

            foreach (var materialPass in materialPasses)
            {
                AddDisposable(materialPass);

                foreach (var meshPart in materialPass.MeshParts)
                {
                    meshPart.Material.SetMeshConstants(_meshConstantsBuffer.Buffer);
                }
            }
            MaterialPasses = materialPasses;
        }
Exemplo n.º 7
0
        public ModelMesh(
            GraphicsDevice graphicsDevice,
            ResourceUploadBatch uploadBatch,
            string name,
            MeshVertex[] vertices,
            ushort[] indices,
            VertexMaterial[] vertexMaterials,
            Texture[] textures,
            ModelMeshMaterialPass[] materialPasses,
            bool isSkinned,
            ModelBone parentBone,
            uint numBones,
            BoundingBox boundingBox)
        {
            Name = name;

            ParentBone = parentBone;
            NumBones   = numBones;

            BoundingBox = boundingBox;

            Skinned = isSkinned;

            _vertexBuffer = AddDisposable(StaticBuffer.Create(
                                              graphicsDevice,
                                              uploadBatch,
                                              vertices));

            _indexBuffer = AddDisposable(StaticBuffer.Create(
                                             graphicsDevice,
                                             uploadBatch,
                                             indices));

            _materialsBuffer = AddDisposable(StaticBuffer.Create(
                                                 graphicsDevice,
                                                 uploadBatch,
                                                 vertexMaterials));

            _textures = AddDisposable(new TextureSet(graphicsDevice, textures));

            foreach (var materialPass in materialPasses)
            {
                AddDisposable(materialPass);
            }
            MaterialPasses = materialPasses;
        }
Exemplo n.º 8
0
        internal ModelBoneHierarchy(W3dHierarchyDef w3dHierarchy)
        {
            SetNameAndInstanceId("W3DHierarchy", w3dHierarchy.Header.Name);

            Bones = new ModelBone[w3dHierarchy.Pivots.Items.Count];

            for (var i = 0; i < w3dHierarchy.Pivots.Items.Count; i++)
            {
                var pivot = w3dHierarchy.Pivots.Items[i];

                var parent = pivot.ParentIdx == -1
                    ? null
                    : Bones[pivot.ParentIdx];

                Bones[i] = new ModelBone(
                    i,
                    pivot.Name,
                    parent,
                    pivot.Translation,
                    pivot.Rotation);
            }
        }
Exemplo n.º 9
0
        internal static ModelBoneHierarchy ParseAsset(BinaryReader reader, Asset asset)
        {
            var w3xHierarchy = W3xHierarchy.Parse(reader, asset.Header);

            var bones = new ModelBone[w3xHierarchy.Pivots.Length];

            for (var i = 0; i < w3xHierarchy.Pivots.Length; i++)
            {
                var w3xPivot = w3xHierarchy.Pivots[i];

                bones[i] = new ModelBone(
                    i,
                    w3xPivot.Name,
                    w3xPivot.ParentIdx != -1
                        ? bones[w3xPivot.ParentIdx]
                        : null,
                    w3xPivot.Translation,
                    w3xPivot.Rotation);
            }

            return(new ModelBoneHierarchy(asset, bones));
        }
Exemplo n.º 10
0
 internal ModelSubObject(string fullName, ModelBone bone, ModelRenderObject renderObject)
     : this(fullName, fullName.Substring(fullName.IndexOf('.') + 1), bone, renderObject)
 {
 }
Exemplo n.º 11
0
        internal ModelMesh(
            GraphicsDevice graphicsDevice,
            string name,
            MeshVertex.Basic[] vertices,
            ushort[] indices,
            Effect effect,
            ModelMeshMaterialPass[] materialPasses,
            bool isSkinned,
            ModelBone parentBone,
            uint numBones,
            BoundingBox boundingBox,
            bool hidden,
            bool cameraOriented)
        {
            Name = name;

            ParentBone = parentBone;
            NumBones   = numBones;

            BoundingBox = boundingBox;

            Skinned = isSkinned;

            Hidden         = hidden;
            CameraOriented = cameraOriented;

            _effect = effect;

            _vertexBuffer = AddDisposable(graphicsDevice.CreateStaticBuffer(
                                              vertices,
                                              BufferUsage.VertexBuffer));

            _indexBuffer = AddDisposable(graphicsDevice.CreateStaticBuffer(
                                             indices,
                                             BufferUsage.IndexBuffer));

            var commandEncoder = graphicsDevice.ResourceFactory.CreateCommandList();

            commandEncoder.Begin();

            _meshConstantsBuffer = AddDisposable(new ConstantBuffer <MeshMaterial.MeshConstants>(graphicsDevice));
            _meshConstantsBuffer.Value.SkinningEnabled = isSkinned;
            _meshConstantsBuffer.Value.NumBones        = numBones;
            _meshConstantsBuffer.Update(commandEncoder);

            commandEncoder.End();

            graphicsDevice.SubmitCommands(commandEncoder);

            graphicsDevice.DisposeWhenIdle(commandEncoder);

            foreach (var materialPass in materialPasses)
            {
                AddDisposable(materialPass);

                foreach (var meshPart in materialPass.MeshParts)
                {
                    AddDisposable(meshPart.Material);
                    meshPart.Material.SetMeshConstants(_meshConstantsBuffer.Buffer);
                }
            }
            MaterialPasses = materialPasses;
        }
Exemplo n.º 12
0
 internal ModelBone(int index, string name, ModelBone parent, in Vector3 translation, in Quaternion rotation)
Exemplo n.º 13
0
 internal ModelSubObject(string name, ModelBone bone, ModelMesh renderObject)
 {
     Name         = name;
     Bone         = bone;
     RenderObject = renderObject;
 }