/// <summary> /// Creates a model with information loaded from a model file /// </summary> /// <param name="transforms">Transforms applied to each model meshes</param> /// <param name="mesh">A collection of model meshes</param> public Model(Matrix[] transforms, ModelMeshCollection mesh) { this.transforms = transforms; this.mesh = mesh; offsetTransform = Matrix.Identity; offsetToOrigin = false; vertices = new List <Vector3>(); indices = new List <int>(); shader = new SimpleEffectShader(); technique = ""; afterEffectShaders = new List <IShader>(); animationTransforms = new Dictionary <string, Matrix>(); resourceName = ""; #if !WINDOWS_PHONE shaderName = TypeDescriptor.GetClassName(shader); #endif modelLoaderName = ""; useInternalMaterials = false; useLighting = true; shadowAttribute = ShadowAttribute.None; showBoundingBox = false; boundingBoxCalculated = false; CalculateTriangleCount(); CalculateMinimumBoundingSphere(); }
public RenderingPolygon(ContentManager Content) : base(Content) { lightGreen = content.Load<Texture2D>("Textures/green_texture"); lightBlue = content.Load<Texture2D>("Textures/blue_texture"); cube = content.Load<Model>("Models/Cube"); tetra = content.Load<Model>("Models/Tetra"); cubeMesh = cube.Meshes; tetraMesh = tetra.Meshes; boundingSphereCube = new BoundingSphere(); foreach (ModelMesh mesh in cubeMesh) { if (boundingSphereCube.Radius == 0) boundingSphereCube = mesh.BoundingSphere; else boundingSphereCube = BoundingSphere.CreateMerged(boundingSphereCube, mesh.BoundingSphere); } boundingSphereTetra = new BoundingSphere(); foreach (ModelMesh mesh in tetraMesh) { if (boundingSphereTetra.Radius == 0) boundingSphereTetra = mesh.BoundingSphere; else boundingSphereTetra = BoundingSphere.CreateMerged(boundingSphereTetra, mesh.BoundingSphere); } boundingSphereCube.Radius *= 0.8f; boundingSphereTetra.Radius *= 0.8f; }
public Model(GraphicsDevice graphicsDevice, List<ModelBone> bones, List<ModelMesh> meshes) { // TODO: Complete member initialization this.graphicsDevice = graphicsDevice; Bones = new ModelBoneCollection(bones); Meshes = new ModelMeshCollection(meshes); }
public Model(GraphicsBuffer elementBuffer, ElementType elementType, Sphere3d bounds) { if (elementBuffer == null) throw new ArgumentNullException("elementBuffer"); this.elementBuffer = elementBuffer; this.elementType = elementType; this.bounds = bounds; bones = new ModelBoneCollection(this); meshes = new ModelMeshCollection(this); }
/// <summary> /// Disposes of model contents. /// </summary> public virtual void Dispose() { vertices.Clear(); mesh = null; if (shader != null) { shader.Dispose(); } }
/// <summary> /// Constructs a model. /// </summary> /// <param name="graphicsDevice">A valid reference to <see cref="GraphicsDevice"/>.</param> /// <param name="bones">The collection of bones.</param> /// <param name="meshes">The collection of meshes.</param> public Model(GraphicsDevice graphicsDevice, List<ModelBone> bones, List<ModelMesh> meshes) { if(graphicsDevice == null)throw new ArgumentNullException("graphicsDevice"); // TODO: Complete member initialization this.graphicsDevice = graphicsDevice; Bones = new ModelBoneCollection(bones); Meshes = new ModelMeshCollection(meshes); }
internal override void Draw(Matrix generalWorldMatrix) { int index = 0; ModelMeshCollection meshes = model.Meshes; foreach (var mesh in meshes) { Matrix worldMatrix = mesh.ParentBone.Transform * generalWorldMatrix; Effect.Parameters["World"].SetValue(worldMatrix); mesh.Draw(); index++; } }
/// <summary> /// Constructs a model. /// </summary> /// <param name="graphicsDevice">A valid reference to <see cref="GraphicsDevice"/>.</param> /// <param name="bones">The collection of bones.</param> /// <param name="meshes">The collection of meshes.</param> public Model(GraphicsDevice graphicsDevice, List<ModelBone> bones, List<ModelMesh> meshes) { if (graphicsDevice == null) { throw new ArgumentNullException("graphicsDevice", FrameworkResources.ResourceCreationWhenDeviceIsNull); } // TODO: Complete member initialization this.graphicsDevice = graphicsDevice; Bones = new ModelBoneCollection(bones); Meshes = new ModelMeshCollection(meshes); }
internal override void Draw(Matrix generalWorldMatrix) { int index = 0; ModelMeshCollection meshes = model.Meshes; foreach (var mesh in meshes) { Matrix worldMatrix = mesh.ParentBone.Transform * generalWorldMatrix; Effect.Parameters["World"].SetValue(worldMatrix); Effect.Parameters["InverseTransposeWorld"].SetValue(Matrix.Transpose(Matrix.Invert(worldMatrix))); Effect.Parameters["baseTexture"].SetValue(textures[index]); mesh.Draw(); index++; } }
public CompositeModel(Model model, Vector3 position, Matrix rotation) { this.model = model; this.Meshes = model.Meshes; this.position = position; this.rotation = rotation; //findme if (r == null) { r = new Random(); } this.customColor = new Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble()); this.scale = 1.0f; this.collisionCollection = new CompositeCollision(this.parent,this.position, this.rotation); }
private BoundingSphereBuilder(ModelMeshCollection meshes, Matrix[] transforms) { Meshes = meshes; Transforms = transforms; Sphere = new BoundingSphere(Vector3.Zero, 0); }
public static BoundingSphere Build(ModelMeshCollection meshes, Matrix[] transforms) { return new BoundingSphereBuilder(meshes, transforms).Build(); }
/// <summary> /// Disposes of model contents. /// </summary> public virtual void Dispose() { vertices.Clear(); mesh = null; if (shader != null) shader.Dispose(); }
/// <summary> /// Creates a model with information loaded from a model file /// </summary> /// <param name="transforms">Transforms applied to each model meshes</param> /// <param name="mesh">A collection of model meshes</param> public Model(Matrix[] transforms, ModelMeshCollection mesh) { this.transforms = transforms; this.mesh = mesh; offsetTransform = Matrix.Identity; offsetToOrigin = false; vertices = new List<Vector3>(); indices = new List<int>(); shader = new SimpleEffectShader(); technique = ""; afterEffectShaders = new List<IShader>(); animationTransforms = new Dictionary<string, Matrix>(); resourceName = ""; #if !WINDOWS_PHONE shaderName = TypeDescriptor.GetClassName(shader); #endif modelLoaderName = ""; useInternalMaterials = false; useLighting = true; shadowAttribute = ShadowAttribute.None; showBoundingBox = false; boundingBoxCalculated = false; CalculateTriangleCount(); CalculateMinimumBoundingSphere(); }
private void ReadMeshes(ContentReader input, VertexDeclaration[] vertexDeclarations) { int length = input.ReadInt32(); ModelMesh[] meshes = new ModelMesh[length]; for (int i = 0; i < length; i++) { string name = input.ReadObject<string>(); ModelBone parentBone = this.ReadBoneReference(input); BoundingSphere boundingSphere = new BoundingSphere(); boundingSphere.Center = input.ReadVector3(); boundingSphere.Radius = input.ReadSingle(); VertexBuffer vertexBuffer = input.ReadObject<VertexBuffer>(); IndexBuffer indexBuffer = input.ReadObject<IndexBuffer>(); object tag = input.ReadObject<object>(); ModelMeshPart[] meshParts = ReadMeshParts(input, vertexBuffer, indexBuffer, vertexDeclarations); meshes[i] = new ModelMesh(name, parentBone, boundingSphere, vertexBuffer, indexBuffer, meshParts, tag); } this.meshes = new ModelMeshCollection(meshes); }
/// <summary> /// Constructs a model. /// </summary> /// <param name="graphicsDevice">A valid reference to <see cref="GraphicsDevice"/>.</param> /// <param name="bones">The collection of bones.</param> /// <param name="meshes">The collection of meshes.</param> internal Model(GraphicsDevice graphicsDevice, List<ModelBone> bones, List<ModelMesh> meshes) { Bones = new ModelBoneCollection(bones); Meshes = new ModelMeshCollection(meshes); }
public static Vector3[] FindCollisionPoints(ModelMeshCollection mesh, BoundingBox boundingBox) { Vector3 inset = (boundingBox.Max - boundingBox.Min) * 0.01f; boundingBox.Min += inset; boundingBox.Max -= inset; Vector3[] collisionPoints = new Vector3[6]; int[] numberAdded = new int[6]; foreach(ModelMesh modelMesh in mesh) { foreach(ModelMeshPart modelMeshPart in modelMesh.MeshParts) { VertexPositionColor[] verts = new VertexPositionColor[modelMeshPart.NumVertices]; modelMesh.VertexBuffer.GetData(verts); foreach(VertexPositionColor vertexElement in verts) { if(vertexElement.Position.X < boundingBox.Min.X) { collisionPoints[0] += vertexElement.Position; numberAdded[0]++; } else if(vertexElement.Position.X > boundingBox.Max.X) { collisionPoints[1] += vertexElement.Position; numberAdded[1]++; } if(vertexElement.Position.Y < boundingBox.Min.Y) { collisionPoints[2] += vertexElement.Position; numberAdded[2]++; } else if(vertexElement.Position.Y > boundingBox.Max.Y) { collisionPoints[3] += vertexElement.Position; numberAdded[3]++; } if(vertexElement.Position.Z < boundingBox.Min.Z) { collisionPoints[4] += vertexElement.Position; numberAdded[4]++; } else if(vertexElement.Position.Z > boundingBox.Max.Z) { collisionPoints[5] += vertexElement.Position; numberAdded[5]++; } } } } for(int i = 0; i < collisionPoints.Length; i++) { collisionPoints[i] *= 1f / numberAdded[i]; } collisionPoints[0].X = boundingBox.Min.X; collisionPoints[1].X = boundingBox.Max.X; collisionPoints[2].Y = boundingBox.Min.Y; collisionPoints[3].Y = boundingBox.Max.Y; collisionPoints[4].Z = boundingBox.Min.Z; collisionPoints[5].Z = boundingBox.Max.Z; return collisionPoints; }
protected virtual void ReadMeshes(ref ModelMeshCollection meshes) { ReadList(ref meshes, CreateModelMeshCollection, CreateModelMesh, ReadMesh); }