public BvhTriangleMeshShape(StridingMeshInterface meshInterface, bool useQuantizedAabbCompression, bool buildBvh)
            : base(meshInterface)
        {
            m_bvh = null;
            m_ownsBvh = false;
            m_useQuantizedAabbCompression = useQuantizedAabbCompression;
            m_shapeType = BroadphaseNativeTypes.TRIANGLE_MESH_SHAPE_PROXYTYPE;
            //construct bvh from meshInterface
#if !DISABLE_BVH

            //IndexedVector3 bvhAabbMin = IndexedVector3.Zero, bvhAabbMax = IndexedVector3.Zero;
            //if (meshInterface.hasPremadeAabb())
            //{
            //    meshInterface.getPremadeAabb(ref bvhAabbMin, ref bvhAabbMax);
            //}
            //else
            //{
            //    meshInterface.calculateAabbBruteForce(ref bvhAabbMin, ref bvhAabbMax);
            //}
            if (buildBvh)
            {
                BuildOptimizedBvh();
            }
#endif //DISABLE_BVH
        }
Beispiel #2
0
 protected void BuildMeshParts(StridingMeshInterface meshInterface)
 {
     for (int i = 0; i < meshInterface.GetNumSubParts(); ++i)
     {
         GImpactMeshShapePart newpart = new GImpactMeshShapePart(meshInterface, i);
         m_mesh_parts.Add(newpart);
     }
 }
	    public ConvexTriangleMeshShape(StridingMeshInterface meshInterface, bool calcAabb)
        {
	        m_shapeType = BroadphaseNativeTypes.CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE;
            m_stridingMesh = meshInterface;
	        if ( calcAabb )
            {
		        RecalcLocalAabb();
            }
        }
 public ConvexTriangleMeshShape(StridingMeshInterface meshInterface, bool calcAabb)
 {
     m_shapeType    = BroadphaseNativeTypes.CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE;
     m_stridingMesh = meshInterface;
     if (calcAabb)
     {
         RecalcLocalAabb();
     }
 }
Beispiel #5
0
 public TrimeshPrimitiveManager(StridingMeshInterface meshInterface, int part)
 {
     m_meshInterface = meshInterface;
     m_part          = part;
     m_scale         = m_meshInterface.GetScaling();
     m_margin        = 0.1f;
     m_lock_count    = 0;
     vertexbase      = 0;
     numverts        = 0;
     stride          = 0;
     indexbase       = 0;
     indexstride     = 0;
     numfaces        = 0;
 }
Beispiel #6
0
 public TrimeshPrimitiveManager(TrimeshPrimitiveManager manager)
 {
     m_meshInterface = manager.m_meshInterface;
     m_part          = manager.m_part;
     m_margin        = manager.m_margin;
     m_scale         = manager.m_scale;
     m_lock_count    = 0;
     vertexbase      = 0;
     numverts        = 0;
     stride          = 0;
     indexbase       = 0;
     indexstride     = 0;
     numfaces        = 0;
 }
 public TriangleMeshShape(StridingMeshInterface meshInterface)
 {
     m_inConstructor = true;
     m_meshInterface = meshInterface;
     m_shapeType = BroadphaseNativeTypes.TRIANGLE_MESH_SHAPE_PROXYTYPE;
     if (meshInterface.HasPremadeAabb())
     {
         meshInterface.GetPremadeAabb(out m_localAabbMin, out m_localAabbMax);
     }
     else
     {
         RecalcLocalAabb();
     }
     m_inConstructor = false;
 }
Beispiel #8
0
 public TriangleMeshShape(StridingMeshInterface meshInterface)
 {
     m_inConstructor = true;
     m_meshInterface = meshInterface;
     m_shapeType     = BroadphaseNativeTypes.TRIANGLE_MESH_SHAPE_PROXYTYPE;
     if (meshInterface.HasPremadeAabb())
     {
         meshInterface.GetPremadeAabb(out m_localAabbMin, out m_localAabbMax);
     }
     else
     {
         RecalcLocalAabb();
     }
     m_inConstructor = false;
 }
        ///optionally pass in a larger bvh aabb, used for quantization. This allows for deformations within this aabb
        public BvhTriangleMeshShape(StridingMeshInterface meshInterface, bool useQuantizedAabbCompression, ref IndexedVector3 bvhAabbMin, ref IndexedVector3 bvhAabbMax, bool buildBvh)
            : base(meshInterface)
        {
            m_bvh     = null;
            m_ownsBvh = false;
            m_useQuantizedAabbCompression = useQuantizedAabbCompression;
            m_shapeType = BroadphaseNativeTypes.TRIANGLE_MESH_SHAPE_PROXYTYPE;
#if !DISABLE_BVH
            if (buildBvh)
            {
                m_bvh = new OptimizedBvh();

                m_bvh.Build(meshInterface, m_useQuantizedAabbCompression, ref bvhAabbMin, ref bvhAabbMax);
                m_ownsBvh = true;
            }
#endif //DISABLE_BVH
        }
Beispiel #10
0
        public void Refit(StridingMeshInterface meshInterface, ref IndexedVector3 aabbMin, ref IndexedVector3 aabbMax)
        {
            if (m_useQuantization)
            {
                SetQuantizationValues(ref aabbMin, ref aabbMax);

                UpdateBvhNodes(meshInterface, 0, m_curNodeIndex, 0);

                ///now update all subtree headers

                for (int i = 0; i < m_SubtreeHeaders.Count; i++)
                {
                    BvhSubtreeInfo subtree = m_SubtreeHeaders[i];
                    subtree.SetAabbFromQuantizeNode(m_quantizedContiguousNodes[subtree.m_rootNodeIndex]);
                }
            }
            else
            {
            }
        }
Beispiel #11
0
        public void RefitPartial(StridingMeshInterface meshInterface, ref IndexedVector3 aabbMin, ref IndexedVector3 aabbMax)
        {
            //incrementally initialize quantization values
            if (!m_useQuantization)
            {
                return;
            }
            Debug.Assert(m_useQuantization);

            Debug.Assert(aabbMin.X > m_bvhAabbMin.X);
            Debug.Assert(aabbMin.Y > m_bvhAabbMin.Y);
            Debug.Assert(aabbMin.Z > m_bvhAabbMin.Z);

            Debug.Assert(aabbMax.X < m_bvhAabbMax.X);
            Debug.Assert(aabbMax.Y < m_bvhAabbMax.Y);
            Debug.Assert(aabbMax.Z < m_bvhAabbMax.Z);

            ///we should update all quantization values, using updateBvhNodes(meshInterface);
            ///but we only update chunks that overlap the given aabb

            UShortVector3 quantizedQueryAabbMin;
            UShortVector3 quantizedQueryAabbMax;

            Quantize(out quantizedQueryAabbMin, ref aabbMin, false);
            Quantize(out quantizedQueryAabbMax, ref aabbMax, true);

            for (int i = 0; i < m_SubtreeHeaders.Count; i++)
            {
                BvhSubtreeInfo subtree = m_SubtreeHeaders[i];

                //PCK: unsigned instead of bool
                bool overlap = AabbUtil2.TestQuantizedAabbAgainstQuantizedAabb(ref quantizedQueryAabbMin, ref quantizedQueryAabbMax, ref subtree.m_quantizedAabbMin, ref subtree.m_quantizedAabbMax);
                if (overlap)
                {
                    UpdateBvhNodes(meshInterface, subtree.m_rootNodeIndex, subtree.m_rootNodeIndex + subtree.m_subtreeSize, i);
                    subtree.SetAabbFromQuantizeNode(m_quantizedContiguousNodes[subtree.m_rootNodeIndex]);
                }
            }
        }
        public BvhTriangleMeshShape(StridingMeshInterface meshInterface, bool useQuantizedAabbCompression, bool buildBvh)
            : base(meshInterface)
        {
            m_bvh     = null;
            m_ownsBvh = false;
            m_useQuantizedAabbCompression = useQuantizedAabbCompression;
            m_shapeType = BroadphaseNativeTypes.TRIANGLE_MESH_SHAPE_PROXYTYPE;
            //construct bvh from meshInterface
#if !DISABLE_BVH
            //IndexedVector3 bvhAabbMin = IndexedVector3.Zero, bvhAabbMax = IndexedVector3.Zero;
            //if (meshInterface.hasPremadeAabb())
            //{
            //    meshInterface.getPremadeAabb(ref bvhAabbMin, ref bvhAabbMax);
            //}
            //else
            //{
            //    meshInterface.calculateAabbBruteForce(ref bvhAabbMin, ref bvhAabbMax);
            //}
            if (buildBvh)
            {
                BuildOptimizedBvh();
            }
#endif //DISABLE_BVH
        }
        public void Refit(StridingMeshInterface meshInterface, ref IndexedVector3 aabbMin, ref IndexedVector3 aabbMax)
        {
            if (m_useQuantization)
            {

                SetQuantizationValues(ref aabbMin, ref aabbMax);

                UpdateBvhNodes(meshInterface, 0, m_curNodeIndex, 0);

                ///now update all subtree headers

                for (int i = 0; i < m_SubtreeHeaders.Count; i++)
                {
                    BvhSubtreeInfo subtree = m_SubtreeHeaders[i];
                    subtree.SetAabbFromQuantizeNode(m_quantizedContiguousNodes[subtree.m_rootNodeIndex]);
                }
            }
            else
            {

            }
        }
Beispiel #14
0
 protected void BuildMeshParts(StridingMeshInterface meshInterface)
 {
     for (int i = 0; i < meshInterface.GetNumSubParts(); ++i)
     {
         GImpactMeshShapePart newpart = new GImpactMeshShapePart(meshInterface, i);
         m_mesh_parts.Add(newpart);
     }
 }
 public void Initialize(ITriangleCallback callback, StridingMeshInterface meshInterface)
 {
     m_meshInterface = meshInterface;
     m_callback      = callback;
 }
Beispiel #16
0
        public void Build(StridingMeshInterface triangles, bool useQuantizedAabbCompression, ref IndexedVector3 bvhAabbMin, ref IndexedVector3 bvhAabbMax)
        {
            int numLeafNodes = 0;

            m_useQuantization = useQuantizedAabbCompression;


            if (m_useQuantization)
            {
                //initialize quantization values
                SetQuantizationValues(ref bvhAabbMin, ref bvhAabbMax);

                QuantizedNodeTriangleCallback callback = new QuantizedNodeTriangleCallback(m_quantizedLeafNodes, this);

                triangles.InternalProcessAllTriangles(callback, ref m_bvhAabbMin, ref m_bvhAabbMax);

                //now we have an array of leafnodes in m_leafNodes
                numLeafNodes = m_quantizedLeafNodes.Count;

                //m_quantizedContiguousNodes.resize(2*numLeafNodes);
                m_quantizedContiguousNodes.Capacity = 2 * numLeafNodes;
            }
            else
            {
                NodeTriangleCallback callback = new NodeTriangleCallback(m_leafNodes);

                IndexedVector3 aabbMin = MathUtil.MIN_VECTOR;
                IndexedVector3 aabbMax = MathUtil.MAX_VECTOR;

                triangles.InternalProcessAllTriangles(callback, ref aabbMin, ref aabbMax);

                //now we have an array of leafnodes in m_leafNodes
                numLeafNodes = m_leafNodes.Count;

                //m_contiguousNodes.resize(2*numLeafNodes);
                m_contiguousNodes.Capacity = 2 * numLeafNodes;
            }

            m_curNodeIndex = 0;

            BuildTree(0, numLeafNodes);

            //for (int i = 0; i < m_quantizedContiguousNodes.Count; ++i)
            //{
            //    QuantizedBvhNode bvhn = m_quantizedContiguousNodes[i];
            //}


            ///if the entire tree is small then subtree size, we need to create a header info for the tree
            if (m_useQuantization && m_SubtreeHeaders.Count == 0)
            {
                BvhSubtreeInfo subtree = new BvhSubtreeInfo();
                m_SubtreeHeaders.Add(subtree);

                subtree.SetAabbFromQuantizeNode(m_quantizedContiguousNodes[0]);
                subtree.m_rootNodeIndex = 0;
                subtree.m_subtreeSize   = m_quantizedContiguousNodes[0].IsLeafNode() ? 1 : m_quantizedContiguousNodes[0].GetEscapeIndex();
            }

            //PCK: update the copy of the size
            m_subtreeHeaderCount = m_SubtreeHeaders.Count;

            //PCK: clear m_quantizedLeafNodes and m_leafNodes, they are temporary
            m_quantizedLeafNodes.Clear();
            m_leafNodes.Clear();
        }
        }                                  // for pool

        public MyNodeOverlapCallback(ITriangleCallback callback, StridingMeshInterface meshInterface)
        {
            m_meshInterface = meshInterface;
            m_callback      = callback;
        }
	    public void	Build(StridingMeshInterface triangles,bool useQuantizedAabbCompression, ref IndexedVector3 bvhAabbMin, ref IndexedVector3 bvhAabbMax)
        {
	        int numLeafNodes = 0;
            m_useQuantization = useQuantizedAabbCompression;

        	
	        if (m_useQuantization)
	        {

		        //initialize quantization values
		        SetQuantizationValues(ref bvhAabbMin,ref bvhAabbMax);

		        QuantizedNodeTriangleCallback callback = new QuantizedNodeTriangleCallback(m_quantizedLeafNodes,this);
        	
		        triangles.InternalProcessAllTriangles(callback,ref m_bvhAabbMin,ref m_bvhAabbMax);

		        //now we have an array of leafnodes in m_leafNodes
		        numLeafNodes = m_quantizedLeafNodes.Count;

                //m_quantizedContiguousNodes.resize(2*numLeafNodes);
                m_quantizedContiguousNodes.Capacity = 2 * numLeafNodes;
	        } 
            else
	        {
		        NodeTriangleCallback callback = new NodeTriangleCallback(m_leafNodes);

		        IndexedVector3 aabbMin = MathUtil.MIN_VECTOR;
		        IndexedVector3 aabbMax = MathUtil.MAX_VECTOR;

		        triangles.InternalProcessAllTriangles(callback,ref aabbMin,ref aabbMax);

		        //now we have an array of leafnodes in m_leafNodes
		        numLeafNodes = m_leafNodes.Count;

                //m_contiguousNodes.resize(2*numLeafNodes);
                m_contiguousNodes.Capacity = 2 * numLeafNodes;
	        }

	        m_curNodeIndex = 0;

	        BuildTree(0,numLeafNodes);

            //for (int i = 0; i < m_quantizedContiguousNodes.Count; ++i)
            //{
            //    QuantizedBvhNode bvhn = m_quantizedContiguousNodes[i];
            //}


	        ///if the entire tree is small then subtree size, we need to create a header info for the tree
	        if(m_useQuantization && m_SubtreeHeaders.Count == 0)
	        {

                BvhSubtreeInfo subtree = new BvhSubtreeInfo();
                m_SubtreeHeaders.Add(subtree);

		        subtree.SetAabbFromQuantizeNode(m_quantizedContiguousNodes[0]);
		        subtree.m_rootNodeIndex = 0;
		        subtree.m_subtreeSize = m_quantizedContiguousNodes[0].IsLeafNode() ? 1 : m_quantizedContiguousNodes[0].GetEscapeIndex();
	        }

	        //PCK: update the copy of the size
	        m_subtreeHeaderCount = m_SubtreeHeaders.Count;

	        //PCK: clear m_quantizedLeafNodes and m_leafNodes, they are temporary
	        m_quantizedLeafNodes.Clear();
	        m_leafNodes.Clear();
        }
Beispiel #19
0
 public GImpactMeshShapePart(StridingMeshInterface meshInterface, int part)
 {
     m_primitive_manager.m_meshInterface = meshInterface;
     m_primitive_manager.m_part = part;
     m_box_set.SetPrimitiveManager(m_primitive_manager);
 }
        ///optionally pass in a larger bvh aabb, used for quantization. This allows for deformations within this aabb
        public BvhTriangleMeshShape(StridingMeshInterface meshInterface, bool useQuantizedAabbCompression, ref IndexedVector3 bvhAabbMin, ref IndexedVector3 bvhAabbMax, bool buildBvh)
            : base(meshInterface)
        {
            m_bvh = null;
            m_ownsBvh = false;
            m_useQuantizedAabbCompression = useQuantizedAabbCompression;
            m_shapeType = BroadphaseNativeTypes.TRIANGLE_MESH_SHAPE_PROXYTYPE;
#if !DISABLE_BVH

            if (buildBvh)
            {
                m_bvh = new OptimizedBvh();

                m_bvh.Build(meshInterface, m_useQuantizedAabbCompression, ref bvhAabbMin, ref bvhAabbMax);
                m_ownsBvh = true;
            }

#endif //DISABLE_BVH

        }
	    public void	RefitPartial(StridingMeshInterface meshInterface,ref IndexedVector3 aabbMin, ref IndexedVector3 aabbMax)
        {
	        //incrementally initialize quantization values
            if (!m_useQuantization)
            {
                return;
            }
	        Debug.Assert(m_useQuantization);

	        Debug.Assert(aabbMin.X > m_bvhAabbMin.X);
	        Debug.Assert(aabbMin.Y > m_bvhAabbMin.Y);
	        Debug.Assert(aabbMin.Z > m_bvhAabbMin.Z);

	        Debug.Assert(aabbMax.X < m_bvhAabbMax.X);
	        Debug.Assert(aabbMax.Y < m_bvhAabbMax.Y);
	        Debug.Assert(aabbMax.Z < m_bvhAabbMax.Z);

	        ///we should update all quantization values, using updateBvhNodes(meshInterface);
	        ///but we only update chunks that overlap the given aabb
        	
	        UShortVector3 quantizedQueryAabbMin;
            UShortVector3 quantizedQueryAabbMax;

	        Quantize(out quantizedQueryAabbMin,ref aabbMin,false);
	        Quantize(out quantizedQueryAabbMax,ref aabbMax,true);

	        for (int i=0;i<m_SubtreeHeaders.Count;i++)
	        {
		        BvhSubtreeInfo subtree = m_SubtreeHeaders[i];

		        //PCK: unsigned instead of bool
		        bool overlap = AabbUtil2.TestQuantizedAabbAgainstQuantizedAabb(ref quantizedQueryAabbMin,ref quantizedQueryAabbMax,ref subtree.m_quantizedAabbMin,ref subtree.m_quantizedAabbMax);
		        if (overlap)
		        {
			        UpdateBvhNodes(meshInterface,subtree.m_rootNodeIndex,subtree.m_rootNodeIndex+subtree.m_subtreeSize,i);
			        subtree.SetAabbFromQuantizeNode(m_quantizedContiguousNodes[subtree.m_rootNodeIndex]);
		        }
	        }
        }
        public MyNodeOverlapCallback() { } // for pool
        public MyNodeOverlapCallback(ITriangleCallback callback, StridingMeshInterface meshInterface)
        {
            m_meshInterface = meshInterface;
            m_callback = callback;

        }
Beispiel #23
0
 public GImpactMeshShapePart(StridingMeshInterface meshInterface, int part)
 {
     m_primitive_manager.m_meshInterface = meshInterface;
     m_primitive_manager.m_part          = part;
     m_box_set.SetPrimitiveManager(m_primitive_manager);
 }
Beispiel #24
0
 public GImpactMeshShape(StridingMeshInterface meshInterface)
 {
     m_meshInterface = meshInterface;
     BuildMeshParts(meshInterface);
 }
Beispiel #25
0
 public TrimeshPrimitiveManager(TrimeshPrimitiveManager manager)
 {
     m_meshInterface = manager.m_meshInterface;
     m_part = manager.m_part;
     m_margin = manager.m_margin;
     m_scale = manager.m_scale;
     m_lock_count = 0;
     vertexbase = 0;
     numverts = 0;
     stride = 0;
     indexbase = 0;
     indexstride = 0;
     numfaces = 0;
 }
Beispiel #26
0
 public GImpactMeshShape(StridingMeshInterface meshInterface)
 {
     m_meshInterface = meshInterface;
     BuildMeshParts(meshInterface);
 }
        public void UpdateBvhNodes(StridingMeshInterface meshInterface, int firstNode, int endNode, int index)
        {
            //(void)index;

	            Debug.Assert(m_useQuantization);

	        int curNodeSubPart=-1;

	        //get access info to trianglemesh data
		    Object vertexBaseObject = null;
		    int numverts = 0;
		    PHY_ScalarType type = PHY_ScalarType.PHY_INTEGER;
		    int stride = 0;
            Object indexBaseObject = null;
		    int indexstride = 0;
		    int numfaces = 0;
		    PHY_ScalarType indicestype = PHY_ScalarType.PHY_INTEGER;

		    IndexedVector3[]	triangleVerts = new IndexedVector3[3];
		    IndexedVector3	aabbMin,aabbMax;
		    IndexedVector3 meshScaling = meshInterface.GetScaling();
    		

		    for (int i=endNode-1;i>=firstNode;i--)
		    {
			    QuantizedBvhNode curNode = m_quantizedContiguousNodes[i];
			    if (curNode.IsLeafNode())
			    {
				    //recalc aabb from triangle data
				    int nodeSubPart = curNode.GetPartId();
				    int nodeTriangleIndex = curNode.GetTriangleIndex();
				    if (nodeSubPart != curNodeSubPart)
				    {
					    if (curNodeSubPart >= 0)
                        {
						    meshInterface.UnLockReadOnlyVertexBase(curNodeSubPart);
                        }
					    meshInterface.GetLockedReadOnlyVertexIndexBase(out vertexBaseObject,out numverts,out type,out stride,out indexBaseObject,out indexstride,out numfaces,out indicestype,nodeSubPart);

					    curNodeSubPart = nodeSubPart;
					    Debug.Assert(indicestype==PHY_ScalarType.PHY_INTEGER);
				    }
				    //triangles.getLockedReadOnlyVertexIndexBase(vertexBase,numVerts,
                    int gfxBaseIndex = nodeTriangleIndex*indexstride;
                    //unsigned int* gfxbase = (unsigned int*)(indexbase+nodeTriangleIndex*indexstride);
                    int[] indexBase = (indexBaseObject as ObjectArray<int>).GetRawArray();

                    if (vertexBaseObject is IList<IndexedVector3>)
                    {
                        IndexedVector3[] vertexBase = (vertexBaseObject as ObjectArray<IndexedVector3>).GetRawArray();
                        for (int j = 2; j >= 0; j--)
                        {
                            int graphicsIndex = indexBase[gfxBaseIndex+j];
                            if (type == PHY_ScalarType.PHY_FLOAT)
                            {

                                triangleVerts[j] = vertexBase[graphicsIndex] * meshScaling;
                            }
                            else
                            {
                                Debug.Assert(false, "Unsupported Type");
                            }
                        }
                    }
                    else if (vertexBaseObject is ObjectArray<float>)
                    {
                        float[] vertexBase = (vertexBaseObject as ObjectArray<float>).GetRawArray() ;
                        for (int j = 2; j >= 0; j--)
                        {
                            //int graphicsindex = indicestype==PHY_ScalarType.PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
                            int graphicsIndex = indexBase[gfxBaseIndex+j];
                            if (type == PHY_ScalarType.PHY_FLOAT)
                            {
                                int graphicsBaseIndex = (graphicsIndex * stride);
                                //IList<float> graphicsbase = (float*)(vertexbase+graphicsindex*stride);
                                triangleVerts[j] = new IndexedVector3(
                                    vertexBase[graphicsBaseIndex] * meshScaling.X,
                                    vertexBase[graphicsBaseIndex + 1] * meshScaling.Y,
                                    vertexBase[graphicsBaseIndex + 2] * meshScaling.Z);
                            }
                            else
                            {
                                Debug.Assert(false, "Unsupported Type");
                            }
                        }


                    }
                    else
                    {
                        Debug.Assert(false, "Unsupported Type");
                    }
    				
				    aabbMin = MathUtil.MAX_VECTOR;
				    aabbMax = MathUtil.MIN_VECTOR; 
				    MathUtil.VectorMin(ref triangleVerts[0],ref aabbMin);
				    MathUtil.VectorMax(ref triangleVerts[0],ref aabbMax);
				    MathUtil.VectorMin(ref triangleVerts[1],ref aabbMin);
				    MathUtil.VectorMax(ref triangleVerts[1],ref aabbMax);
				    MathUtil.VectorMin(ref triangleVerts[2],ref aabbMin);
				    MathUtil.VectorMax(ref triangleVerts[2],ref aabbMax);

				    Quantize(out curNode.m_quantizedAabbMin,ref aabbMin,false);
				    Quantize(out curNode.m_quantizedAabbMax,ref aabbMax,true);
    				
			    } 
                else
			    {
				    //combine aabb from both children

				    QuantizedBvhNode leftChildNode = m_quantizedContiguousNodes[i+1];
    				
				    QuantizedBvhNode rightChildNode = leftChildNode.IsLeafNode() ? m_quantizedContiguousNodes[i+2] :
					    m_quantizedContiguousNodes[i+1+leftChildNode.GetEscapeIndex()];
    				

				    {
                        curNode.m_quantizedAabbMin = leftChildNode.m_quantizedAabbMin;
                        curNode.m_quantizedAabbMin.Min(ref rightChildNode.m_quantizedAabbMin);

                        curNode.m_quantizedAabbMax = leftChildNode.m_quantizedAabbMax;
                        curNode.m_quantizedAabbMax.Max(ref rightChildNode.m_quantizedAabbMax);
				    }
			    }

		    }

		    if (curNodeSubPart >= 0)
			    meshInterface.UnLockReadOnlyVertexBase(curNodeSubPart);




        }
Beispiel #28
0
        public void UpdateBvhNodes(StridingMeshInterface meshInterface, int firstNode, int endNode, int index)
        {
            //(void)index;

            Debug.Assert(m_useQuantization);

            int curNodeSubPart = -1;

            //get access info to trianglemesh data
            Object         vertexBaseObject = null;
            int            numverts         = 0;
            PHY_ScalarType type             = PHY_ScalarType.PHY_INTEGER;
            int            stride           = 0;
            Object         indexBaseObject  = null;
            int            indexstride      = 0;
            int            numfaces         = 0;
            PHY_ScalarType indicestype      = PHY_ScalarType.PHY_INTEGER;

            IndexedVector3[] triangleVerts = new IndexedVector3[3];
            IndexedVector3   aabbMin, aabbMax;
            IndexedVector3   meshScaling = meshInterface.GetScaling();


            for (int i = endNode - 1; i >= firstNode; i--)
            {
                QuantizedBvhNode curNode = m_quantizedContiguousNodes[i];
                if (curNode.IsLeafNode())
                {
                    //recalc aabb from triangle data
                    int nodeSubPart       = curNode.GetPartId();
                    int nodeTriangleIndex = curNode.GetTriangleIndex();
                    if (nodeSubPart != curNodeSubPart)
                    {
                        if (curNodeSubPart >= 0)
                        {
                            meshInterface.UnLockReadOnlyVertexBase(curNodeSubPart);
                        }
                        meshInterface.GetLockedReadOnlyVertexIndexBase(out vertexBaseObject, out numverts, out type, out stride, out indexBaseObject, out indexstride, out numfaces, out indicestype, nodeSubPart);

                        curNodeSubPart = nodeSubPart;
                        Debug.Assert(indicestype == PHY_ScalarType.PHY_INTEGER);
                    }
                    //triangles.getLockedReadOnlyVertexIndexBase(vertexBase,numVerts,
                    int gfxBaseIndex = nodeTriangleIndex * indexstride;
                    //unsigned int* gfxbase = (unsigned int*)(indexbase+nodeTriangleIndex*indexstride);
                    int[] indexBase = (indexBaseObject as ObjectArray <int>).GetRawArray();

                    if (vertexBaseObject is IList <IndexedVector3> )
                    {
                        IndexedVector3[] vertexBase = (vertexBaseObject as ObjectArray <IndexedVector3>).GetRawArray();
                        for (int j = 2; j >= 0; j--)
                        {
                            int graphicsIndex = indexBase[gfxBaseIndex + j];
                            if (type == PHY_ScalarType.PHY_FLOAT)
                            {
                                triangleVerts[j] = vertexBase[graphicsIndex] * meshScaling;
                            }
                            else
                            {
                                Debug.Assert(false, "Unsupported Type");
                            }
                        }
                    }
                    else if (vertexBaseObject is ObjectArray <float> )
                    {
                        float[] vertexBase = (vertexBaseObject as ObjectArray <float>).GetRawArray();
                        for (int j = 2; j >= 0; j--)
                        {
                            //int graphicsindex = indicestype==PHY_ScalarType.PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
                            int graphicsIndex = indexBase[gfxBaseIndex + j];
                            if (type == PHY_ScalarType.PHY_FLOAT)
                            {
                                int graphicsBaseIndex = (graphicsIndex * stride);
                                //IList<float> graphicsbase = (float*)(vertexbase+graphicsindex*stride);
                                triangleVerts[j] = new IndexedVector3(
                                    vertexBase[graphicsBaseIndex] * meshScaling.X,
                                    vertexBase[graphicsBaseIndex + 1] * meshScaling.Y,
                                    vertexBase[graphicsBaseIndex + 2] * meshScaling.Z);
                            }
                            else
                            {
                                Debug.Assert(false, "Unsupported Type");
                            }
                        }
                    }
                    else
                    {
                        Debug.Assert(false, "Unsupported Type");
                    }

                    aabbMin = MathUtil.MAX_VECTOR;
                    aabbMax = MathUtil.MIN_VECTOR;
                    MathUtil.VectorMin(ref triangleVerts[0], ref aabbMin);
                    MathUtil.VectorMax(ref triangleVerts[0], ref aabbMax);
                    MathUtil.VectorMin(ref triangleVerts[1], ref aabbMin);
                    MathUtil.VectorMax(ref triangleVerts[1], ref aabbMax);
                    MathUtil.VectorMin(ref triangleVerts[2], ref aabbMin);
                    MathUtil.VectorMax(ref triangleVerts[2], ref aabbMax);

                    Quantize(out curNode.m_quantizedAabbMin, ref aabbMin, false);
                    Quantize(out curNode.m_quantizedAabbMax, ref aabbMax, true);
                }
                else
                {
                    //combine aabb from both children

                    QuantizedBvhNode leftChildNode = m_quantizedContiguousNodes[i + 1];

                    QuantizedBvhNode rightChildNode = leftChildNode.IsLeafNode() ? m_quantizedContiguousNodes[i + 2] :
                                                      m_quantizedContiguousNodes[i + 1 + leftChildNode.GetEscapeIndex()];


                    {
                        curNode.m_quantizedAabbMin = leftChildNode.m_quantizedAabbMin;
                        curNode.m_quantizedAabbMin.Min(ref rightChildNode.m_quantizedAabbMin);

                        curNode.m_quantizedAabbMax = leftChildNode.m_quantizedAabbMax;
                        curNode.m_quantizedAabbMax.Max(ref rightChildNode.m_quantizedAabbMax);
                    }
                }
            }

            if (curNodeSubPart >= 0)
            {
                meshInterface.UnLockReadOnlyVertexBase(curNodeSubPart);
            }
        }
 public void Initialize(ITriangleCallback callback, StridingMeshInterface meshInterface)
 {
     m_meshInterface = meshInterface;
     m_callback = callback;
 }
Beispiel #30
0
 public TrimeshPrimitiveManager(StridingMeshInterface meshInterface, int part)
 {
     m_meshInterface = meshInterface;
     m_part = part;
     m_scale = m_meshInterface.GetScaling();
     m_margin = 0.1f;
     m_lock_count = 0;
     vertexbase = 0;
     numverts = 0;
     stride = 0;
     indexbase = 0;
     indexstride = 0;
     numfaces = 0;
 }