Exemplo n.º 1
0
        /// <summary>
        /// Generate the skinned packmesh information
        /// </summary>
        /// <param name="packmesh">Container of packmesh to generate</param>
        public void gerarModeloElastico(Packmesh packmesh)
        {
            if (packmesh.SkinInformation == null)
            {
                throw new ArgumentException();
            }

            int numInfl = 0;

            BoneCombination[] ossos;

            // Use ConvertToBlendedMesh to generate a drawable packmesh
            MeshData mesh_info = packmesh.MeshData;

            mesh_info.Mesh = packmesh.SkinInformation.ConvertToBlendedMesh(mesh_info.Mesh,
                                                                           MeshFlags.Managed | MeshFlags.OptimizeVertexCache,
                                                                           packmesh.GetAdjacencyStream(), out numInfl, out ossos);

            // Store this info
            packmesh.nInfluencias = numInfl;
            packmesh.SetBones(ossos);

            // Get the number of attributes
            packmesh.nAtributos = ossos.Length;

            packmesh.MeshData = mesh_info;
        }
Exemplo n.º 2
0
        } // Renderizar().fim

        /// <summary>
        /// Draw a quadro and all child and sibling frames
        /// </summary>
        /// <param name="quadro">Frame to draw</param>
        private void desenharQuadro(QuadroDerivado frame)
        {
            Packmesh mesh = (Packmesh)frame.MeshContainer;

            while (mesh != null)
            {
                desenharPackmesh(mesh, frame);

                mesh = (Packmesh)mesh.NextContainer;
            } // endwhile

            if (frame.FrameSibling != null)
            {
                desenharQuadro((QuadroDerivado)frame.FrameSibling);
            } // endif

            if (frame.FrameFirstChild != null)
            {
                desenharQuadro((QuadroDerivado)frame.FrameFirstChild);
            } // endif
        }     // desenharQuadro().fim
Exemplo n.º 3
0
        }     // ossos_ConfigurarMatrizes().fim

        /// <summary>
        /// Sets the bone matrices for a packmesh container
        /// </summary>
        private void ossos_ConfigurarMatrizes(Packmesh mesh)
        {
            // Is there skin information?  If so, setup the matrices
            if (mesh.SkinInformation != null)
            {
                int nOssos = mesh.SkinInformation.NumberBones;

                QuadroDerivado[] frameMatrices = new QuadroDerivado[nOssos];
                for (int i = 0; i < nOssos; i++)
                {
                    QuadroDerivado frame = (QuadroDerivado)Frame.Find(
                        quadroRaiz.FrameHierarchy,
                        mesh.SkinInformation.GetBoneName(i));

                    if (frame == null)
                    {
                        throw new ArgumentException();
                    }

                    frameMatrices[i] = frame;
                } // endfor
                mesh.SetFrames(frameMatrices);
            }     // endif
        }         // ossos_ConfigurarMatrizes().fim
Exemplo n.º 4
0
        /// <summary>
        /// Create a new packmesh container
        /// </summary>
        /// <returns>The newly created container</returns>
        ///
        public override MeshContainer CreateMeshContainer(string name,
                                                          MeshData meshData, ExtendedMaterial[] materials,
                                                          EffectInstance effectInstances, GraphicsStream adjacency,
                                                          SkinInformation skinInfo)
        {
            // We only handle meshes here
            if (meshData.Mesh == null)
            {
                throw new ArgumentException();
            }

            // We must have a vertex format packmesh
            if (meshData.Mesh.VertexFormat == VertexFormats.None)
            {
                throw new ArgumentException();
            }

            Packmesh packmesh = new Packmesh();

            packmesh.Name = name;
            int    numFaces = meshData.Mesh.NumberFaces;
            Device dev      = meshData.Mesh.Device;

            // Make sure there are normals
            if ((meshData.Mesh.VertexFormat & VertexFormats.Normal) == 0)
            {
                // Clone the packmesh
                Mesh tempMesh = meshData.Mesh.Clone(meshData.Mesh.Options.Value,
                                                    meshData.Mesh.VertexFormat | VertexFormats.Normal, dev);

                meshData.Mesh = tempMesh;
                meshData.Mesh.ComputeNormals();
            }

            // Store the materials
            packmesh.SetMaterials(materials);
            packmesh.SetAdjacency(adjacency);
            Texture[] texturas = new Texture[materials.Length];

            // Create any textures
            for (int i = 0; i < materials.Length; i++)
            {
                if (materials[i].TextureFilename != null)
                {
                    texturas[i] = TextureLoader.FromFile(dev, @"..\..\" +
                                                         materials[i].TextureFilename);
                }
            }
            packmesh.SetTextures(texturas);
            packmesh.MeshData = meshData;

            // If there is skinning info, save any required data
            if (skinInfo != null)
            {
                packmesh.SkinInformation = skinInfo;
                int      nOssos         = skinInfo.NumberBones;
                Matrix[] offsetMatrices = new Matrix[nOssos];

                for (int i = 0; i < nOssos; i++)
                {
                    offsetMatrices[i] = skinInfo.GetBoneOffsetMatrix(i);
                }

                packmesh.SetOffsetMatrices(offsetMatrices);

                app.gerarModeloElastico(packmesh);
            }

            return(packmesh);
        }
Exemplo n.º 5
0
        }     // desenharQuadro().fim

        /// <summary>
        /// Draw a meshcontainer
        /// </summary>
        /// <param name="packmesh">Mesh container to draw</param>
        /// <param name="quadro">Parent quadro of this container</param>
        private void desenharPackmesh(Packmesh mesh, QuadroDerivado frame)
        {
            // Is there skin information?
            if (mesh.SkinInformation != null)
            {
                int attribIdPrev = -1;

                // Draw
                for (int iattrib = 0; iattrib < mesh.nAtributos; iattrib++)
                {
                    int numBlend            = 0;
                    BoneCombination[] bones = mesh.GetBones();
                    for (int i = 0; i < mesh.nInfluencias; i++)
                    {
                        if (bones[iattrib].BoneId[i] != -1)
                        {
                            numBlend = i;
                        } // endif
                    }     // endfor

                    if (device.DeviceCaps.MaxVertexBlendMatrices >= numBlend + 1)
                    {
                        // first calculate the world matrices for the current set of
                        // blend weights and get the accurate count of the number of
                        // blends
                        Matrix[]         offsetMatrices = mesh.GetOffsetMatrices();
                        QuadroDerivado[] frameMatrices  = mesh.GetFrames();
                        for (int i = 0; i < mesh.nInfluencias; i++)
                        {
                            int matrixIndex = bones[iattrib].BoneId[i];
                            if (matrixIndex != -1)
                            {
                                Matrix tempMatrix = offsetMatrices[matrixIndex] *
                                                    frameMatrices[matrixIndex].CombinedTransformationMatrix;

                                device.Transform.SetWorldMatrixByIndex(i, tempMatrix);
                            } // endif
                        }     // endfor

                        device.RenderState.VertexBlend = (VertexBlend)numBlend;
                        // lookup the material used for this subset of faces
                        if ((attribIdPrev != bones[iattrib].AttribId) ||
                            (attribIdPrev == -1))
                        {
                            device.Material = mesh.GetMaterials()[
                                bones[iattrib].AttribId].Material3D;

                            device.SetTexture(0, mesh.GetTextures()[
                                                  bones[iattrib].AttribId]);

                            attribIdPrev = bones[iattrib].AttribId;
                        }// endif

                        mesh.MeshData.Mesh.DrawSubset(iattrib);
                    }
                }
            }    // endif
            else // standard packmesh, just draw it after setting material properties
            {
                device.Transform.World = frame.CombinedTransformationMatrix;

                ExtendedMaterial[] mtrl = mesh.GetMaterials();
                for (int iMaterial = 0; iMaterial < mtrl.Length; iMaterial++)
                {
                    device.Material = mtrl[iMaterial].Material3D;
                    device.SetTexture(0, mesh.GetTextures()[iMaterial]);
                    mesh.MeshData.Mesh.DrawSubset(iMaterial);
                } // endfor
            }     // endelse
        }         // desenharPackmesh().fim