public void Draw(BaseCamera camera) { if (Active) { if (HitTest) { world = lastWorld; } // Copy any parent transforms. // Draw the model. A model can have multiple meshes, so loop. for (int meshIndex = 0; meshIndex < mesh.Meshes.Count; meshIndex++) { meshM = mesh.Meshes[meshIndex]; // This is where the mesh orientation is set, as well // as our camera and projection. foreach (BasicEffect effect in meshM.Effects) { effect.EnableDefaultLighting(); if (elementsWorldMatrix.Length == 0) { effect.World = transforms[meshM.ParentBone.Index] * world; } else { effect.World = transforms[meshM.ParentBone.Index] * elementsWorldMatrix[meshIndex] * world; } effect.View = camera.GetViewMatrix(); effect.Projection = camera.GetProjectionMatrix(); } // Draw the mesh, using the effects set above. meshM.Draw(); } } }
public void Draw(BasicEffect effect, GameTime gametime) { List <ulong> models = ComponentManager.GetAllEntitiesWithComp <ModelComponent>(); foreach (ulong mC in models) { ModelComponent m = ComponentManager.GetComponent <ModelComponent>(mC); CameraComponent camera = ComponentManager.GetComponent <CameraComponent>(mC); TransformComponent transform = ComponentManager.GetComponent <TransformComponent>(mC); Matrix[] transforms = new Matrix[m.model.Bones.Count]; Matrix worldMatrix = Matrix.CreateScale(0.05f, 0.05f, 0.05f) * Matrix.CreateFromQuaternion(transform.qRot) * Matrix.CreateTranslation(transform.position); m.model.CopyAbsoluteBoneTransformsTo(transforms); for (int index = 0; index < m.model.Meshes.Count; index++) { ModelMesh mesh = m.model.Meshes[index]; foreach (BasicEffect be in mesh.Effects) { be.EnableDefaultLighting(); be.PreferPerPixelLighting = true; be.World = mesh.ParentBone.Transform * m.chopperMeshWorldMatrices[index] * worldMatrix; be.View = camera.viewMatrix; be.Projection = camera.projectionMatrix; } mesh.Draw(); } } }
public static void DrawModelMesh(this Model model, ModelMesh mesh) { Matrix mat = Matrix.Identity; GetModelMeshTransform(mesh.ParentBone, ref mat); Matrix View = Utility.Camera.View; Matrix Projection = Utility.Camera.Projection; for (int x = 0; x < mesh.Effects.Count; x++) { BasicEffect eff = mesh.Effects[x] as BasicEffect; if (eff != null) { eff.World = mat; eff.View = View; eff.Projection = Projection; eff.LightingEnabled = true; eff.EnableDefaultLighting(); eff.TextureEnabled = true; eff.VertexColorEnabled = true; } } mesh.Draw(); }
public static void ExtractModelMeshPartData(ModelMesh mm, ModelMeshPart mmp, ref Matrix xform, List <Vector3> vertices, List <TriangleVertexIndices> indices, string name) { int offset = vertices.Count; Vector3[] a = new Vector3[mmp.NumVertices]; mm.VertexBuffer.GetData <Vector3>(mmp.StreamOffset + mmp.BaseVertex * mmp.VertexStride, a, 0, mmp.NumVertices, mmp.VertexStride); for (int i = 0; i != a.Length; ++i) { Vector3.Transform(ref a[i], ref xform, out a[i]); } vertices.AddRange(a); if (mm.IndexBuffer.IndexElementSize != IndexElementSize.SixteenBits) { throw new Exception( String.Format("Model {0} uses 32-bit indices, which are not supported.", name)); } short[] s = new short[mmp.PrimitiveCount * 3]; mm.IndexBuffer.GetData <short>(mmp.StartIndex * 2, s, 0, mmp.PrimitiveCount * 3); TriangleVertexIndices[] tvi = new TriangleVertexIndices[mmp.PrimitiveCount]; for (int i = 0; i != tvi.Length; ++i) { tvi[i].I0 = s[i * 3 + 0] + offset; tvi[i].I1 = s[i * 3 + 1] + offset; tvi[i].I2 = s[i * 3 + 2] + offset; } indices.AddRange(tvi); }
public override void OnEndDrawMesh(GraphicsDevice graphicsDevice, ModelMesh mesh, Matrix bone, Matrix view, Matrix projection) { if (!Active) { return; } BoundingBoxBuffers boundingBoxBuffers = mesh.Tag as BoundingBoxBuffers; if (boundingBoxBuffers == null) { return; } graphicsDevice.SetVertexBuffer(boundingBoxBuffers.Vertices); graphicsDevice.Indices = boundingBoxBuffers.Indices; _lineEffect.World = bone; _lineEffect.View = view; _lineEffect.Projection = projection; foreach (EffectPass pass in _lineEffect.CurrentTechnique.Passes) { pass.Apply(); graphicsDevice.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, boundingBoxBuffers.VertexCount, 0, boundingBoxBuffers.PrimitiveCount); } }
/// <summary> /// Create the mesh renderer component. /// </summary> /// <param name="model">Path of the model asset to draw.</param> /// <param name="meshName">Which mesh to draw from model.</param> public ModelMeshRenderer(string model, string meshName) { Model modelInstance = Resources.GetModel(model); ModelMesh mesh = modelInstance.Meshes[meshName]; _entity = new Core.Graphics.MeshEntity(modelInstance, mesh); }
private void DrawMeshShadow(Matrix transform, ModelMesh mesh, float alpha) { // Store original effects for mesh parts, before substituting them for shadow rendering var originalEffects = new Dictionary <ModelMeshPart, Effect>(); foreach (ModelMeshPart part in mesh.MeshParts) { originalEffects[part] = part.Effect; part.Effect = _basicEffect; } foreach (BasicEffect effect in mesh.Effects) { effect.AmbientLightColor = Vector3.Zero; effect.Alpha = alpha; effect.DirectionalLight0.Enabled = false; effect.DirectionalLight1.Enabled = false; effect.DirectionalLight2.Enabled = false; // effect.View = _basicEffect.View; // effect.Projection = _basicEffect.Projection; effect.World = transform * _shadowTransform; } mesh.Draw(); // Restore former effects for mesh parts foreach (ModelMeshPart part in mesh.MeshParts) { part.Effect = originalEffects[part]; } }
public static Model toModel(VertexBuffer vb, IndexBuffer ib, Effect effect, GraphicsDevice gd) { ModelMeshPart meshPart = new ModelMeshPart(); meshPart.IndexBuffer = ib; //meshPart.Effect = effect;//>>1 meshPart.NumVertices = vb.VertexCount; //meshPart.PrimitiveCount = vb.VertexCount / 3; meshPart.PrimitiveCount = ib.IndexCount / 3; meshPart.StartIndex = 0; meshPart.VertexBuffer = vb; meshPart.VertexOffset = 0; ModelMesh modelMesh = new ModelMesh(gd, new ModelMeshPart[] { meshPart }.ToList()); meshPart.Effect = effect;//1 List <ModelBone> bones = new List <ModelBone>(); bones.Add(new ModelBone() { Transform = Matrix.Identity }); // modelMesh.ParentBone = bones[0]; Model returnval = new Model(gd, bones, new ModelMesh[] { modelMesh }.ToList()); return(returnval); }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Leds"); ModelMesh modelMesh = model.FindMesh("Led"); ModelMesh modelMesh2 = model.FindMesh("LedBulb"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(modelMesh.ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(modelMesh2.ParentBone); for (int i = 0; i < 8; i++) { Color color = LedColors[i]; color *= 0.5f; color.A = byte.MaxValue; Matrix m = Matrix.CreateRotationY(-(float)Math.PI / 2f) * Matrix.CreateRotationZ((float)Math.PI / 2f); m_standaloneBlockMeshesByColor[i] = new BlockMesh(); m_standaloneBlockMeshesByColor[i].AppendModelMeshPart(modelMesh.MeshParts[0], boneAbsoluteTransform * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_standaloneBlockMeshesByColor[i].AppendModelMeshPart(modelMesh2.MeshParts[0], boneAbsoluteTransform2 * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, color); for (int j = 0; j < 6; j++) { int num = SetMountingFace(SetColor(0, i), j); Matrix m2 = (j >= 4) ? ((j != 4) ? (Matrix.CreateRotationX((float)Math.PI) * Matrix.CreateTranslation(0.5f, 1f, 0.5f)) : Matrix.CreateTranslation(0.5f, 0f, 0.5f)) : (Matrix.CreateRotationX((float)Math.PI / 2f) * Matrix.CreateTranslation(0f, 0f, -0.5f) * Matrix.CreateRotationY((float)j * (float)Math.PI / 2f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f)); m_blockMeshesByData[num] = new BlockMesh(); m_blockMeshesByData[num].AppendModelMeshPart(modelMesh.MeshParts[0], boneAbsoluteTransform * m2, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_blockMeshesByData[num].AppendModelMeshPart(modelMesh2.MeshParts[0], boneAbsoluteTransform2 * m2, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, color); m_collisionBoxesByData[num] = new BoundingBox[1] { m_blockMeshesByData[num].CalculateBoundingBox() }; } } }
public void AddMesh(ModelMesh mesh) { _meshes.Add(new Mesh() { ModelMesh = mesh, InitialTransform = mesh.ParentBone.Transform }); }
/// <summary> /// Creates the bounding box for the model. This should only be called during model /// initialization, as it is much too slow to be used during runtime, or each frame for each model. /// </summary> public BoundingBox GetBoundingBox(Model model, ref Matrix[] BoneTransforms) { BoundingBox tempBox = new BoundingBox(); for (int i = 0; i < model.Meshes.Count; i++) { ModelMesh mesh = model.Meshes[i]; VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[mesh.VertexBuffer.SizeInBytes / VertexPositionNormalTexture.SizeInBytes]; mesh.VertexBuffer.GetData <VertexPositionNormalTexture>(vertices); Vector3[] vertexs = new Vector3[vertices.Length]; for (int k = 0; k < vertexs.Length; k++) { vertexs[k] = Vector3.Transform(vertices[k].Position, BoneTransforms[mesh.ParentBone.Index]);// * WorldMatrix); } BoundingBox b = BoundingBox.CreateFromPoints(vertexs); if (i == 0) { tempBox = b; } else { tempBox = BoundingBox.CreateMerged(tempBox, b); } } return(tempBox); }
public static ModelMesh SetupEffects(this ModelMesh mesh, Matrix world, Matrix view, Matrix projection ) { foreach (var meshPart in mesh.MeshParts) { if (meshPart.Effect is BasicEffect) { ((BasicEffect)meshPart.Effect) .SetWorld(world) .SetView(view) .SetProjection(projection) .EnableDefaultLighting(); } else { var effect = meshPart.Effect; effect.CurrentTechnique = effect.Techniques["Technique1"]; effect.Parameters["World"].SetValue(world); effect.Parameters["View"].SetValue(view); effect.Parameters["Projection"].SetValue(projection); } } return(mesh); }
/// <summary> /// Get all the triangles from all mesh parts /// </summary> private static void ExtractModelMeshData(ModelMesh mesh, ref Matrix transform, List <Vector3> vertices, List <Triangle> indices) { foreach (ModelMeshPart meshPart in mesh.MeshParts) { ExtractModelMeshPartData(meshPart, ref transform, vertices, indices); } }
public MeshRenderObj(ModelMesh mesh, List <PartInfo> listPartInfo) { this.mesh = mesh; this.listPartInfo = listPartInfo; meshTransform = mesh.ParentBone.Transform; ModelBone parentBone = mesh.ParentBone.Parent; // ignore the root bone as it has an invalid/strange transform // also ignore the first child of the root as that transform will be // applied at render and represents a changeable/default value while (parentBone != null && parentBone.Parent != null && parentBone.Parent.Parent != null) { meshTransform = meshTransform * parentBone.Transform; parentBone = parentBone.Parent; } /* * UIMeshData data = mesh.Tag as UIMeshData; * if (data != null) * { * System.Diagnostics.Debug.WriteLine("Got BBox min " + data.bBox.Min + " max " + data.bBox.Max + " Object: " + mesh.Name); * } * * // output the results * ModelHelper.DebugOutTransform(mesh.ParentBone.Name, meshTransform); */ }
public void MeshLoads() { Settings.initializeSettings(); String meshERFPath = "E:\\Program Files (x86)\\Steam\\steamapps\\common\\dragon age origins\\packages\\core\\data\\modelmeshdata.erf"; ERF meshes = new ERF(meshERFPath); meshes.readKeyData(); Assert.Greater(meshes.resourceCount, 0); int failures = 0; for (int i = 0; i < meshes.resourceCount; i++) { GFF temp = IO.findFile <GFF>(meshes.resourceNames[i]); Assert.NotNull(temp, "Not found: |" + meshes.resourceNames[i] + "|" + i); if (Path.GetExtension(meshes.resourceNames[i]) == ".msh") { try { ModelMesh tempH = new ModelMesh(temp); } catch (Exception) { Console.WriteLine(meshes.resourceNames[i]); failures++; } } } Assert.AreEqual(0, failures); }
/// <summary> /// Debugging method that handles the writing of the mesh structure. /// </summary> /// <param name="ID">The index of the current mesh</param> /// <param name="mesh">The current mesh</param> /// <param name="writer">The stream writer used to write the information /// to a text file</param> private void WriteModelMesh(int ID, ModelMesh mesh, StreamWriter writer) { writer.WriteLine("- ID : " + ID); writer.WriteLine(" Name: " + mesh.Name); writer.Write(" Bone: " + mesh.ParentBone.Name); writer.WriteLine(" (" + mesh.ParentBone.Index + ")"); }
private void DrawMesh(Matrix transform, ModelMesh mesh, float alpha) { GraphicsDevice.RenderState.AlphaBlendEnable = true; GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha; // GraphicsDevice.RenderState.AlphaBlendOperation = BlendFunction.Add; // foreach (BasicEffect effect in mesh.Effects) foreach (SunlightEffect effect in mesh.Effects) { // effect.EnableDefaultLighting(); effect.Alpha = alpha; effect.View = Camera.View; effect.Projection = Camera.Projection; effect.World = transform; effect.ApplyParameters(); // SunlightEffect sunlight = effect; // if (sunlight != null) // { // } } mesh.Draw(); GraphicsDevice.RenderState.AlphaBlendEnable = false; }
protected void DrawShadowMapHelper(Model model, Matrix world) { var shadowMapGenerate = _effects["Shader_ShadowMap"]; for (int index = 0; index < model.Meshes.Count; index++) { ModelMesh mesh = model.Meshes[index]; for (int i = 0; i < mesh.MeshParts.Count; i++) { ModelMeshPart meshpart = mesh.MeshParts[i]; shadowMapGenerate.Parameters["WorldViewProj"].SetValue(world * lightViewProjection); shadowMapGenerate.CurrentTechnique.Passes[0].Apply(); GraphicsDevice.SetVertexBuffer(meshpart.VertexBuffer); GraphicsDevice.Indices = (meshpart.IndexBuffer); int primitiveCount = meshpart.PrimitiveCount; int vertexOffset = meshpart.VertexOffset; int vCount = meshpart.NumVertices; int startIndex = meshpart.StartIndex; GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, vertexOffset, startIndex, primitiveCount); } } }
private void Draw(ModelMesh mesh, Matrix projectionXform, Matrix viewXform, Matrix worldXform, Transforms.IGeometryTransform modelXform) { if (modelXform is Transforms.SkinnedTransform skinXform) { var skinTransforms = skinXform.SkinMatrices.Select(item => item.ToXna()).ToArray(); foreach (var effect in mesh.Effects) { UpdateTransforms(effect, projectionXform, viewXform, worldXform, skinTransforms); } } if (modelXform is Transforms.RigidTransform statXform) { var statTransform = statXform.WorldMatrix.ToXna(); worldXform = Matrix.Multiply(statTransform, worldXform); foreach (var effect in mesh.Effects) { UpdateTransforms(effect, projectionXform, viewXform, worldXform); } } mesh.Draw(); }
private static void drawMesh(ModelMesh mesh, GameModel model, string tech, Plane?clipPlane, Matrix view) { Matrix entityWorld = ConversionHelper.MathConverter.Convert(model.Entity.CollisionInformation.WorldTransform.Matrix); foreach (Effect currentEffect in mesh.Effects) { currentEffect.CurrentTechnique = currentEffect.Techniques[tech]; currentEffect.Parameters["Texture"].SetValue(model.Texture.ActualTexture); currentEffect.Parameters["xCamerasViewProjection"].SetValue(view * MathConverter.Convert(Camera.ProjectionMatrix)); currentEffect.Parameters["xWorld"].SetValue(mesh.ParentBone.Transform * model.Transform * entityWorld);// * Camera.World); currentEffect.Parameters["xPassThroughLighting"].SetValue(true); //currentEffect.Parameters["xLightPos"].SetValue(lights.LightPosition); //currentEffect.Parameters["xLightPower"].SetValue(0.4f); //currentEffect.Parameters["xAmbient"].SetValue(lights.AmbientPower); //currentEffect.Parameters["xLightDir"].SetValue(lights.LightDirection); if (clipPlane.HasValue) { currentEffect.Parameters["xEnableClipping"].SetValue(true); currentEffect.Parameters["xClipPlane"].SetValue(new Vector4(clipPlane.Value.Normal, clipPlane.Value.D)); } else { currentEffect.Parameters["xEnableClipping"].SetValue(false); } } mesh.Draw(); }
//See https://electronicmeteor.wordpress.com/2011/10/25/bounding-boxes-for-your-model-meshes/ public static BoundingBox BuildBoundingBox(ModelMesh mesh, Matrix meshTransform) { // Create initial variables to hold min and max xyz values for the mesh Vector3 meshMax = new Vector3(float.MinValue); Vector3 meshMin = new Vector3(float.MaxValue); foreach (ModelMeshPart part in mesh.MeshParts) { // The stride is how big, in bytes, one vertex is in the vertex buffer // We have to use this as we do not know the make up of the vertex int stride = part.VertexBuffer.VertexDeclaration.VertexStride; VertexPositionNormalTexture[] vertexData = new VertexPositionNormalTexture[part.NumVertices]; part.VertexBuffer.GetData(part.VertexOffset * stride, vertexData, 0, part.NumVertices, stride); // Find minimum and maximum xyz values for this mesh part Vector3 vertPosition = new Vector3(); for (int i = 0; i < vertexData.Length; i++) { vertPosition = vertexData[i].Position; // update our values from this vertex meshMin = Vector3.Min(meshMin, vertPosition); meshMax = Vector3.Max(meshMax, vertPosition); } } // transform by mesh bone matrix meshMin = Vector3.Transform(meshMin, meshTransform); meshMax = Vector3.Transform(meshMax, meshTransform); // Create the bounding box return(new BoundingBox(meshMin, meshMax)); }
public void Draw(Matrix view, Matrix projection) { //foreach (ModelMesh mesh in model.Meshes) for (int i = 0; i < model.Meshes.Count; i++) { ModelMesh mesh = model.Meshes[i]; foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.GraphicsDevice.DepthStencilState = DepthStencilState.Default; if (i == 1 || i == 3) { effect.World = Matrix.CreateRotationY(WheelAngle) * mesh.ParentBone.Transform * Matrix.CreateRotationZ(Body.Rotation) * Matrix.CreateTranslation(new Vector3(Body.Position, 0f)); } else { effect.World = mesh.ParentBone.Transform * Matrix.CreateRotationZ(Body.Rotation) * Matrix.CreateTranslation(new Vector3(Body.Position, 0f)); } effect.View = view; effect.Projection = projection; } mesh.Draw(); } }
public static void DrawWithTextureBumpShader(ModelMesh mesh, Effect shader, Vector3 cameraPosition, Matrix world, Matrix view, Matrix projection, Texture2D texture, Texture2D normalMap) { foreach (ModelMeshPart part in mesh.MeshParts) { part.Effect = shader; shader.Parameters["World"].SetValue(world); shader.Parameters["View"].SetValue(view); shader.Parameters["Projection"].SetValue(projection); shader.Parameters["WorldInverseTranspose"].SetValue(Matrix.Transpose(Matrix.Invert(world))); shader.Parameters["ModelTexture"].SetValue(texture); shader.Parameters["AmbientColor"].SetValue(Color.White.ToVector4()); shader.Parameters["AmbientIntensity"].SetValue(0.1f); shader.Parameters["DiffuseLightDirection"].SetValue(new Vector3(0.0f, 1000.0f, 1000.0f)); //shader.Parameters["DiffuseColor"].SetValue(Color.White.ToVector4()); //shader.Parameters["DiffuseIntensity"].SetValue(1.0f); shader.Parameters["Shininess"].SetValue(20.0f); shader.Parameters["SpecularColor"].SetValue(Color.White.ToVector4()); shader.Parameters["SpecularIntensity"].SetValue(0.8f); shader.Parameters["NormalMap"].SetValue(normalMap); } mesh.Draw(); }
protected override void InitFromMeshData(Device device, GeometryGenerator.MeshData mesh) { var subset = new MeshGeometry.Subset { FaceCount = mesh.Indices.Count / 3, FaceStart = 0, VertexCount = mesh.Vertices.Count, VertexStart = 0 }; Subsets.Add(subset); var max = new Vector3(float.MinValue); var min = new Vector3(float.MaxValue); foreach (var vertex in mesh.Vertices) { max = Vector3.Maximize(max, vertex.Position); min = Vector3.Minimize(min, vertex.Position); } BoundingBox = new BoundingBox(min, max); Vertices.AddRange(mesh.Vertices.Select(v => new PosNormalTexTan(v.Position, v.Normal, v.TexC, v.TangentU)).ToList()); Indices.AddRange(mesh.Indices.Select(i => (short)i)); Materials.Add(new Material { Ambient = Color.Gray, Diffuse = Color.White, Specular = new Color4(16, 1, 1, 1) }); DiffuseMapSRV.Add(null); NormalMapSRV.Add(null); ModelMesh.SetSubsetTable(Subsets); ModelMesh.SetVertices(device, Vertices); ModelMesh.SetIndices(device, Indices); }
/// <summary> /// This simple draw function is used to draw the on-screen /// representation of the lights affecting the meshes in the scene. /// </summary> protected void DrawLights() { ModelMesh mesh = pointLightMesh.Meshes[0]; ModelMeshPart meshPart = mesh.MeshParts[0]; graphics.GraphicsDevice.Vertices[0].SetSource( mesh.VertexBuffer, meshPart.StreamOffset, meshPart.VertexStride); graphics.GraphicsDevice.VertexDeclaration = meshPart.VertexDeclaration; graphics.GraphicsDevice.Indices = mesh.IndexBuffer; pointLightMeshEffect.Begin(SaveStateMode.None); pointLightMeshEffect.CurrentTechnique.Passes[0].Begin(); //loop through the lights and draw a flat-colored sphere //to represent their positions for (int i = 0; i < numLights; i++) { lightMeshWorld.M41 = lights[i].Position.X; lightMeshWorld.M42 = lights[i].Position.Y; lightMeshWorld.M43 = lights[i].Position.Z; pointLightMeshEffect.Parameters["world"].SetValue(lightMeshWorld); pointLightMeshEffect.Parameters["lightColor"].SetValue( lights[i].Color.ToVector4()); pointLightMeshEffect.CommitChanges(); graphics.GraphicsDevice.DrawIndexedPrimitives( PrimitiveType.TriangleList, meshPart.BaseVertex, 0, meshPart.NumVertices, meshPart.StartIndex, meshPart.PrimitiveCount); } pointLightMeshEffect.CurrentTechnique.Passes[0].End(); pointLightMeshEffect.End(); }
public ModelMesh CreateMesh(Schema2.Mesh srcMesh, int maxBones = 72) { if (_Device == null) { throw new InvalidOperationException(); } var srcPrims = GetValidPrimitives(srcMesh).ToList(); var dstMesh = new ModelMesh(_Device, Enumerable.Range(0, srcPrims.Count).Select(item => new ModelMeshPart()).ToList()); dstMesh.Name = srcMesh.Name; dstMesh.BoundingSphere = srcMesh.CreateBoundingSphere(); var srcNormals = new MeshNormalsFallback(srcMesh); var idx = 0; foreach (var srcPrim in srcPrims) { CreateMeshPart(dstMesh.MeshParts[idx++], srcPrim, srcNormals, maxBones); } return(dstMesh); }
/// <summary> /// This method draws a model mesh, with the given worldMatrix as viewed by the camera. /// </summary> /// <param name="mesh">The mesh to draw</param> /// <param name="worldMatrix">The matrix holding the position, rotation and scale of the mesh</param> /// <param name="camera">The camera which represents the user's current view</param> public void DrawModelMesh(ModelMesh mesh, Matrix worldMatrix, bool applyCustomEffects) { Cameras.Camera currentCamera = DisplayController.Display.CurrentView.Camera; // setup effect parameters for each effect foreach (BasicEffect effect in mesh.Effects) { // use default settings for now. effect.EnableDefaultLighting(); effect.PreferPerPixelLighting = true; // the view, projection and world matrices must be setup for each effect, each frame. effect.View = currentCamera.ViewMatrix; effect.Projection = currentCamera.ProjectionMatrix; effect.World = worldMatrix; // apply custom effects (if any): if (applyCustomEffects) { this.ApplyCustomEffects(effect); } // propagate changes. Any changes to parameters are not applied until CommitChanges() is called. effect.CommitChanges(); } // actually draw the model, now that all effects have been setup: mesh.Draw(); }
private void DrawBoxBody(RigidBody body) { // We know that the shape is a boxShape BoxShape shape = body.Shape as BoxShape; // Create the 4x4 xna matrix, containing the orientation // (represented in jitter by a 3x3 matrix) and the position. Matrix matrix = Conversion.ToXNAMatrix(body.Orientation); matrix.Translation = Conversion.ToXNAVector(body.Position); // We have a (1,1,1) box so packing the box size // information into the the "scale" part of the xna // matrix is a good idea. Matrix scaleMatrix = Matrix.CreateScale(shape.Size.X, shape.Size.Y, shape.Size.Z); // the next lines of code draw the boxModel using the matrix. ModelMesh mesh = boxModel.Meshes[0]; foreach (BasicEffect effect in mesh.Effects) { effect.DiffuseColor = ((Color)body.Tag).ToVector3(); effect.EnableDefaultLighting(); effect.World = scaleMatrix * matrix; effect.View = viewMatrix; effect.Projection = projectionMatrix; } mesh.Draw(); }
private static ModelMesh ReadMesh(BinaryReader r) { var data = new ModelMesh(); data.NumVerts = r.ReadInt32(); data.NumPrims = r.ReadInt32(); data.NumRefBones= r.ReadInt32(); data.RefBones = ReadList(r, data.NumRefBones, ReadRefBone); foreach(var i in data.RefBones) i.Matrix = ReadSingleArray(r, 16); data.Vertices = ReadList(r, data.NumVerts, ReadVertex); data.NumTangents= r.ReadInt32(); System.Diagnostics.Debug.Assert(data.NumTangents == 0); data.Tangents = ReadList(r, data.NumTangents, ReadVector4); data.Skins = ReadList(r, data.NumVerts, ReadSkin); //System.Diagnostics.Debug.Assert(data.Unknown2 == 0); data.Primitives = new List<ModelPrimitive>(); for(int i= 0; i < data.NumPrims; ++i) { var prim = new ModelPrimitive(); prim.NumIndices = r.ReadInt32(); prim.Indices = ReadList(r, prim.NumIndices, r.ReadUInt16); data.Primitives.Add(prim); } return data; }
protected override void Draw(GameTime gt, IObject obj, RenderHelper render, ICamera cam, IList <Light.ILight> lights) { AnimatedModel modelo = obj.Modelo as AnimatedModel; for (int i = 0; i < modelo.GetAnimatedModel().Meshes.Count; i++) { ModelMesh modelMesh = modelo.GetAnimatedModel().Meshes[i]; for (int j = 0; j < modelMesh.MeshParts.Count; j++) { SkinnedModelBasicEffect basicEffect = (SkinnedModelBasicEffect)modelMesh.MeshParts[j].Effect; basicEffect.CurrentTechnique = basicEffect.Techniques["FORWARD"]; basicEffect.Parameters["diffuseMap0"].SetValue(modelo.getTexture(TextureType.DIFFUSE, i, j)); basicEffect.Parameters["diffuseMapEnabled"].SetValue(true); if (followBone) { basicEffect.World = Followed.GetBoneAbsoluteTransform(boneName) * Followobj.WorldMatrix; basicEffect.Bones = ac.GetBoneTransformations(); } else { basicEffect.World = WorldMatrix; basicEffect.Bones = ac.GetBoneTransformations(); } basicEffect.View = cam.View; basicEffect.Projection = cam.Projection; } modelMesh.Draw(); } }
protected override void Draw(GameTime gt, IObject obj, RenderHelper render, ICamera cam, IList <Light.ILight> lights) { AnimatedModel modelo = obj.Modelo as AnimatedModel; for (int i = 0; i < modelo.GetAnimatedModel().Meshes.Count; i++) { ModelMesh modelMesh = modelo.GetAnimatedModel().Meshes[i]; for (int j = 0; j < modelMesh.MeshParts.Count; j++) { SkinnedEffect basicEffect = (SkinnedEffect)modelMesh.MeshParts[j].Effect; if (EnableTexture) { basicEffect.Texture = modelo.getTexture(TextureType.DIFFUSE, i, j); } if (followBone) { basicEffect.World = Followed.GetBoneAbsoluteTransform(boneName) * Followobj.WorldMatrix; basicEffect.SetBoneTransforms(modelo.getBonesTransformation()); } else { basicEffect.World = WorldMatrix; basicEffect.SetBoneTransforms(ac.GetBoneTransformations()); } basicEffect.View = cam.View; basicEffect.Projection = cam.Projection; } modelMesh.Draw(); } }
public override Asset Import(string path) { MSHS mshs = MSHS.Load(path); Model model = new Model(); string name = Path.GetFileNameWithoutExtension(path); int meshnum = 0; foreach (var tdrmesh in mshs.Meshes) { ModelMesh mesh = new ModelMesh(); mesh.Name = name + meshnum++.ToString("0000"); ModelMeshPart meshpart = new ModelMeshPart(); meshpart.PrimitiveType = OpenTK.Graphics.OpenGL.PrimitiveType.Triangles; SceneManager.Current.UpdateProgress(string.Format("Processing {0}", mesh.Name)); for (int i = 0; i < tdrmesh.Faces.Count; i++) { var face = tdrmesh.Faces[i]; var v1 = tdrmesh.Vertexes[face.V1]; var v2 = tdrmesh.Vertexes[face.V2]; var v3 = tdrmesh.Vertexes[face.V3]; meshpart.AddFace( new OpenTK.Vector3[] { new OpenTK.Vector3(v1.Position.X, v1.Position.Y, v1.Position.Z), new OpenTK.Vector3(v2.Position.X, v2.Position.Y, v2.Position.Z), new OpenTK.Vector3(v3.Position.X, v3.Position.Y, v3.Position.Z) }, new OpenTK.Vector3[] { new OpenTK.Vector3(v1.Normal.X, v1.Normal.Y, v1.Normal.Z), new OpenTK.Vector3(v2.Normal.X, v2.Normal.Y, v2.Normal.Z), new OpenTK.Vector3(v3.Normal.X, v3.Normal.Y, v3.Normal.Z) }, new OpenTK.Vector2[] { new OpenTK.Vector2(v1.UV.X, v1.UV.Y), new OpenTK.Vector2(v2.UV.X, v2.UV.Y), new OpenTK.Vector2(v3.UV.X, v3.UV.Y) } ); } mesh.AddModelMeshPart(meshpart); model.SetName(mesh.Name, model.AddMesh(mesh)); } return model; }
public void OnBeginDrawMesh(ModelMesh mesh, RenderSettings renderSettings) { mesh.Effect.LightViewProjection = _lightViewProjection; if (_creatingShadowMap) { mesh.Effect.CurrentTechnique = "RenderShadowMap"; } else { mesh.Effect.CurrentTechnique = "RenderScene"; mesh.Effect.ShadowsEnabled = true; mesh.Effect.ShadowMap = _shadowRenderTarget; mesh.Effect.ShadowMapSize = ShadowMapSize; } }
private static void WriteMesh(BinaryWriter w, ModelMesh data) { w.Write(data.NumVerts); w.Write(data.NumPrims); w.Write(data.NumRefBones); Write(w, WriteString, data.RefBones.Select(i => i.Name)); Write(w, (v) => Write(w, w.Write, v), data.RefBones.Select(i => i.Matrix)); Write(w, WriteVertex, data.Vertices); w.Write(data.NumTangents); Write(w, WriteVector4, data.Tangents); Write(w, WriteSkin, data.Skins); foreach(var i in data.Primitives) { w.Write(i.NumIndices); Write(w, w.Write, i.Indices); } }
public override void OnEndDrawMesh(ModelMesh mesh, RenderSettings renderSettings) { NormalBuffers normalBuffers = GetNormalBuffers(mesh); _device.VertexDeclaration = _lineVertexDeclaration; _device.SetStreamSource(0, normalBuffers.Vertices, 0, VertexPositionColor.SizeInBytes); _device.Indices = normalBuffers.Indices; _lineEffect.WorldViewProjection = renderSettings.ViewMatrix * renderSettings.ProjectionMatrix; int passes = _lineEffect.Begin(); for (int pass = 0; pass < passes; ++pass) { _lineEffect.BeginPass(pass); _device.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, normalBuffers.VertexCount, 0, normalBuffers.PrimitiveCount); _lineEffect.EndPass(); } }
private NormalBuffers GetNormalBuffers(ModelMesh mesh) { if (!_normals.ContainsKey(mesh)) { NormalBuffers normalBuffers = new NormalBuffers(); Line3D[] normalLines = NormalLinesGenerator.Generate(mesh.SourceMesh); normalBuffers.PrimitiveCount = normalLines.Length; normalBuffers.VertexCount = normalLines.Length * 2; VertexBuffer vertexBuffer = new VertexBuffer(_device, normalBuffers.VertexCount * VertexPositionColor.SizeInBytes, Usage.WriteOnly, VertexFormat.None, Pool.Default); DataStream vertexDataStream = vertexBuffer.Lock(0, normalBuffers.VertexCount * VertexPositionColor.SizeInBytes, LockFlags.None); VertexPositionColor[] vertices = new VertexPositionColor[normalBuffers.VertexCount]; int counter = 0; for (int i = 0; i < normalLines.Length; ++i) { Vector3D normalColor = Vector3D.Normalize(normalLines[i].Direction); normalColor += Vector3D.One; normalColor *= 0.5f; vertices[counter++] = new VertexPositionColor(normalLines[i].Start, normalColor); vertices[counter++] = new VertexPositionColor(normalLines[i].End, normalColor); } vertexDataStream.WriteRange(vertices); vertexBuffer.Unlock(); normalBuffers.Vertices = vertexBuffer; IndexBuffer indexBuffer = new IndexBuffer(_device, normalBuffers.VertexCount * sizeof(int), Usage.WriteOnly, Pool.Default, false); DataStream indexDataStream = indexBuffer.Lock(0, normalBuffers.VertexCount * sizeof(int), LockFlags.None); indexDataStream.WriteRange(Enumerable.Range(0, normalBuffers.VertexCount).ToArray()); indexBuffer.Unlock(); normalBuffers.Indices = indexBuffer; _normals.Add(mesh, normalBuffers); } return _normals[mesh]; }
public override Asset Import(string path) { MDL mdl = MDL.Load(path); Model model = new Model(); ModelMesh mesh = new ModelMesh(); // 2015-07-12 : Commenting out SupportingDocuments["Source"] to see if anything breaks // model.SupportingDocuments["Source"] = mdl; bool bUsePrepData = true; for (int i = 0; i < mdl.Meshes.Count; i++) { Dictionary<int, int> newIndex = new Dictionary<int, int>(); ModelMeshPart meshpart = new ModelMeshPart(); var mdlmesh = mdl.GetMesh(i); meshpart.Material = SceneManager.Current.Content.Load<Material, MaterialImporter>(mdlmesh.Name, Path.GetDirectoryName(path), true); if (bUsePrepData) { foreach (var f in mdl.Faces.Where(f => f.MaterialID == i)) { for (int j = 0; j < 3; j++) { if (!newIndex.ContainsKey(f.Verts[j])) { var v = mdl.Vertices[f.Verts[j]]; int index = meshpart.AddVertex(new Vector3(v.Position.X, v.Position.Y, v.Position.Z), new Vector3(v.Normal.X, v.Normal.Y, v.Normal.Z), new Vector2(v.UV.X, v.UV.Y), new Vector2(v.UV2.X, v.UV2.Y), v.Colour, false); newIndex.Add(f.Verts[j], index); } } meshpart.AddFace( newIndex[f.Verts[0]], newIndex[f.Verts[1]], newIndex[f.Verts[2]] ); } } else { int[] verts = new int[3]; for (int j = 0; j < mdlmesh.StripList.Count - 2; j++) { if (mdlmesh.StripList[j + 2].Degenerate) { continue; } verts[0] = mdlmesh.StripList[j + 0].Index; if (j % 2 == 0) { verts[1] = mdlmesh.StripList[j + 1].Index; verts[2] = mdlmesh.StripList[j + 2].Index; } else { verts[1] = mdlmesh.StripList[j + 2].Index; verts[2] = mdlmesh.StripList[j + 1].Index; } for (int k = 0; k < 3; k++) { if (!newIndex.ContainsKey(verts[k])) { var v = mdl.Vertices[verts[k]]; int index = meshpart.AddVertex(new Vector3(v.Position.X, v.Position.Y, v.Position.Z), new Vector3(v.Normal.X, v.Normal.Y, v.Normal.Z), new Vector2(v.UV.X, v.UV.Y), new Vector2(v.UV2.X, v.UV2.Y), v.Colour, false); newIndex.Add(verts[k], index); } } meshpart.AddFace( newIndex[verts[0]], newIndex[verts[1]], newIndex[verts[2]] ); } // Process patch list for (int j = 0; j < mdlmesh.TriList.Count; j += 3) { verts[0] = mdlmesh.TriList[j + 0].Index; verts[1] = mdlmesh.TriList[j + 1].Index; verts[2] = mdlmesh.TriList[j + 2].Index; for (int k = 0; k < 3; k++) { if (!newIndex.ContainsKey(verts[k])) { var v = mdl.Vertices[verts[k]]; int index = meshpart.AddVertex(new Vector3(v.Position.X, v.Position.Y, v.Position.Z), new Vector3(v.Normal.X, v.Normal.Y, v.Normal.Z), new Vector2(v.UV.X, v.UV.Y), new Vector2(v.UV2.X, v.UV2.Y), v.Colour, false); newIndex.Add(verts[k], index); } } meshpart.AddFace( newIndex[verts[0]], newIndex[verts[1]], newIndex[verts[2]] ); } } mesh.AddModelMeshPart(meshpart); Console.WriteLine(meshpart.VertexCount / 3); } mesh.Name = mdl.Name; model.SetName(mdl.Name, model.AddMesh(mesh)); return model; }
protected override bool ReadInternal() { RootMesh = null; TexturesPaths = new List<string>(); TexturesCache = new Dictionary<int, Texture2D>(); Meshes = new List<ModelMesh>(); if (base.ReadInternal() == false) { return false; } AnimationLength = Reader.ReadInt32(); ShadeType = (ModelShadeType)Reader.ReadInt32(); if (FileHeader.Version.Version >= 0x0104) { Alpha = Reader.ReadByte(); } else { Alpha = 0; } var unknown = Reader.ReadBytes(16); var textureCount = Reader.ReadInt32(); for (var i = 0; i < textureCount; i++) { var textureName = Reader.ReadStringIso(40); TexturesPaths.Add(string.Format("data/texture/{0}", textureName)); } var mainMeshName = Reader.ReadStringIso(40); var meshCount = Reader.ReadInt32(); for (var i = 0; i < meshCount; i++) { var mesh = new ModelMesh(this); Meshes.Add(mesh); if (mesh.Name == mainMeshName) { RootMesh = mesh; } } if (RootMesh == null) { throw new Exception("Failed to find main-mesh node"); } RootMesh.Parent = null; RootMesh.UpdateChildren(Meshes); var bbmin = new Vector3(999999, 999999, 999999); var bbmax = new Vector3(-999999, -999999, -9999999); RootMesh.SetBoundingBox(ref bbmin, ref bbmax); BbMin = bbmin; BbMax = bbmax; BbRange = (BbMin + BbMax) / 2.0f; RootMesh.CalcMatrix1(); RootMesh.CalcMatrix2(); _realBbMin = new Vector3(999999, 999999, 999999); _realBbMax = new Vector3(-999999, -999999, -999999); //glm::mat4 mat = glm::scale(glm::vec3(1,-1,1)); var mat = Matrix.CreateScale(1, -1, 1); RootMesh.SetBoundingBox2(ref mat, ref _realBbMin, ref _realBbMax); _realBbRange = (_realBbMax + _realBbMin) / 2.0f; MaxRange = Math.Max( Math.Max(_realBbMax.X, -_realBbMin.X), Math.Max( Math.Max(_realBbMax.Y, -_realBbMin.Y), Math.Max(_realBbMax.Z, -_realBbMin.Z) ) ); return true; }
public override Asset Import(string path) { DAT dat = DAT.Load(path); SceneManager.Current.Content.LoadMany<MaterialList, MaterialImporter>(Path.GetFileName(path).Replace(".dat", ".mat", StringComparison.OrdinalIgnoreCase), Path.GetDirectoryName(path) + "\\", true); Model model = new Model(); foreach (var datmesh in dat.DatMeshes) { Console.WriteLine(datmesh.Name); datmesh.Mesh.GenerateNormals(); ModelMesh mesh = new ModelMesh(); mesh.Name = (datmesh.Name.Contains(".") ? datmesh.Name.Substring(0, datmesh.Name.IndexOf(".")) : datmesh.Name); SceneManager.Current.UpdateProgress(string.Format("Processing {0}", mesh.Name)); for (int i = -1; i < datmesh.Mesh.Materials.Count; i++) { var meshpart = new ModelMeshPart(); if (i > -1) { var material = SceneManager.Current.Materials.Entries.Find(m => m.Name == datmesh.Mesh.Materials[i]); if (material == null) { material = new Material { Name = datmesh.Mesh.Materials[i] }; SceneManager.Current.Add(material); } meshpart.Material = (Material)material; } foreach (var face in datmesh.Mesh.Faces.Where(f => f.MaterialID == i)) { int smoothingGroup = (face.SmoothingGroup << 8); meshpart.AddFace( new OpenTK.Vector3[] { new OpenTK.Vector3(datmesh.Mesh.Verts[face.V1].X, datmesh.Mesh.Verts[face.V1].Y, datmesh.Mesh.Verts[face.V1].Z), new OpenTK.Vector3(datmesh.Mesh.Verts[face.V2].X, datmesh.Mesh.Verts[face.V2].Y, datmesh.Mesh.Verts[face.V2].Z), new OpenTK.Vector3(datmesh.Mesh.Verts[face.V3].X, datmesh.Mesh.Verts[face.V3].Y, datmesh.Mesh.Verts[face.V3].Z) }, new OpenTK.Vector3[] { new OpenTK.Vector3(datmesh.Mesh.Normals[smoothingGroup + face.V1].X, datmesh.Mesh.Normals[smoothingGroup + face.V1].Y, datmesh.Mesh.Normals[smoothingGroup + face.V1].Z), new OpenTK.Vector3(datmesh.Mesh.Normals[smoothingGroup + face.V2].X, datmesh.Mesh.Normals[smoothingGroup + face.V2].Y, datmesh.Mesh.Normals[smoothingGroup + face.V2].Z), new OpenTK.Vector3(datmesh.Mesh.Normals[smoothingGroup + face.V3].X, datmesh.Mesh.Normals[smoothingGroup + face.V3].Y, datmesh.Mesh.Normals[smoothingGroup + face.V3].Z) }, new OpenTK.Vector2[] { (datmesh.Mesh.HasUVs ? new OpenTK.Vector2(datmesh.Mesh.UVs[face.UV1].X, datmesh.Mesh.UVs[face.UV1].Y) : OpenTK.Vector2.Zero), (datmesh.Mesh.HasUVs ? new OpenTK.Vector2(datmesh.Mesh.UVs[face.UV2].X, datmesh.Mesh.UVs[face.UV2].Y) : OpenTK.Vector2.Zero), (datmesh.Mesh.HasUVs ? new OpenTK.Vector2(datmesh.Mesh.UVs[face.UV3].X, datmesh.Mesh.UVs[face.UV3].Y) : OpenTK.Vector2.Zero) } ); } mesh.AddModelMeshPart(meshpart, false); } for (int i = mesh.MeshParts.Count - 1; i >= 0; i--) { if (mesh.MeshParts[i].VertexCount == 0) { mesh.MeshParts.RemoveAt(i); } else { mesh.MeshParts[i].Finalise(); } } model.SetName(mesh.Name, model.AddMesh(mesh)); } return model; }
public override Asset Import(string path) { BOM bom = BOM.Load(path); Model model = new Model(); model.SupportingDocuments["Source"] = bom; for (int i = 0; i < bom.Meshes.Count; i++) { var bommesh = bom.Meshes[i]; ModelMesh mesh = new ModelMesh(); ModelMeshPart meshpart = new ModelMeshPart(); if (i < 4) { for (int j = 0; j < bommesh.IndexBuffer.Count; j += 3) { int p0 = bommesh.IndexBuffer[j + 0]; int p1 = bommesh.IndexBuffer[j + 1]; int p2 = bommesh.IndexBuffer[j + 2]; meshpart.AddFace( new Vector3[] { new Vector3(bom.Verts[p0].Position.X, bom.Verts[p0].Position.Y, bom.Verts[p0].Position.Z), new Vector3(bom.Verts[p1].Position.X, bom.Verts[p1].Position.Y, bom.Verts[p1].Position.Z), new Vector3(bom.Verts[p2].Position.X, bom.Verts[p2].Position.Y, bom.Verts[p2].Position.Z), }, new Vector3[] { new Vector3(bom.Verts[p0].Normal.X, bom.Verts[p0].Normal.Y, bom.Verts[p0].Normal.Z), new Vector3(bom.Verts[p1].Normal.X, bom.Verts[p1].Normal.Y, bom.Verts[p1].Normal.Z), new Vector3(bom.Verts[p2].Normal.X, bom.Verts[p2].Normal.Y, bom.Verts[p2].Normal.Z), }, new Vector2[] { Vector2.Zero, Vector2.Zero, Vector2.Zero } ); } } else { // Process triangle strip for (int j = 0; j < bommesh.IndexBuffer.Count - 2; j++) { BOMVertex v0, v1, v2; v0 = bom.Verts[bommesh.IndexBuffer[j + 0]]; if (j % 2 != 0) { v1 = bom.Verts[bommesh.IndexBuffer[j + 1]]; v2 = bom.Verts[bommesh.IndexBuffer[j + 2]]; } else { v1 = bom.Verts[bommesh.IndexBuffer[j + 2]]; v2 = bom.Verts[bommesh.IndexBuffer[j + 1]]; } meshpart.AddFace( new Vector3[] { new Vector3(v0.Position.X, v0.Position.Y, v0.Position.Z), new Vector3(v1.Position.X, v1.Position.Y, v1.Position.Z), new Vector3(v2.Position.X, v2.Position.Y, v2.Position.Z) }, new Vector3[] { new Vector3(v0.Normal.X, v0.Normal.Y, v0.Normal.Z), new Vector3(v1.Normal.X, v1.Normal.Y, v1.Normal.Z), new Vector3(v2.Normal.X, v2.Normal.Y, v2.Normal.Z) }, new Vector2[] { Vector2.Zero, Vector2.Zero, Vector2.Zero } ); } } mesh.AddModelMeshPart(meshpart); mesh.Name = bom.Name + "_" + i; model.SetName(bom.Name, model.AddMesh(mesh)); } return model; }
public void OnEndDrawMesh(ModelMesh mesh, RenderSettings renderSettings) { if (!_creatingShadowMap) { mesh.Effect.ShadowsEnabled = false; mesh.Effect.ShadowMap = null; } }
public virtual void OnEndDrawMesh(ModelMesh mesh, RenderSettings renderSettings) { }
public override void OnBeginDrawMesh(ModelMesh mesh, RenderSettings renderSettings) { mesh.Effect.SpecularEnabled = !renderSettings.Parameters.NoSpecular; }
private void BuildMesh(mstudio_mesh_t src, ModelMesh mesh) { foreach (var face in src.Faces) mesh.Faces.Add(face); }
private ModelMesh BuildMesh(mstudio_bodyparts_t bp) { var mesh = new ModelMesh(); BuildMesh(bp, mesh); return mesh; }
private void BuildMesh(mstudio_bodyparts_t bp, ModelMesh mesh) { foreach (var m in bp.Models) BuildMesh(m, mesh); }
private void BuildMesh(mstudio_model_t mdl, ModelMesh mesh) { foreach (var m in mdl.Meshes) BuildMesh(m, mesh); }
public static ModelMesh[] LoadFromFile(GameMode gameMode, string filePath) { if (".pmesh".Equals(Path.GetExtension(filePath), StringComparison.OrdinalIgnoreCase)) { return new[] { LoadPMesh(gameMode, filePath) }; } else { var modelDirectory = Path.GetDirectoryName(filePath); var context = new AssimpContext(); const PostProcessSteps flags = PostProcessSteps.GenerateNormals | PostProcessSteps.GenerateUVCoords | PostProcessSteps.FlipWindingOrder | PostProcessSteps.FlipUVs; var scene = context.ImportFile(filePath, flags); var meshs = new List<ModelMesh>(); foreach (var assimpMesh in scene.Meshes) { var modelMesh = new ModelMesh(gameMode, scene, assimpMesh, modelDirectory); meshs.Add(modelMesh); } return meshs.ToArray(); } }