/// <summary> /// Propagate our global transform to the sub meshes, recomputing their bounding boxes /// </summary> private void UpdateSubMeshes() { Helpers.TransformBoundingBox(ref _localBoundingBox, ref _transform, out _globalBoundingBox); if (_model != null) { for (int i = 0; i < _model.Bones.Count; i++) { _transforms[i] = _model.Bones[i].Transform * _transform; } for (int i = 0; i < _subMeshes.Count; i++) { SubMesh subMesh = _subMeshes[i]; //compute the global transform for this submesh subMesh.GlobalTransform = _transforms[_model.Meshes[subMesh._modelIndex].ParentBone.Index]; MeshMetadata.SubMeshMetadata metadata = subMesh._metadata; BoundingBox source = metadata.BoundingBox; //compute the global bounding box Helpers.TransformBoundingBox(ref source, ref _transform, out subMesh.GlobalBoundingBox); subMesh.GlobalBoundingSphere = BoundingSphere.CreateFromBoundingBox(subMesh.GlobalBoundingBox); } } }
private BoundingBox ComputeBoundingBox(NodeContent input, ref BoundingBox aabb, MeshMetadata metadata) { BoundingBox boundingBox; if (input is MeshContent) { MeshContent mc = (MeshContent)input; MeshHelper.TransformScene(mc, mc.Transform); mc.Transform = Matrix.Identity; boundingBox = BoundingBox.CreateFromPoints(mc.Positions); //create sub mesh information MeshMetadata.SubMeshMetadata subMeshMetadata = new MeshMetadata.SubMeshMetadata(); subMeshMetadata.BoundingBox = boundingBox; subMeshMetadata.RenderQueue = _renderQueue; subMeshMetadata.CastShadows = CastShadows; metadata.AddSubMeshMetadata(subMeshMetadata); if (metadata.SubMeshesMetadata.Count > 1) boundingBox = BoundingBox.CreateMerged(boundingBox, aabb); } else { boundingBox = aabb; } foreach (NodeContent c in input.Children) { boundingBox = BoundingBox.CreateMerged(boundingBox, ComputeBoundingBox(c, ref boundingBox, metadata)); } return boundingBox; }