protected void EnableBVHCulling(float deltaTime, Camera camera, GeometryDescriptor <VertexPositionNormalTextureTangentBitangent> PNTTBGeometryDescriptor, GeometryDescriptor <VertexPositionNormal> PNGeometryDescriptor, GeometryDescriptor <VertexPositionTexture> PTGeometryDescriptor, GeometryDescriptor <VertexPositionColor> PCGeometryDescriptor, GeometryDescriptor <VertexPosition> PGeometryDescriptor) { var PNTTBMeshBVHArray = PNTTBGeometryDescriptor.MeshBVHArray; var PNMeshBVHArray = PNGeometryDescriptor.MeshBVHArray; var PTMeshBVHArray = PTGeometryDescriptor.MeshBVHArray; var PCMeshBVHArray = PCGeometryDescriptor.MeshBVHArray; var PMeshBVHArray = PGeometryDescriptor.MeshBVHArray; if (PNTTBMeshBVHArray.Length > CULLING_THRESH) { invalidateAABB(PNTTBMeshBVHArray); BVHRuntime.TraverseWithFrustumForMesh(_bvhRuntimeNodesPNTTB, PNTTBMeshBVHArray, _bvhTraversalStack, ref camera.ViewProjectionMatirx); } if (PNMeshBVHArray.Length > CULLING_THRESH) { invalidateAABB(PNMeshBVHArray); BVHRuntime.TraverseWithFrustumForMesh(_bvhRuntimeNodesPN, PNMeshBVHArray, _bvhTraversalStack, ref camera.ViewProjectionMatirx); } if (PTMeshBVHArray.Length > CULLING_THRESH) { invalidateAABB(PTMeshBVHArray); BVHRuntime.TraverseWithFrustumForMesh(_bvhRuntimeNodesPT, PTMeshBVHArray, _bvhTraversalStack, ref camera.ViewProjectionMatirx); } if (PCMeshBVHArray.Length > CULLING_THRESH) { invalidateAABB(PCMeshBVHArray); BVHRuntime.TraverseWithFrustumForMesh(_bvhRuntimeNodesPC, PCMeshBVHArray, _bvhTraversalStack, ref camera.ViewProjectionMatirx); } }
public static GameObject Create(GeometryDescriptor descriptor) { var go = GameObject.CreatePrimitive(descriptor.type); go.name = descriptor.type.ToString(); if (!descriptor.hasCollider) { var collider = go.GetComponent <Collider>(); GameObject.Destroy(collider); } var mat = go.FindOrAddTypeInComponentsAndChildren <AutoMaterial>(); mat.Init(descriptor.shader); var autoSpace = go.FindOrAddTypeInComponentsAndChildren <TextureAutoSpace>(); autoSpace.Init(descriptor.space, descriptor.autoSpace, descriptor.target); autoSpace.Update(); if (descriptor.enableTouch) { go.FindOrAddTypeInComponentsAndChildren <TouchMesh>(); } return(go); }
protected void BuildBVH(GeometryDescriptor <VertexPositionNormalTextureTangentBitangent> PNTTBGeometryDescriptor, GeometryDescriptor <VertexPositionNormal> PNGeometryDescriptor, GeometryDescriptor <VertexPositionTexture> PTGeometryDescriptor, GeometryDescriptor <VertexPositionColor> PCGeometryDescriptor, GeometryDescriptor <VertexPosition> PGeometryDescriptor) { var splitMethod = SplitMethods.SAH; var PNTTBMeshBVHArray = PNTTBGeometryDescriptor.MeshBVHArray; var PNMeshBVHArray = PNGeometryDescriptor.MeshBVHArray; var PTMeshBVHArray = PTGeometryDescriptor.MeshBVHArray; var PCMeshBVHArray = PCGeometryDescriptor.MeshBVHArray; var PMeshBVHArray = PGeometryDescriptor.MeshBVHArray; var tuplePNTTB = BVHTreeBuilder <MeshBVH <VertexPositionNormalTextureTangentBitangent> > .Build(PNTTBMeshBVHArray, splitMethod); BVHTree PNTTBTree = tuplePNTTB.Item1; PNTTBMeshBVHArray = tuplePNTTB.Item2; int PNTTBTotalNodes = tuplePNTTB.Item3; var tuplePN = BVHTreeBuilder <MeshBVH <VertexPositionNormal> > .Build(PNMeshBVHArray, splitMethod); BVHTree PNTree = tuplePN.Item1; PNMeshBVHArray = tuplePN.Item2; int PNTotalNodes = tuplePN.Item3; var tuplePT = BVHTreeBuilder <MeshBVH <VertexPositionTexture> > .Build(PTMeshBVHArray, splitMethod); BVHTree PTTree = tuplePT.Item1; PTMeshBVHArray = tuplePT.Item2; int PTTotalNodes = tuplePT.Item3; var tuplePC = BVHTreeBuilder <MeshBVH <VertexPositionColor> > .Build(PCMeshBVHArray, splitMethod); BVHTree PCTree = tuplePC.Item1; PCMeshBVHArray = tuplePC.Item2; int PCTotalNodes = tuplePC.Item3; _bvhRuntimeNodesPNTTB = BVHRuntime.ConstructBVHRuntime(PNTTBTree, PNTTBTotalNodes); _bvhRuntimeNodesPN = BVHRuntime.ConstructBVHRuntime(PNTree, PNTotalNodes); _bvhRuntimeNodesPT = BVHRuntime.ConstructBVHRuntime(PTTree, PTTotalNodes); _bvhRuntimeNodesPC = BVHRuntime.ConstructBVHRuntime(PCTree, PCTotalNodes); var maxPrimitives = Math.Max(PNTTBMeshBVHArray.Length, Math.Max(PNMeshBVHArray.Length, Math.Max(PTMeshBVHArray.Length, PCMeshBVHArray.Length))); _bvhTraversalStack = new int[maxPrimitives]; }