From ec792d87485058bc7e0594a166685f9d749a4aa6 Mon Sep 17 00:00:00 2001 From: yamahigashi Date: Wed, 25 Sep 2024 19:27:33 +0900 Subject: [PATCH 1/3] support subdiv meshes --- src/intersectionMarkerCommand.cpp | 33 ++-- src/intersectionMarkerDrawOverride.cpp | 54 ++---- src/intersectionMarkerDrawOverride.h | 2 +- src/intersectionMarkerNode.cpp | 222 +++++++++++++++++++------ src/intersectionMarkerNode.h | 21 ++- src/kernel/EmbreeKernel.cpp | 7 +- src/kernel/KDTreeKernel.cpp | 5 +- src/kernel/OctreeKernel.cpp | 4 +- src/utility.h | 5 +- 9 files changed, 247 insertions(+), 106 deletions(-) diff --git a/src/intersectionMarkerCommand.cpp b/src/intersectionMarkerCommand.cpp index 3875ac5..fb7064d 100644 --- a/src/intersectionMarkerCommand.cpp +++ b/src/intersectionMarkerCommand.cpp @@ -93,36 +93,47 @@ MStatus IntersectionMarkerCommand::doIt(const MArgList& argList) MFnMesh meshFnA(meshA); MFnMesh meshFnB(meshB); MPlug meshAPlug = MFnDependencyNode(meshFnA.object()).findPlug("outMesh", false, &status); - CHECK_MSTATUS_AND_RETURN_IT(status); MPlug meshBPlug = MFnDependencyNode(meshFnB.object()).findPlug("outMesh", false, &status); - CHECK_MSTATUS_AND_RETURN_IT(status); MFnDependencyNode markerNodeFn(this->markerNode); MPlug markerInMeshAPlug = markerNodeFn.findPlug("inMeshA", false, &status); - CHECK_MSTATUS_AND_RETURN_IT(status); MPlug markerInMeshBPlug = markerNodeFn.findPlug("inMeshB", false, &status); - CHECK_MSTATUS_AND_RETURN_IT(status); dgMod.connect(meshAPlug, markerInMeshAPlug); - status = dgMod.doIt(); - CHECK_MSTATUS_AND_RETURN_IT(status); dgMod.connect(meshBPlug, markerInMeshBPlug); + + // smooth meshes Subdivision + MPlug smoothMeshAPlug = MFnDependencyNode(meshFnA.object()).findPlug("outSmoothMesh", false, &status); + MPlug smoothMeshBPlug = MFnDependencyNode(meshFnB.object()).findPlug("outSmoothMesh", false, &status); + MPlug smoothModeAPlug = MFnDependencyNode(meshFnA.object()).findPlug("displaySmoothMesh", false, &status); + MPlug smoothModeBPlug = MFnDependencyNode(meshFnB.object()).findPlug("displaySmoothMesh", false, &status); + MPlug smoothLevelAPlug = MFnDependencyNode(meshFnA.object()).findPlug("smoothLevel", false, &status); + MPlug smoothLevelBPlug = MFnDependencyNode(meshFnB.object()).findPlug("smoothLevel", false, &status); + + MPlug markerInSmoothMeshAPlug = markerNodeFn.findPlug("inSmoothMeshA", false, &status); + MPlug markerInSmoothMeshBPlug = markerNodeFn.findPlug("inSmoothMeshB", false, &status); + MPlug markerSmoothModeAPlug = markerNodeFn.findPlug("smoothModeA", false, &status); + MPlug markerSmoothModeBPlug = markerNodeFn.findPlug("smoothModeB", false, &status); + MPlug markerSmoothLevelAPlug = markerNodeFn.findPlug("smoothLevelA", false, &status); + MPlug markerSmoothLevelBPlug = markerNodeFn.findPlug("smoothLevelB", false, &status); + + dgMod.connect(smoothMeshAPlug, markerInSmoothMeshAPlug); + dgMod.connect(smoothMeshBPlug, markerInSmoothMeshBPlug); + dgMod.connect(smoothModeAPlug, markerSmoothModeAPlug); + dgMod.connect(smoothModeBPlug, markerSmoothModeBPlug); + dgMod.connect(smoothLevelAPlug, markerSmoothLevelAPlug); + dgMod.connect(smoothLevelBPlug, markerSmoothLevelBPlug); status = dgMod.doIt(); CHECK_MSTATUS_AND_RETURN_IT(status); - // MGlobal::displayInfo("plug connected"); // offset matrix MPlug meshAMatrixPlug = MFnDependencyNode(meshFnA.parent(0)).findPlug("matrix", false, &status); - CHECK_MSTATUS_AND_RETURN_IT(status); - MPlug meshBMatrixPlug = MFnDependencyNode(meshFnB.parent(0)).findPlug("matrix", false, &status); - CHECK_MSTATUS_AND_RETURN_IT(status); MPlug markerOffsetAPlug = markerNodeFn.findPlug("offsetMatrixA", false, &status); MPlug markerOffsetBPlug = markerNodeFn.findPlug("offsetMatrixB", false, &status); dgMod.connect(meshAMatrixPlug, markerOffsetAPlug); - status = dgMod.doIt(); dgMod.connect(meshBMatrixPlug, markerOffsetBPlug); status = dgMod.doIt(); diff --git a/src/intersectionMarkerDrawOverride.cpp b/src/intersectionMarkerDrawOverride.cpp index 71cb00f..66b51c9 100644 --- a/src/intersectionMarkerDrawOverride.cpp +++ b/src/intersectionMarkerDrawOverride.cpp @@ -109,11 +109,23 @@ MUserData* IntersectionMarkerDrawOverride::prepareForDraw( prevChecksum = newChecksum; MFnMesh meshAFn; - status = node->getInputDagMesh(node->meshA, meshAFn); + int smoothModeA; + status = node->getSmoothMode(node->smoothModeA, smoothModeA); + if( smoothModeA == 0 ) { + status = node->getInputDagMesh(node->meshA, meshAFn); + } else { + status = node->getInputDagMesh(node->smoothMeshA, meshAFn); + } CHECK_MSTATUS_AND_RETURN_DATA("prepareForDraw: meshAFn is null"); MFnMesh meshBFn; - status = node->getInputDagMesh(node->meshB, meshBFn); + int smoothModeB; + status = node->getSmoothMode(node->smoothModeB, smoothModeB); + if( smoothModeB == 0 ) { + status = node->getInputDagMesh(node->meshB, meshBFn); + } else { + status = node->getInputDagMesh(node->smoothMeshB, meshBFn); + } CHECK_MSTATUS_AND_RETURN_DATA("prepareForDraw: meshBFn is null"); // Get the offset matrix @@ -128,11 +140,11 @@ MUserData* IntersectionMarkerDrawOverride::prepareForDraw( bool showMeshB = showMeshBPlug.asBool(); if (showMeshA) { - addIntersectedVertices(meshAFn, data, node->intersectedFaceIdsA, outMatrixA); + addIntersectedVertices(meshAFn, data, node->intersectedFacesA, outMatrixA); } if (showMeshB) { - addIntersectedVertices(meshBFn, data, node->intersectedFaceIdsB, outMatrixB); + addIntersectedVertices(meshBFn, data, node->intersectedFacesB, outMatrixB); } return data; @@ -142,42 +154,12 @@ MUserData* IntersectionMarkerDrawOverride::prepareForDraw( MStatus IntersectionMarkerDrawOverride::addIntersectedVertices( const MFnMesh& meshFn, IntersectionMarkerData* data, - const std::unordered_set &intersectedFaceIds, + const std::vector &intersectedFaces, const MMatrix &offsetMatrix ) { MStatus status; - MItMeshPolygon itPoly(meshFn.object(), &status); - CHECK_MSTATUS_AND_RETURN_IT(status); - - MIntArray vertexIndices; - MPointArray vertices; - int prevIndex; - - int numPolygons = meshFn.numPolygons(); - for (const auto &faceId : intersectedFaceIds) { - status = itPoly.setIndex(faceId, prevIndex); - CHECK_MSTATUS_AND_RETURN_IT(status); - IntersectionMarkerData::FaceData faceData; - - MVector normal; - meshFn.getPolygonNormal(faceId, normal); - int numTriangles; - itPoly.numTriangles(numTriangles); - for (int j = 0; j < numTriangles; ++j) { - itPoly.getTriangle(j, vertices, vertexIndices, MSpace::kObject); - for (unsigned int k = 0; k < vertices.length(); ++k) { - // To avoid z-fighting, move the vertex a little bit along the normal - vertices[k] += normal * 0.001; - vertices[k] *= offsetMatrix; - faceData.vertices.append(vertices[k]); - faceData.edges.append(vertices[k]); - faceData.normals.append(normal); - } - faceData.edges.append(vertices[0]); // close the loop of the triangle - } - - // Get normal + for (const auto &faceData : intersectedFaces) { data->faces.push_back(faceData); } diff --git a/src/intersectionMarkerDrawOverride.h b/src/intersectionMarkerDrawOverride.h index 50fc17c..bb8293a 100644 --- a/src/intersectionMarkerDrawOverride.h +++ b/src/intersectionMarkerDrawOverride.h @@ -71,7 +71,7 @@ class IntersectionMarkerDrawOverride : public MHWRender::MPxDrawOverride MStatus addIntersectedVertices( const MFnMesh& meshFn, IntersectionMarkerData* data, - const std::unordered_set &intersectedFaceIds, + const std::vector &intersectedFaces, const MMatrix& offsetMatrix ); diff --git a/src/intersectionMarkerNode.cpp b/src/intersectionMarkerNode.cpp index fa6f705..1632eb8 100644 --- a/src/intersectionMarkerNode.cpp +++ b/src/intersectionMarkerNode.cpp @@ -6,6 +6,7 @@ #include "utility.h" #include "intersectionMarkerNode.h" +#include "intersectionMarkerData.h" #include "kernel/KDTreeKernel.h" #include "kernel/EmbreeKernel.h" @@ -46,6 +47,8 @@ MObject IntersectionMarkerNode::meshA; MObject IntersectionMarkerNode::meshB; +MObject IntersectionMarkerNode::smoothMeshA; +MObject IntersectionMarkerNode::smoothMeshB; MObject IntersectionMarkerNode::offsetMatrixA; MObject IntersectionMarkerNode::offsetMatrixB; MObject IntersectionMarkerNode::restIntersected; @@ -57,6 +60,11 @@ MObject IntersectionMarkerNode::showMeshB; MObject IntersectionMarkerNode::kernelType; MObject IntersectionMarkerNode::collisionMode; +MObject IntersectionMarkerNode::smoothModeA; +MObject IntersectionMarkerNode::smoothModeB; +MObject IntersectionMarkerNode::smoothLevelA; +MObject IntersectionMarkerNode::smoothLevelB; + MObject IntersectionMarkerNode::outputIntersected; CacheType IntersectionMarkerNode::cache(CACHE_SIZE); @@ -94,6 +102,16 @@ MStatus IntersectionMarkerNode::initialize() status = addAttribute(meshB); CHECK_MSTATUS_AND_RETURN_IT(status); + // Initialize Mesh A + smoothMeshA = tInputAttr.create("inSmoothMeshA", "inSmoothMeshA", MFnData::kMesh, MObject::kNullObj, &status); + status = addAttribute(smoothMeshA); + CHECK_MSTATUS_AND_RETURN_IT(status); + + // Initialize Mesh B + smoothMeshB = tInputAttr.create("inSmoothMeshB", "inSmoothMeshB", MFnData::kMesh, MObject::kNullObj, &status); + status = addAttribute(smoothMeshB); + CHECK_MSTATUS_AND_RETURN_IT(status); + // Initialize Offset Matrix offsetMatrixA = mAttr.create(OFFSET_MATRIX_A, OFFSET_MATRIX_A); status = addAttribute(offsetMatrixA); @@ -144,6 +162,38 @@ MStatus IntersectionMarkerNode::initialize() status = addAttribute(vertexChecksumB); CHECK_MSTATUS_AND_RETURN_IT(status); + smoothModeA = nAttr.create("smoothModeA", "smoothModeA", MFnNumericData::kInt, 0); + nAttr.setStorable(false); + nAttr.setKeyable(true); + nAttr.setWritable(true); + nAttr.setReadable(false); + status = addAttribute(smoothModeA); + CHECK_MSTATUS_AND_RETURN_IT(status); + + smoothModeB = nAttr.create("smoothModeB", "smoothModeB", MFnNumericData::kInt, 0); + nAttr.setStorable(false); + nAttr.setKeyable(true); + nAttr.setWritable(true); + nAttr.setReadable(false); + status = addAttribute(smoothModeB); + CHECK_MSTATUS_AND_RETURN_IT(status); + + smoothLevelA = nAttr.create("smoothLevelA", "smoothLevelA", MFnNumericData::kInt, 0); + nAttr.setStorable(true); + nAttr.setKeyable(true); + nAttr.setWritable(true); + nAttr.setReadable(true); + status = addAttribute(smoothLevelA); + CHECK_MSTATUS_AND_RETURN_IT(status); + + smoothLevelB = nAttr.create("smoothLevelB", "smoothLevelB", MFnNumericData::kInt, 0); + nAttr.setStorable(true); + nAttr.setKeyable(true); + nAttr.setWritable(true); + nAttr.setReadable(true); + status = addAttribute(smoothLevelB); + CHECK_MSTATUS_AND_RETURN_IT(status); + // Initialize Kernel kernelType = eAttr.create(KERNEL, KERNEL, 0, &status); CHECK_MSTATUS_AND_RETURN_IT(status); @@ -171,6 +221,9 @@ MStatus IntersectionMarkerNode::initialize() CHECK_MSTATUS_AND_RETURN_IT(status); // Add dependencies + status = attributeAffects(smoothModeA, vertexChecksumA); + status = attributeAffects(smoothModeB, vertexChecksumB); + status = attributeAffects(meshA, vertexChecksumA); status = attributeAffects(meshB, vertexChecksumB); status = attributeAffects(offsetMatrixA, vertexChecksumA); @@ -182,6 +235,7 @@ MStatus IntersectionMarkerNode::initialize() status = attributeAffects(meshB, outputIntersected); status = attributeAffects(showMeshA, outputIntersected); status = attributeAffects(showMeshB, outputIntersected); + CHECK_MSTATUS_AND_RETURN_IT(status); status = attributeAffects(kernelType, outputIntersected); @@ -200,25 +254,15 @@ MStatus IntersectionMarkerNode::preEvaluation( MStatus status; bool dirty = false; dirty = dirty || evaluationNode.dirtyPlugExists(meshA, &status); - CHECK_MSTATUS_AND_RETURN_IT(status); - dirty = dirty || evaluationNode.dirtyPlugExists(meshB, &status); - CHECK_MSTATUS_AND_RETURN_IT(status); - dirty = dirty || evaluationNode.dirtyPlugExists(offsetMatrixA, &status); - CHECK_MSTATUS_AND_RETURN_IT(status); - dirty = dirty || evaluationNode.dirtyPlugExists(offsetMatrixB, &status); - CHECK_MSTATUS_AND_RETURN_IT(status); - dirty = dirty || evaluationNode.dirtyPlugExists(kernelType, &status); - CHECK_MSTATUS_AND_RETURN_IT(status); - dirty = dirty || evaluationNode.dirtyPlugExists(collisionMode, &status); dirty = dirty || evaluationNode.dirtyPlugExists(showMeshA, &status); - CHECK_MSTATUS_AND_RETURN_IT(status); - dirty = dirty || evaluationNode.dirtyPlugExists(showMeshB, &status); + dirty = dirty || evaluationNode.dirtyPlugExists(smoothModeA, &status); + dirty = dirty || evaluationNode.dirtyPlugExists(smoothModeB, &status); CHECK_MSTATUS_AND_RETURN_IT(status); if (dirty) { @@ -253,7 +297,9 @@ MStatus IntersectionMarkerNode::postEvaluation( (evaluationNode.dirtyPlugExists(kernelType, &status) && status ) || (evaluationNode.dirtyPlugExists(collisionMode, &status) && status ) || (evaluationNode.dirtyPlugExists(showMeshA, &status) && status ) || - (evaluationNode.dirtyPlugExists(showMeshB, &status) && status ) + (evaluationNode.dirtyPlugExists(showMeshB, &status) && status ) || + (evaluationNode.dirtyPlugExists(smoothModeA, &status) && status ) || + (evaluationNode.dirtyPlugExists(smoothModeB, &status) && status ) ) { MDataBlock block = forceCache(); MDataHandle meshAHandle = block.inputValue(meshA, &status); @@ -302,9 +348,67 @@ MStatus IntersectionMarkerNode::compute(const MPlug &plug, MDataBlock &dataBlock return status; } + MDataHandle smoothModeAHandle = dataBlock.inputValue(smoothModeA); + if(status != MStatus::kSuccess) { + MGlobal::displayError("Failed to get smoothModeA data handle"); + return status; + } + + MDataHandle smoothModeBHandle = dataBlock.inputValue(smoothModeB); + if(status != MStatus::kSuccess) { + MGlobal::displayError("Failed to get smoothModeB data handle"); + return status; + } + + MDataHandle smoothLevelAHandle = dataBlock.inputValue(smoothLevelA); + if(status != MStatus::kSuccess) { + MGlobal::displayError("Failed to get smoothLevelA data handle"); + return status; + } + + MDataHandle smoothLevelBHandle = dataBlock.inputValue(smoothLevelB); + if(status != MStatus::kSuccess) { + MGlobal::displayError("Failed to get smoothLevelB data handle"); + return status; + } + + MDataHandle smoothMeshAHandle = dataBlock.inputValue(smoothMeshA); + if(status != MStatus::kSuccess) { + MGlobal::displayError("Failed to get smoothMeshA data handle"); + return status; + } + + MDataHandle smoothMeshBHandle = dataBlock.inputValue(smoothMeshB); + if(status != MStatus::kSuccess) { + MGlobal::displayError("Failed to get smoothMeshB data handle"); + return status; + } + + int smoothModeAObject = smoothModeAHandle.asInt(); + int smoothModeBObject = smoothModeBHandle.asInt(); + + smoothModeAHandle.setClean(); + smoothModeBHandle.setClean(); + smoothLevelAHandle.setClean(); + smoothLevelBHandle.setClean(); + // Get the MObject of the meshes - MObject meshAObject = meshAHandle.asMesh(); - MObject meshBObject = meshBHandle.asMesh(); + // MObject meshAObject = meshAHandle.asMesh(); + // MObject meshBObject = meshBHandle.asMesh(); + MObject meshAObject; + if( smoothModeAObject == 0 ) { + meshAObject = meshAHandle.asMesh(); + } else { + meshAObject = smoothMeshAHandle.asMesh(); + } + + MObject meshBObject; + if( smoothModeBObject == 0 ) { + meshBObject = meshBHandle.asMesh(); + } else { + meshBObject = smoothMeshBHandle.asMesh(); + } + MMatrix offsetA = offsetAHandle.asMatrix(); MMatrix offsetB = offsetBHandle.asMatrix(); @@ -318,8 +422,8 @@ MStatus IntersectionMarkerNode::compute(const MPlug &plug, MDataBlock &dataBlock // ------------------------------------------------------------------------------------------- // update checksums // MGlobal::displayInfo("update checksums..."); - int newCheckA = getVertexChecksum(meshAObject, offsetA); - int newCheckB = getVertexChecksum(meshBObject, offsetB); + int newCheckA = getVertexChecksum(meshAObject, offsetA) ^ smoothModeAObject; + int newCheckB = getVertexChecksum(meshBObject, offsetB) ^ smoothModeBObject; MDataHandle vertexChecksumAHandle = dataBlock.outputValue(vertexChecksumA); MDataHandle vertexChecksumBHandle = dataBlock.outputValue(vertexChecksumB); @@ -352,14 +456,14 @@ MStatus IntersectionMarkerNode::compute(const MPlug &plug, MDataBlock &dataBlock try { CacheResultType res = this->cache.get(key); - this->intersectedFaceIdsA = res.first; - this->intersectedFaceIdsB = res.second; + this->intersectedFacesA = res.first; + this->intersectedFacesB = res.second; } catch (const std::out_of_range&) { // The result is not in the cache - this->intersectedFaceIdsA.clear(); - this->intersectedFaceIdsB.clear(); + this->intersectedFacesA.clear(); + this->intersectedFacesB.clear(); // Build kernel A std::shared_ptr kernelA = getActiveKernel(); @@ -392,10 +496,12 @@ MStatus IntersectionMarkerNode::compute(const MPlug &plug, MDataBlock &dataBlock K2KIntersection pairs = kernelA->intersectKernelKernel(*kernelB); for (auto pair : pairs.first) { - this->intersectedFaceIdsA.insert(pair.faceIndex); + // TODO: implement this later + // this->intersectedFacesA.insert(pair.faceIndex); } for (auto pair : pairs.second) { - this->intersectedFaceIdsB.insert(pair.faceIndex); + // TODO: implement this later + // this->intersectedFacesB.insert(pair.faceIndex); } } else { @@ -406,14 +512,14 @@ MStatus IntersectionMarkerNode::compute(const MPlug &plug, MDataBlock &dataBlock // ------------------------------------------------------------------------------------------- // Store the result in the cache - CacheResultType res{this->intersectedFaceIdsA, this->intersectedFaceIdsB}; + CacheResultType res{this->intersectedFacesA, this->intersectedFacesB}; this->cache.put(key, res); modeHandle.setClean(); } // Get output data handle MDataHandle outputIntersectedHandle = dataBlock.outputValue(outputIntersected, &status); - outputIntersectedHandle.set((intersectedFaceIdsA.size() > 0) || (intersectedFaceIdsB.size() > 0)); + outputIntersectedHandle.set((intersectedFacesA.size() > 0) || (intersectedFacesB.size() > 0)); outputIntersectedHandle.setClean(); // clean up @@ -422,16 +528,24 @@ MStatus IntersectionMarkerNode::compute(const MPlug &plug, MDataBlock &dataBlock outputIntersectedHandle.setClean(); dataBlock.setClean(plug); + smoothMeshAHandle.setClean(); + smoothMeshBHandle.setClean(); + return MStatus::kSuccess; } -MStatus IntersectionMarkerNode::checkIntersections(MObject &meshAObject, MObject &meshBObject, std::shared_ptr kernel, MMatrix offset) -{ - MStatus status; +MStatus IntersectionMarkerNode::checkIntersections( + MObject &meshAObject, + MObject &meshBObject, + std::shared_ptr kernel, + MMatrix offset +){ + // MGlobal::displayInfo("checkIntersections..."); - intersectedFaceIdsA.clear(); - intersectedFaceIdsB.clear(); + MStatus status; + intersectedFacesA.clear(); + intersectedFacesB.clear(); // Iterate through the polygons in meshB MFnMesh meshBFn(meshBObject); @@ -460,48 +574,52 @@ MStatus IntersectionMarkerNode::checkIntersections(MObject &meshAObject, MObject // #pragma omp parallel { - std::unordered_set intersectedFaceIdsLocalA; - std::unordered_set intersectedFaceIdsLocalB; + std::vector intersectedFacesLocalA; + std::vector intersectedFacesLocalB; // #pragma omp for for (int polygonIndex = 0; polygonIndex < numPolygons; polygonIndex++) { + MVector normal; + meshBFn.getPolygonNormal(polygonIndex, normal); + TriangleData triangle; int numTrianglesInPolygon = triangleCounts[polygonIndex]; int triangleVerticesOffset = polygonTriangleOffsets[polygonIndex]; int triangleIndicesOffset = polygonIndexOffsets[polygonIndex]; for (int triangleIndex = 0; triangleIndex < numTrianglesInPolygon; triangleIndex++) { - // Get the vertex positions of each triangle + // Get the vertex positions of each triangle int vertexId0 = triangleVertices[triangleVerticesOffset + triangleIndex * 3 + 0]; int vertexId1 = triangleVertices[triangleVerticesOffset + triangleIndex * 3 + 1]; int vertexId2 = triangleVertices[triangleVerticesOffset + triangleIndex * 3 + 2]; MPoint p0 = vertexPositions[vertexId0] * offset; MPoint p1 = vertexPositions[vertexId1] * offset; MPoint p2 = vertexPositions[vertexId2] * offset; - TriangleData triangle(polygonIndex, triangleIndex, p0, p1, p2); + TriangleData triangle(polygonIndex, triangleIndex, p0, p1, p2, normal); - // Check intersection between triangle and the octree (kernel) + // Check intersection between triangle and the kernel std::vector intersectedTriangles = kernel->intersectKernelTriangle(triangle); // If there is any intersection, store the intersection data into intersectedVertexIdsLocal if (!intersectedTriangles.empty()) { for(int k = 0; k < intersectedTriangles.size(); ++k) { - int a = intersectedTriangles[k].faceIndex; - int b = polygonIndex; - intersectedFaceIdsLocalA.insert(a); - intersectedFaceIdsLocalB.insert(b); + IntersectionMarkerData::FaceData faceDataA; + faceDataA.vertices.append(intersectedTriangles[k].vertices[0] + intersectedTriangles[k].normal * 0.001); + faceDataA.vertices.append(intersectedTriangles[k].vertices[1] + intersectedTriangles[k].normal * 0.001); + faceDataA.vertices.append(intersectedTriangles[k].vertices[2] + intersectedTriangles[k].normal * 0.001); + intersectedFacesA.push_back(faceDataA); + + IntersectionMarkerData::FaceData faceDataB; + faceDataB.vertices.append(p0 + normal * 0.001); + faceDataB.vertices.append(p1 + normal * 0.001); + faceDataB.vertices.append(p2 + normal * 0.001); + intersectedFacesB.push_back(faceDataB); } } } } - - // #pragma omp critical - { - intersectedFaceIdsA.insert(intersectedFaceIdsLocalA.begin(), intersectedFaceIdsLocalA.end()); - intersectedFaceIdsB.insert(intersectedFaceIdsLocalB.begin(), intersectedFaceIdsLocalB.end()); - } } return MStatus::kSuccess; @@ -531,7 +649,6 @@ std::shared_ptr IntersectionMarkerNode::getActiveKernel() MStatus IntersectionMarkerNode::getInputDagMesh(const MObject inputAttr, MFnMesh &outMesh) const { - MStatus status; MPlug inputMeshPlug(thisMObject(), inputAttr); // Get the connected source node of the input plug. @@ -553,9 +670,18 @@ MStatus IntersectionMarkerNode::getInputDagMesh(const MObject inputAttr, MFnMesh } +MStatus IntersectionMarkerNode::getSmoothMode( const MObject inputAttr, int &outSmoothMode ) const +{ + MPlug inputMeshPlug(thisMObject(), inputAttr); + + outSmoothMode = inputMeshPlug.asInt(); + return MStatus::kSuccess; + +} + + MStatus IntersectionMarkerNode::getOffsetMatrix(const MObject inputAttr, MMatrix &outMatrix) const { - MStatus status; MPlug inputMeshPlug(thisMObject(), inputAttr); MObject value = inputMeshPlug.asMObject(); @@ -584,7 +710,6 @@ MBoundingBox IntersectionMarkerNode::getBoundingBox(const MObject &meshObject) c MStatus IntersectionMarkerNode::getChecksumA(int &outChecksum) const { - MStatus status; MPlug checksumPlug(thisMObject(), vertexChecksumA); outChecksum = checksumPlug.asInt(); return MStatus::kSuccess; @@ -593,7 +718,6 @@ MStatus IntersectionMarkerNode::getChecksumA(int &outChecksum) const MStatus IntersectionMarkerNode::getChecksumB(int &outChecksum) const { - MStatus status; MPlug checksumPlug(thisMObject(), vertexChecksumB); outChecksum = checksumPlug.asInt(); return MStatus::kSuccess; diff --git a/src/intersectionMarkerNode.h b/src/intersectionMarkerNode.h index eb5a8e4..cea6481 100644 --- a/src/intersectionMarkerNode.h +++ b/src/intersectionMarkerNode.h @@ -5,6 +5,8 @@ #pragma once #include "SpatialDivisionKernel.h" +#include "IntersectionMarkerData.h" +#include "utility.h" #include #include @@ -57,8 +59,8 @@ struct pair_hash { // The type for the value of the cache struct CacheResultType { - std::unordered_set first; - std::unordered_set second; + std::vector first; + std::vector second; }; @@ -143,6 +145,7 @@ std::shared_ptr getActiveKernel() const; MStatus getChecksumB(int &outChecksum) const; MBoundingBox getBoundingBox(const MObject &meshObject) const; MStatus createMeshFromTriangles(const MObject& meshAObject, const MIntArray& intersectedTriangleIDs, MFnMesh& outputMeshFn); + MStatus getSmoothMode( const MObject inputAttr, int &outSmoothMode ) const; MPlug meshAPlug() const { return MPlug(thisMObject(), meshA); } MPlug meshBPlug() const { return MPlug(thisMObject(), meshB); } @@ -150,6 +153,8 @@ std::shared_ptr getActiveKernel() const; public: static MObject meshA; static MObject meshB; + static MObject smoothMeshA; + static MObject smoothMeshB; static MObject offsetMatrixA; static MObject offsetMatrixB; static MObject restIntersected; @@ -161,6 +166,11 @@ std::shared_ptr getActiveKernel() const; static MObject kernelType; static MObject collisionMode; + static MObject smoothModeA; + static MObject smoothModeB; + static MObject smoothLevelA; + static MObject smoothLevelB; + static MObject outputIntersected; static MString NODE_NAME; @@ -170,6 +180,9 @@ std::shared_ptr getActiveKernel() const; static MString drawRegistrantId; static CacheType cache; - std::unordered_set intersectedFaceIdsA; - std::unordered_set intersectedFaceIdsB; + // std::unordered_set intersectedFaceIdsA; + // std::unordered_set intersectedFaceIdsB; + + std::vector intersectedFacesA; + std::vector intersectedFacesB; }; diff --git a/src/kernel/EmbreeKernel.cpp b/src/kernel/EmbreeKernel.cpp index 75a2fb6..9eba5d3 100644 --- a/src/kernel/EmbreeKernel.cpp +++ b/src/kernel/EmbreeKernel.cpp @@ -106,11 +106,13 @@ MStatus EmbreeKernel::build(const MObject& meshObject, const MBoundingBox& bbox, // collect all triangles std::vector primitives; MItMeshPolygon itPoly(meshObject); + MVector normal; + int numTriangles; int primId = 0; for(; !itPoly.isDone(); itPoly.next()) { - int numTriangles; itPoly.numTriangles(numTriangles); + itPoly.getNormal(normal, MSpace::kObject); for (int triangleId=0; triangleId < numTriangles; ++triangleId) { MPointArray points; @@ -121,7 +123,8 @@ MStatus EmbreeKernel::build(const MObject& meshObject, const MBoundingBox& bbox, triangleId, points[0] * offsetMatrix, points[1] * offsetMatrix, - points[2] * offsetMatrix); + points[2] * offsetMatrix, + normal); RTCBuildPrimitive prim; prim.lower_x = (float)triangle.bbox.min().x; diff --git a/src/kernel/KDTreeKernel.cpp b/src/kernel/KDTreeKernel.cpp index 3f22b18..037f828 100644 --- a/src/kernel/KDTreeKernel.cpp +++ b/src/kernel/KDTreeKernel.cpp @@ -16,6 +16,8 @@ std::vector KDTreeKernel::extractTriangles( MItMeshPolygon itPoly(meshObject); for(; !itPoly.isDone(); itPoly.next()) { + MVector normal; + itPoly.getNormal(normal, MSpace::kObject); int numTriangles; itPoly.numTriangles(numTriangles); @@ -29,7 +31,8 @@ std::vector KDTreeKernel::extractTriangles( triangleId, points[0] * offsetMatrix, points[1] * offsetMatrix, - points[2] * offsetMatrix); + points[2] * offsetMatrix, + normal); triangles.push_back(triangle); } diff --git a/src/kernel/OctreeKernel.cpp b/src/kernel/OctreeKernel.cpp index 41077b0..c78116b 100644 --- a/src/kernel/OctreeKernel.cpp +++ b/src/kernel/OctreeKernel.cpp @@ -30,6 +30,8 @@ MStatus OctreeKernel::build(const MObject& meshObject, const MBoundingBox& bbox, MItMeshPolygon itPoly(meshObject); // MGlobal::displayInfo("Building octree..."); for (; !itPoly.isDone(); itPoly.next()) { + MVector normal; + itPoly.getNormal(normal, MSpace::kObject); int numTriangles; itPoly.numTriangles(numTriangles); @@ -44,7 +46,7 @@ MStatus OctreeKernel::build(const MObject& meshObject, const MBoundingBox& bbox, MPoint p1 = points[1] * offsetMatrix; MPoint p2 = points[2] * offsetMatrix; - TriangleData triangle(itPoly.index(), i, p0, p1, p2); + TriangleData triangle(itPoly.index(), i, p0, p1, p2, normal); // Add the triangle to the octree insertTriangle(root, triangle, 0); } diff --git a/src/utility.h b/src/utility.h index 474f1a5..5cb72b0 100644 --- a/src/utility.h +++ b/src/utility.h @@ -41,9 +41,10 @@ struct TriangleData int triangleIndex; MPoint vertices[3]; MBoundingBox bbox; + MVector normal; TriangleData() = default; - TriangleData(int faceIndex, int triangleIndex, MPoint v0, MPoint v1, MPoint v2) + TriangleData(int faceIndex, int triangleIndex, MPoint v0, MPoint v1, MPoint v2, const MVector& n) : faceIndex(faceIndex), triangleIndex(triangleIndex) { vertices[0] = v0; @@ -53,6 +54,8 @@ struct TriangleData bbox.expand(v0); bbox.expand(v1); bbox.expand(v2); + + normal = n; } MPoint center() const From fea4cd3154ce68977a31d565c345384782efe56c Mon Sep 17 00:00:00 2001 From: yamahigashi Date: Wed, 25 Sep 2024 20:11:53 +0900 Subject: [PATCH 2/3] reverted to using ids for drawing override --- src/intersectionMarkerDrawOverride.cpp | 79 +++++++++++++++++++++-- src/intersectionMarkerDrawOverride.h | 7 ++ src/intersectionMarkerNode.cpp | 89 ++++++++++---------------- src/intersectionMarkerNode.h | 12 ++-- src/kernel/EmbreeKernel.cpp | 7 +- src/kernel/KDTreeKernel.cpp | 5 +- src/kernel/OctreeKernel.cpp | 4 +- src/utility.h | 5 +- 8 files changed, 125 insertions(+), 83 deletions(-) diff --git a/src/intersectionMarkerDrawOverride.cpp b/src/intersectionMarkerDrawOverride.cpp index 66b51c9..9b869eb 100644 --- a/src/intersectionMarkerDrawOverride.cpp +++ b/src/intersectionMarkerDrawOverride.cpp @@ -140,11 +140,13 @@ MUserData* IntersectionMarkerDrawOverride::prepareForDraw( bool showMeshB = showMeshBPlug.asBool(); if (showMeshA) { - addIntersectedVertices(meshAFn, data, node->intersectedFacesA, outMatrixA); + addIntersectedVertices(meshAFn, data, node->intersectedFaceIdsA, outMatrixA); + // addIntersectedVertices(meshAFn, data, node->intersectedFacesA, outMatrixA); } if (showMeshB) { - addIntersectedVertices(meshBFn, data, node->intersectedFacesB, outMatrixB); + addIntersectedVertices(meshBFn, data, node->intersectedFaceIdsB, outMatrixB); + // addIntersectedVertices(meshBFn, data, node->intersectedFacesB, outMatrixB); } return data; @@ -154,18 +156,87 @@ MUserData* IntersectionMarkerDrawOverride::prepareForDraw( MStatus IntersectionMarkerDrawOverride::addIntersectedVertices( const MFnMesh& meshFn, IntersectionMarkerData* data, - const std::vector &intersectedFaces, + const std::unordered_set &intersectedFaceIds, const MMatrix &offsetMatrix ) { MStatus status; - for (const auto &faceData : intersectedFaces) { + CHECK_MSTATUS_AND_RETURN_IT(status); + + MIntArray vertexIndices; + MPointArray vertices; + + + MIntArray triangleCounts; // number of triangles in each face + MIntArray triangleVertices; // The triangle vertex Ids for each triangle + MIntArray triangleIndices; // The index array for each triangle in face vertex space + MPointArray vertexPositions; + MVector normal; + + int numPolygons = meshFn.numPolygons(); + meshFn.getTriangles(triangleCounts, triangleVertices); + meshFn.getTriangleOffsets(triangleCounts, triangleIndices); + meshFn.getPoints(vertexPositions, MSpace::kObject); // not having DAG path, so use object space + + // Calculate the offset into the triangleVertices array for each polygon + MIntArray polygonTriangleOffsets(numPolygons, 0); + MIntArray polygonIndexOffsets(numPolygons, 0); + for (int polygonIndex = 1; polygonIndex < numPolygons; polygonIndex++) { + int previousTriangles = triangleCounts[polygonIndex - 1]; + polygonTriangleOffsets[polygonIndex] = polygonTriangleOffsets[polygonIndex - 1] + previousTriangles * 3; + polygonIndexOffsets[polygonIndex] = polygonIndexOffsets[polygonIndex - 1] + previousTriangles; + } + + for (const auto &faceId : intersectedFaceIds) { + if( faceId < 0 || faceId >= numPolygons ) { + MString message = "Face ID out of bounds: " + MString(std::to_string(faceId).c_str()); + MGlobal::displayInfo(message); + continue; + } + TriangleData triangle; + int numTrianglesInPolygon = triangleCounts[faceId]; + int triangleVerticesOffset = polygonTriangleOffsets[faceId]; + int triangleIndicesOffset = polygonIndexOffsets[faceId]; + + CHECK_MSTATUS_AND_RETURN_IT(status); + IntersectionMarkerData::FaceData faceData; + meshFn.getPolygonNormal(faceId, normal); + for (int triangleIndex = 0; triangleIndex < numTrianglesInPolygon; triangleIndex++) { + // Get the vertex positions of each triangle + int vertexId0 = triangleVertices[triangleVerticesOffset + triangleIndex * 3 + 0]; + int vertexId1 = triangleVertices[triangleVerticesOffset + triangleIndex * 3 + 1]; + int vertexId2 = triangleVertices[triangleVerticesOffset + triangleIndex * 3 + 2]; + MPoint p0 = vertexPositions[vertexId0] * offsetMatrix; + MPoint p1 = vertexPositions[vertexId1] * offsetMatrix; + MPoint p2 = vertexPositions[vertexId2] * offsetMatrix; + TriangleData triangle(faceId, triangleIndex, p0, p1, p2); + + faceData.vertices.append(p0 + normal * 0.001); + faceData.vertices.append(p1 + normal * 0.001); + faceData.vertices.append(p2 + normal * 0.001); + } data->faces.push_back(faceData); } return status; } + +// MStatus IntersectionMarkerDrawOverride::addIntersectedVertices( +// const MFnMesh& meshFn, +// IntersectionMarkerData* data, +// const std::vector &intersectedFaces, +// const MMatrix &offsetMatrix +// ) { +// MStatus status; +// +// for (const auto &faceData : intersectedFaces) { +// data->faces.push_back(faceData); +// } +// +// return status; +// } + void IntersectionMarkerDrawOverride::addUIDrawables( const MDagPath& objPath, MHWRender::MUIDrawManager& drawManager, diff --git a/src/intersectionMarkerDrawOverride.h b/src/intersectionMarkerDrawOverride.h index bb8293a..96fa283 100644 --- a/src/intersectionMarkerDrawOverride.h +++ b/src/intersectionMarkerDrawOverride.h @@ -68,6 +68,13 @@ class IntersectionMarkerDrawOverride : public MHWRender::MPxDrawOverride IntersectionMarkerDrawOverride(const MObject& obj); // class IntersectionMarkerData : public MUserData {...}; static void OnModelEditorChanged(void *clientData); + MStatus addIntersectedVertices( + const MFnMesh& meshFn, + IntersectionMarkerData* data, + const std::unordered_set &intersectedFaceIds, + const MMatrix& offsetMatrix + ); + MStatus addIntersectedVertices( const MFnMesh& meshFn, IntersectionMarkerData* data, diff --git a/src/intersectionMarkerNode.cpp b/src/intersectionMarkerNode.cpp index 1632eb8..d72aee6 100644 --- a/src/intersectionMarkerNode.cpp +++ b/src/intersectionMarkerNode.cpp @@ -456,14 +456,14 @@ MStatus IntersectionMarkerNode::compute(const MPlug &plug, MDataBlock &dataBlock try { CacheResultType res = this->cache.get(key); - this->intersectedFacesA = res.first; - this->intersectedFacesB = res.second; + this->intersectedFaceIdsA = res.first; + this->intersectedFaceIdsB = res.second; } catch (const std::out_of_range&) { // The result is not in the cache - this->intersectedFacesA.clear(); - this->intersectedFacesB.clear(); + this->intersectedFaceIdsA.clear(); + this->intersectedFaceIdsB.clear(); // Build kernel A std::shared_ptr kernelA = getActiveKernel(); @@ -496,12 +496,10 @@ MStatus IntersectionMarkerNode::compute(const MPlug &plug, MDataBlock &dataBlock K2KIntersection pairs = kernelA->intersectKernelKernel(*kernelB); for (auto pair : pairs.first) { - // TODO: implement this later - // this->intersectedFacesA.insert(pair.faceIndex); + this->intersectedFaceIdsA.insert(pair.faceIndex); } for (auto pair : pairs.second) { - // TODO: implement this later - // this->intersectedFacesB.insert(pair.faceIndex); + this->intersectedFaceIdsB.insert(pair.faceIndex); } } else { @@ -512,14 +510,14 @@ MStatus IntersectionMarkerNode::compute(const MPlug &plug, MDataBlock &dataBlock // ------------------------------------------------------------------------------------------- // Store the result in the cache - CacheResultType res{this->intersectedFacesA, this->intersectedFacesB}; + CacheResultType res{this->intersectedFaceIdsA, this->intersectedFaceIdsB}; this->cache.put(key, res); modeHandle.setClean(); } // Get output data handle MDataHandle outputIntersectedHandle = dataBlock.outputValue(outputIntersected, &status); - outputIntersectedHandle.set((intersectedFacesA.size() > 0) || (intersectedFacesB.size() > 0)); + outputIntersectedHandle.set((intersectedFaceIdsA.size() > 0) || (intersectedFaceIdsB.size() > 0)); outputIntersectedHandle.setClean(); // clean up @@ -541,11 +539,10 @@ MStatus IntersectionMarkerNode::checkIntersections( std::shared_ptr kernel, MMatrix offset ){ - - // MGlobal::displayInfo("checkIntersections..."); MStatus status; - intersectedFacesA.clear(); - intersectedFacesB.clear(); + // MGlobal::displayInfo("checkIntersections..."); + intersectedFaceIdsA.clear(); + intersectedFaceIdsB.clear(); // Iterate through the polygons in meshB MFnMesh meshBFn(meshBObject); @@ -561,65 +558,60 @@ MStatus IntersectionMarkerNode::checkIntersections( meshBFn.getPoints(vertexPositions, MSpace::kWorld); // Calculate the offset into the triangleVertices array for each polygon + // And similarly, calculate the offset into the triangleIndices array for each polygon MIntArray polygonTriangleOffsets(numPolygons, 0); - for (int polygonIndex = 1; polygonIndex < numPolygons; polygonIndex++) { - polygonTriangleOffsets[polygonIndex] = polygonTriangleOffsets[polygonIndex - 1] + triangleCounts[polygonIndex - 1] * 3; - } + // MIntArray polygonIndexOffsets(numPolygons, 0); - // Similarly, calculate the offset into the triangleIndices array for each polygon - MIntArray polygonIndexOffsets(numPolygons, 0); for (int polygonIndex = 1; polygonIndex < numPolygons; polygonIndex++) { - polygonIndexOffsets[polygonIndex] = polygonIndexOffsets[polygonIndex - 1] + triangleCounts[polygonIndex - 1]; + int previousTriangles = triangleCounts[polygonIndex - 1]; + polygonTriangleOffsets[polygonIndex] = polygonTriangleOffsets[polygonIndex - 1] + previousTriangles * 3; + // polygonIndexOffsets[polygonIndex] = polygonIndexOffsets[polygonIndex - 1] + previousTriangles; } // #pragma omp parallel { - std::vector intersectedFacesLocalA; - std::vector intersectedFacesLocalB; + std::unordered_set intersectedFaceIdsLocalA; + std::unordered_set intersectedFaceIdsLocalB; // #pragma omp for for (int polygonIndex = 0; polygonIndex < numPolygons; polygonIndex++) { - MVector normal; - meshBFn.getPolygonNormal(polygonIndex, normal); - TriangleData triangle; int numTrianglesInPolygon = triangleCounts[polygonIndex]; int triangleVerticesOffset = polygonTriangleOffsets[polygonIndex]; - int triangleIndicesOffset = polygonIndexOffsets[polygonIndex]; + // int triangleIndicesOffset = polygonIndexOffsets[polygonIndex]; for (int triangleIndex = 0; triangleIndex < numTrianglesInPolygon; triangleIndex++) { - // Get the vertex positions of each triangle + int vertexId0 = triangleVertices[triangleVerticesOffset + triangleIndex * 3 + 0]; int vertexId1 = triangleVertices[triangleVerticesOffset + triangleIndex * 3 + 1]; int vertexId2 = triangleVertices[triangleVerticesOffset + triangleIndex * 3 + 2]; MPoint p0 = vertexPositions[vertexId0] * offset; MPoint p1 = vertexPositions[vertexId1] * offset; MPoint p2 = vertexPositions[vertexId2] * offset; - TriangleData triangle(polygonIndex, triangleIndex, p0, p1, p2, normal); + TriangleData triangle(polygonIndex, triangleIndex, p0, p1, p2); - // Check intersection between triangle and the kernel + // Check intersection between triangle and the octree (kernel) std::vector intersectedTriangles = kernel->intersectKernelTriangle(triangle); // If there is any intersection, store the intersection data into intersectedVertexIdsLocal if (!intersectedTriangles.empty()) { for(int k = 0; k < intersectedTriangles.size(); ++k) { - IntersectionMarkerData::FaceData faceDataA; - faceDataA.vertices.append(intersectedTriangles[k].vertices[0] + intersectedTriangles[k].normal * 0.001); - faceDataA.vertices.append(intersectedTriangles[k].vertices[1] + intersectedTriangles[k].normal * 0.001); - faceDataA.vertices.append(intersectedTriangles[k].vertices[2] + intersectedTriangles[k].normal * 0.001); - intersectedFacesA.push_back(faceDataA); - - IntersectionMarkerData::FaceData faceDataB; - faceDataB.vertices.append(p0 + normal * 0.001); - faceDataB.vertices.append(p1 + normal * 0.001); - faceDataB.vertices.append(p2 + normal * 0.001); - intersectedFacesB.push_back(faceDataB); + int a = intersectedTriangles[k].faceIndex; + int b = polygonIndex; + intersectedFaceIdsLocalA.insert(a); + intersectedFaceIdsLocalB.insert(b); } } } } + + // #pragma omp critical + { + intersectedFaceIdsA.insert(intersectedFaceIdsLocalA.begin(), intersectedFaceIdsLocalA.end()); + intersectedFaceIdsB.insert(intersectedFaceIdsLocalB.begin(), intersectedFaceIdsLocalB.end()); + } } return MStatus::kSuccess; @@ -650,21 +642,8 @@ std::shared_ptr IntersectionMarkerNode::getActiveKernel() MStatus IntersectionMarkerNode::getInputDagMesh(const MObject inputAttr, MFnMesh &outMesh) const { MPlug inputMeshPlug(thisMObject(), inputAttr); - - // Get the connected source node of the input plug. - MPlugArray connectedPlugs; - inputMeshPlug.connectedTo(connectedPlugs, true, false); - if (connectedPlugs.length() == 0) { - return MStatus::kFailure; // No source node is connected. - } - MObject sourceNode = connectedPlugs[0].node(); - - // Now sourceNode is the MObject of the connected source node (the mesh node). - // To get the MDagPath of the mesh node, use MFnDagNode. - MFnDagNode sourceDagNode(sourceNode); - MDagPath sourceDagPath; - sourceDagNode.getPath(sourceDagPath); - outMesh.setObject(sourceDagPath); + MObject value = inputMeshPlug.asMObject(); + outMesh.setObject(value); return MStatus::kSuccess; } diff --git a/src/intersectionMarkerNode.h b/src/intersectionMarkerNode.h index cea6481..798f323 100644 --- a/src/intersectionMarkerNode.h +++ b/src/intersectionMarkerNode.h @@ -6,7 +6,6 @@ #include "SpatialDivisionKernel.h" #include "IntersectionMarkerData.h" -#include "utility.h" #include #include @@ -59,8 +58,8 @@ struct pair_hash { // The type for the value of the cache struct CacheResultType { - std::vector first; - std::vector second; + std::unordered_set first; + std::unordered_set second; }; @@ -180,9 +179,6 @@ std::shared_ptr getActiveKernel() const; static MString drawRegistrantId; static CacheType cache; - // std::unordered_set intersectedFaceIdsA; - // std::unordered_set intersectedFaceIdsB; - - std::vector intersectedFacesA; - std::vector intersectedFacesB; + std::unordered_set intersectedFaceIdsA; + std::unordered_set intersectedFaceIdsB; }; diff --git a/src/kernel/EmbreeKernel.cpp b/src/kernel/EmbreeKernel.cpp index 9eba5d3..75a2fb6 100644 --- a/src/kernel/EmbreeKernel.cpp +++ b/src/kernel/EmbreeKernel.cpp @@ -106,13 +106,11 @@ MStatus EmbreeKernel::build(const MObject& meshObject, const MBoundingBox& bbox, // collect all triangles std::vector primitives; MItMeshPolygon itPoly(meshObject); - MVector normal; - int numTriangles; int primId = 0; for(; !itPoly.isDone(); itPoly.next()) { + int numTriangles; itPoly.numTriangles(numTriangles); - itPoly.getNormal(normal, MSpace::kObject); for (int triangleId=0; triangleId < numTriangles; ++triangleId) { MPointArray points; @@ -123,8 +121,7 @@ MStatus EmbreeKernel::build(const MObject& meshObject, const MBoundingBox& bbox, triangleId, points[0] * offsetMatrix, points[1] * offsetMatrix, - points[2] * offsetMatrix, - normal); + points[2] * offsetMatrix); RTCBuildPrimitive prim; prim.lower_x = (float)triangle.bbox.min().x; diff --git a/src/kernel/KDTreeKernel.cpp b/src/kernel/KDTreeKernel.cpp index 037f828..3f22b18 100644 --- a/src/kernel/KDTreeKernel.cpp +++ b/src/kernel/KDTreeKernel.cpp @@ -16,8 +16,6 @@ std::vector KDTreeKernel::extractTriangles( MItMeshPolygon itPoly(meshObject); for(; !itPoly.isDone(); itPoly.next()) { - MVector normal; - itPoly.getNormal(normal, MSpace::kObject); int numTriangles; itPoly.numTriangles(numTriangles); @@ -31,8 +29,7 @@ std::vector KDTreeKernel::extractTriangles( triangleId, points[0] * offsetMatrix, points[1] * offsetMatrix, - points[2] * offsetMatrix, - normal); + points[2] * offsetMatrix); triangles.push_back(triangle); } diff --git a/src/kernel/OctreeKernel.cpp b/src/kernel/OctreeKernel.cpp index c78116b..41077b0 100644 --- a/src/kernel/OctreeKernel.cpp +++ b/src/kernel/OctreeKernel.cpp @@ -30,8 +30,6 @@ MStatus OctreeKernel::build(const MObject& meshObject, const MBoundingBox& bbox, MItMeshPolygon itPoly(meshObject); // MGlobal::displayInfo("Building octree..."); for (; !itPoly.isDone(); itPoly.next()) { - MVector normal; - itPoly.getNormal(normal, MSpace::kObject); int numTriangles; itPoly.numTriangles(numTriangles); @@ -46,7 +44,7 @@ MStatus OctreeKernel::build(const MObject& meshObject, const MBoundingBox& bbox, MPoint p1 = points[1] * offsetMatrix; MPoint p2 = points[2] * offsetMatrix; - TriangleData triangle(itPoly.index(), i, p0, p1, p2, normal); + TriangleData triangle(itPoly.index(), i, p0, p1, p2); // Add the triangle to the octree insertTriangle(root, triangle, 0); } diff --git a/src/utility.h b/src/utility.h index 5cb72b0..474f1a5 100644 --- a/src/utility.h +++ b/src/utility.h @@ -41,10 +41,9 @@ struct TriangleData int triangleIndex; MPoint vertices[3]; MBoundingBox bbox; - MVector normal; TriangleData() = default; - TriangleData(int faceIndex, int triangleIndex, MPoint v0, MPoint v1, MPoint v2, const MVector& n) + TriangleData(int faceIndex, int triangleIndex, MPoint v0, MPoint v1, MPoint v2) : faceIndex(faceIndex), triangleIndex(triangleIndex) { vertices[0] = v0; @@ -54,8 +53,6 @@ struct TriangleData bbox.expand(v0); bbox.expand(v1); bbox.expand(v2); - - normal = n; } MPoint center() const From 245a1dc165472dad50e4768dd811bbad87ba8474 Mon Sep 17 00:00:00 2001 From: yamahigashi Date: Wed, 25 Sep 2024 20:17:38 +0900 Subject: [PATCH 3/3] added maya2025 --- buildAll.bat | 1 + 1 file changed, 1 insertion(+) diff --git a/buildAll.bat b/buildAll.bat index 265113a..764ba53 100644 --- a/buildAll.bat +++ b/buildAll.bat @@ -8,6 +8,7 @@ rem SET COMPILER=Visual Studio 15 2017 Win64 SET COMPILER=Visual Studio 16 2019 rem SET COMPILER=Visual Studio 17 2022 +call :build_for_maya 2025 call :build_for_maya 2024 call :build_for_maya 2023 call :build_for_maya 2022