//-------------- #region D R A W //-------------- protected override void Draw(GameTime gameTime) { gpu.SetRenderTarget(MainTarget); gpu.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Transparent, 1.0f, 0); Set3DStates(); //hero[IDLE].Draw(cam, skinFx.world); // normal way // RENDER CHARACTER // specialized way SkinModel kid = hero[IDLE]; for (int i = 0; i < kid.meshes.Length; i++) { SkinModel.SkinMesh mesh = kid.meshes[i]; if (mesh.opacity < 0.6f) { continue; } skinFx.SetDiffuseCol(Color.White.ToVector4()); skinFx.SetSpecularCol(new Vector3(0.2f, 0.3f, 0.05f)); skinFx.SetSpecularPow(256f); skinFx.world = mtx_hero_rotate * Matrix.CreateTranslation(hero_pos); // ***MUST DO THIS BEFORE: SET DRAW PARAMS*** // (If we wanted, we could swap out a shirt or something by setting skinFx.texture = ...) // TO DO: set up a DrawMesh that takes a custom transforms list for animation blending kid.DrawMesh(i, cam, skinFx.world, false, false); } //RENDER SHINY TRANSPARENT STUFF(eyes ) skinFx.SetShineAmplify(100f); for (int i = 0; i < kid.meshes.Length; i++) { SkinModel.SkinMesh mesh = kid.meshes[i]; if (mesh.opacity >= 0.6f) { continue; } // Make adjustments for eyes: float oldAlpha = skinFx.alpha; skinFx.alpha = 0.2f; skinFx.SetDiffuseCol(Color.Blue.ToVector4()); skinFx.SetSpecularCol(new Vector3(100f, 100f, 100f)); // TO DO: custom DrawMesh that takes a custom blendTransform hero[IDLE].DrawMesh(i, cam, skinFx.world, false); skinFx.alpha = oldAlpha; } skinFx.SetShineAmplify(1f); // DRAW MAINTARGET TO BACKBUFFER ------------------------------------------------------------------------------------------------------- gpu.SetRenderTarget(null); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, SamplerState.LinearWrap, DepthStencilState.None, RasterizerState.CullNone); spriteBatch.Draw(MainTarget, desktopRect, Color.White); spriteBatch.End(); base.Draw(gameTime); }
private bool GetBoneForMesh(SkinModel.SkinMesh sMesh, string name, out SkinModel.ModelBone bone, out int boneIndexInMesh) { bool found = false; bone = null; boneIndexInMesh = 0; for (int j = 0; j < sMesh.meshBones.Length; j++) // loop thru the bones of the mesh { if (sMesh.meshBones[j].name == name) // found a bone whose name matches { found = true; bone = sMesh.meshBones[j]; // return the matching bone boneIndexInMesh = j; // return the index into the bone-list of the mesh } } return(found); }
// SHOW MESH BONE CREATION INFO public void ShowMeshBoneCreationInfo(Mesh assimpMesh, SkinModel.SkinMesh sMesh, bool MatrixInfo, int mi) { // If an imported model uses multiple materials, the import splits up the mesh. Use this value as index into the scene's material list. // http://sir-kimmi.de/assimp/lib_html/structai_mesh.html#aa2807c7ba172115203ed16047ad65f9e Console.Write("\n\n Name " + assimpMesh.Name + " scene.Mesh[" + mi + "] "); Console.Write("\n" + " assimpMesh.VertexCount: " + assimpMesh.VertexCount + " rmMesh.MaterialIndexName: " + sMesh.material_name + " Material index: " + sMesh.material_index + " (material associated to this mesh) " + " Bones.Count: " + assimpMesh.Bones.Count); Console.Write("\n" + " Note bone 0 doesn't exist in the original assimp bone data structure to facilitate a bone 0 for mesh node transforms so " + "that aibone[0] is converted to modelBone[1]"); for (int i = 0; i < sMesh.meshBones.Length; i++) { var bone = sMesh.meshBones[i]; Console.Write("\n Bone [" + i + "] Name " + bone.name + " meshIndex: " + bone.meshIndex + " meshBoneIndex: " + bone.boneIndex + " numberOfAssociatedWeightedVertices: " + bone.numWeightedVerts); if (MatrixInfo) { Console.Write("\n Offset: " + bone.offset_mtx); } } }