NodeContent GetDataHolder(NodeContent input, string name) { NodeContentCollection children = input.Children; for (int i = children.Count - 1; i >= 0; --i) { NodeContent n = children[i]; if (n.Name.ToLower() == name.ToLower()) { return(n); } } return(null); }
private void parseChildren(NodeContentCollection ncc) { foreach (NodeContent nc in ncc) { if (nc is MeshContent) { MeshContent mc = (MeshContent)nc; CalcMinMax(mc); } else { parseChildren(nc.Children); } } }
private void parseChildren(NodeContentCollection nodeContentCollection) { foreach (NodeContent nodeContent in nodeContentCollection) { if (nodeContent is MeshContent) { MeshContent meshContent = (MeshContent)nodeContent; foreach (Vector3 vector in meshContent.Positions) { if (vector.X < minX) { minX = vector.X; } if (vector.Y < minY) { minY = vector.Y; } if (vector.Z < minZ) { minZ = vector.Z; } if (vector.X > maxX) { maxX = vector.X; } if (vector.Y > maxY) { maxY = vector.Y; } if (vector.Z > maxZ) { maxZ = vector.Z; } } } else { parseChildren(nodeContent.Children); } } }
/* * float minX = -1; * float minY = -1; * float minZ = -1; * float maxX = 1; * float maxY = 1; * float maxZ = 1; */ public override ModelContent Process(NodeContent input, ContentProcessorContext context) { //rotates models to make the Y-axis point UP //MeshHelper.TransformScene(input,Matrix.CreateRotationX(MathHelper.ToRadians(-90))); //this part is to create a bounding BOX in the models tag property NodeContentCollection ncc = input.Children; //The input itself might actually be a mesh content, so have to check that before the children if (input is MeshContent) { MeshContent mc = (MeshContent)input; CalcMinMax(mc); } parseChildren(ncc); ModelContent mc2 = base.Process(input, context); mc2.Tag = new BoundingBox(min, max); return(mc2); }
//foreach (ModelMesh meshPart in meshContent.Children) //{ //foreach mesh (essentially layer of the image) go through the mossitions //GeometryContent Geo = new GeometryContent(); //foreach(GeometryContent Geo2 in Geo.Vertices.Positions) private void FindVectorValues(NodeContentCollection nodeContentCollection, bool Alternative) { //for each content node in the collection of content foreach (NodeContent nodeContent in nodeContentCollection) { //values local for each mesh made //finds the minimum and maximum vectors (min and max pts) in a model //temp bounding box made for a single mesh BoundingBox TempBox; if (nodeContent is MeshContent) { //collect Content of this mesh layer MeshContent meshContent = (MeshContent)nodeContent; float MinX = float.MaxValue; float MinY = float.MaxValue; float MinZ = float.MaxValue; float MaxX = float.MinValue; float MaxY = float.MinValue; float MaxZ = float.MinValue; //new system for going through meshes foreach (GeometryContent Geo in meshContent.Geometry) { //MinX = float.MaxValue; //MinY = float.MaxValue; //MinZ = float.MaxValue; //MaxX = float.MinValue; //MaxY = float.MinValue; //MaxZ = float.MinValue; for (int cntr = 0; cntr < Geo.Vertices.VertexCount; cntr++) { Vector3 LocalVector = Geo.Vertices.Positions[cntr]; if (LocalVector.X < MinX) MinX = LocalVector.X; if (LocalVector.Y < MinY) MinY = LocalVector.Y; if (LocalVector.Z < MinZ) MinZ = LocalVector.Z; //now max vars if (LocalVector.X > MaxX) MaxX = LocalVector.X; if (LocalVector.Y > MaxY) MaxY = LocalVector.Y; if (LocalVector.Z > MaxZ) MaxZ = LocalVector.Z; } //found min and max values for one box, now it's time to add that single mesh box into the final box TempBox = new BoundingBox(new Vector3(MinX, MinY, MinZ), new Vector3(MaxX, MaxY, MaxZ)); CollisionBox = BoundingBox.CreateMerged(CollisionBox, TempBox); } //CollisionBox = new BoundingBox(new Vector3(MinX, MinY, MinZ), new Vector3(MaxX, MaxY, MaxZ)); } } }
//calculates the max and min 3D values of the Model's mesh to make the bounding box //I iz good at Maths; actually the math is BASIC //NodeCollection is the private void FindVectorValues(NodeContentCollection nodeContentCollection) { //for each content node in the collection of content foreach (NodeContent nodeContent in nodeContentCollection) { //values local for each mesh made //finds the minimum and maximum vectors (min and max pts) in a model float MinX = float.MaxValue; float MinY = float.MaxValue; float MinZ = float.MaxValue; float MaxX = float.MinValue; float MaxY = float.MinValue; float MaxZ = float.MinValue; //temp bounding box made for a single mesh BoundingBox TempBox; //actually finds min and max size if it's a mesh and not some sort of mesh in a mesh (parent and child meshes/nodes) if (nodeContent is MeshContent) { //collect Content of this mesh layer MeshContent meshContent = (MeshContent)nodeContent; //ModelMesh Model = (ModelMesh)meshContent; foreach (Vector3 LocalVector in meshContent.Positions) { if (LocalVector.X < MinX) MinX = LocalVector.X; if (LocalVector.Y < MinY) MinY = LocalVector.Y; if (LocalVector.Z < MinZ) MinZ = LocalVector.Z; //now max vars if (LocalVector.X > MaxX) MaxX = LocalVector.X; if (LocalVector.Y > MaxY) MaxY = LocalVector.Y; if (LocalVector.Z > MaxZ) MaxZ = LocalVector.Z; } //found min and max values for one box, now it's time to add that single mesh box into the final box TempBox = new BoundingBox(new Vector3(MinX, MinY, MinZ), new Vector3(MaxX, MaxY, MaxZ)); CollisionBox = BoundingBox.CreateMerged(CollisionBox, TempBox); } /* else { //This method is recursive if there are child meshes FindVectorValues(nodeContent.Children); }*/ } }
/// <summary> /// Creates an instance of NodeContent. /// </summary> public NodeContent() { children = new NodeContentCollection(this); animations = new AnimationContentDictionary(); }
/// <summary> /// Creates an instance of NodeContent. /// </summary> public NodeContent() { children = new NodeContentCollection(this); animations = new AnimationContentDictionary(); Transform = Matrix.Identity; }
public NodeContent() { this.children = new NodeContentCollection(this); }
//calculates the max and min 3D values of the Model's mesh to make the bounding box //I iz good at Maths; actually the math is BASIC //NodeCollection is the private void FindVectorValues(NodeContentCollection nodeContentCollection) { //for each content node in the collection of content foreach (NodeContent nodeContent in nodeContentCollection) { //actually finds min and max size if it's a mesh and not some sort of mesh in a mesh (parent and child meshes/nodes) if (nodeContent is MeshContent) { //collect Content of this mesh layer MeshContent meshContent = (MeshContent)nodeContent; //foreach mesh (essentially layer of the image) go through the mossitions foreach (Vector3 LocalVector in meshContent.Positions) { if (LocalVector.X < MinX) MinX = LocalVector.X; if (LocalVector.Y < MinY) MinY = LocalVector.Y; if (LocalVector.Z < MinZ) MinZ = LocalVector.Z; // if (LocalVector.X > MaxX) MaxX = LocalVector.X; if (LocalVector.Y > MaxY) MaxY = LocalVector.Y; if (LocalVector.Z > MaxZ) MaxZ = LocalVector.Z; } } else { //This method is recursive if there are child meshes FindVectorValues(nodeContent.Children); } } }