void MyDisplayVertices1::compute() { int i; // Access input object (portData is inherited from HxModule): HxSurface* surface = (HxSurface*) portData.source(); if (!surface) { // Check if input object is available hideGeom(scene); return; } // Get value from input port, query size of surface: int numTriPerVertex = portNumTriangles.getValue(); int nVertices = surface->points.size(); int nTriangles = surface->triangles.size(); // We need a triangle counter for every vertex: McDArray<unsigned short> triCount(nVertices); triCount.fill(0); // Loop through all triangles and increase counter of the vertices: for (i=0; i<nTriangles; i++) for (int j=0; j<3; j++) triCount[surface->triangles[i].points[j]]++; // Now create the scene graph. First remove all previous childs: scene->removeAllChildren(); // Cube size should be 1% of the diagonal of the bounding box. float size = surface->getBoundingBoxSize().length() * 0.01; // Pointer to surface coordinates casted from McVec3f to SbVec3f. SbVec3f* p = (SbVec3f*) surface->points.dataPtr(); SbVec3f q(0,0,0); // position of last point int count = 0; // vertex counter for (i=0; i<nVertices; i++) { if (triCount[i] == numTriPerVertex) { SoTranslation* trans = new SoTranslation; trans->translation.setValue(p[i]-q); SoCube* cube = new SoCube; cube->width = cube->height = cube->depth = size; scene->addChild(trans); scene->addChild(cube); count++; q=p[i]; } } theMsg->printf("Found %d vertices belonging to %d triangles", count, numTriPerVertex); showGeom(scene); // finally show scene in viewer }
void NxAbstractMeshDescription::UpdateDerivedInformation(NxApexRenderDebug* renderDebug) { if (numIndices > 0) { pMin = pPosition[pIndices[0]]; pMax = pMin; } avgEdgeLength = 0; avgTriangleArea = 0; PxU32 triCount(numIndices / 3); PxU32 edgeCount(numIndices); for (PxU32 j = 0; j < numIndices; j += 3) { PxU32 i0 = pIndices[j + 0]; PxU32 i1 = pIndices[j + 1]; PxU32 i2 = pIndices[j + 2]; const PxVec3& v0 = pPosition[i0]; const PxVec3& v1 = pPosition[i1]; const PxVec3& v2 = pPosition[i2]; pMin.minimum(v0); pMin.minimum(v1); pMin.minimum(v2); pMax.maximum(v0); pMax.maximum(v1); pMax.maximum(v2); PxVec3 e0 = v1 - v0; PxVec3 e1 = v2 - v1; PxVec3 e2 = v0 - v2; avgEdgeLength += e0.magnitude(); avgEdgeLength += e1.magnitude(); avgEdgeLength += e2.magnitude(); if (renderDebug) { renderDebug->setCurrentColor(renderDebug->getDebugColor(physx::DebugColors::DarkBlue)); renderDebug->debugLine(v0, v1); renderDebug->debugLine(v1, v2); renderDebug->debugLine(v2, v0); renderDebug->setCurrentColor(renderDebug->getDebugColor(physx::DebugColors::Green)); renderDebug->debugPoint(v0, 0.1f); renderDebug->debugPoint(v1, 0.1f); renderDebug->debugPoint(v2, 0.1f); } PxF32 triangleArea = e0.cross(e2).magnitude() * 0.5f; avgTriangleArea += triangleArea; triCount++; } avgEdgeLength /= edgeCount; avgTriangleArea /= triCount; centroid = 0.5f * (pMin + pMax); radius = 0.5f * (pMax - pMin).magnitude(); //printf("Min = <%f, %f, %f>; Max = <%f, %f, %f>; centroid = <%f, %f, %f>; radius = %f; avgEdgeLength = %f; avgTriangleArea = %f;\n", // pMin.x, pMin.y, pMin.z, pMax.x, pMax.y, pMax.z, centroid.x, centroid.y, centroid.z, radius, avgEdgeLength, avgTriangleArea); }