diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj index 0799117..cfc5a50 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj @@ -147,13 +147,13 @@ + + - - diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters index a03f502..87d0e67 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters @@ -122,9 +122,6 @@ Header Files\Editor - - Source Files - Header Files\Renderer @@ -140,6 +137,9 @@ Header Files + + Header Files + @@ -246,7 +246,7 @@ Header Files\Renderer - Source Files + Header Files diff --git a/ArchitectureColoredPainting/Shaders/painting.comp b/ArchitectureColoredPainting/Shaders/painting.comp index 3f87d1a..5fb4ae9 100644 --- a/ArchitectureColoredPainting/Shaders/painting.comp +++ b/ArchitectureColoredPainting/Shaders/painting.comp @@ -32,7 +32,7 @@ layout(std430, binding = 4) buffer elementOffsetBuffer ** @[2] pointsOffset ** @[3] linesOffset **********************/ - uint elementOffset[][4]; + uvec4 elementOffset[]; }; layout(std430, binding = 5) buffer elementIndexBuffer { @@ -45,7 +45,7 @@ layout(std430, binding = 6) buffer elementDataBuffer const float PI = 3.14159265358979; -const uint STACK_SIZE = 16; +const uint STACK_SIZE = 10; struct Stack { @@ -716,7 +716,7 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal bool hitElement = false; vec4 elementColor = vec4(-1); - uint currentOffset[4] = elementOffset[elementIndex]; + uvec4 currentOffset = elementOffset[elementIndex]; uint elementBvhRoot = currentOffset[0]; uint elementBvhLength = currentOffset[1]; uint pointsOffset = currentOffset[2]; @@ -752,32 +752,38 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal for ( uint contourIterator = contourIndex + 1;contourIterator < contourIndex + 1 + lineCount; contourIterator++) { uint lineIndex = elementIndexs[contourIterator]; - uint p0Index = elementIndexs[linesOffset + 4 * lineIndex]; - uint p1Index = elementIndexs[linesOffset + 4 * lineIndex + 1]; - uint p2Index = elementIndexs[linesOffset + 4 * lineIndex + 2]; - uint p3Index = elementIndexs[linesOffset + 4 * lineIndex + 3]; - - vec2 p0 = vec2(elementData[pointsOffset + 2 * p0Index], - elementData[pointsOffset + 2 * p0Index + 1]); - vec2 p1 = vec2(elementData[pointsOffset + 2 * p1Index], - elementData[pointsOffset + 2 * p1Index + 1]); - vec2 p2 = vec2(elementData[pointsOffset + 2 * p2Index], - elementData[pointsOffset + 2 * p2Index + 1]); - vec2 p3 = vec2(elementData[pointsOffset + 2 * p3Index], - elementData[pointsOffset + 2 * p3Index + 1]); - if( bound.z==p0.x && distance(localUV, p3)<0.01) + uint pLocation = linesOffset + 4 * lineIndex; + uvec4 pxIndex = uvec4(pointsOffset)+2*uvec4(elementIndexs[pLocation], elementIndexs[pLocation+1], elementIndexs[pLocation+2], elementIndexs[pLocation+3]); + uvec4 pyIndex = uvec4(1)+pxIndex; +// vec2 p0 = vec2(elementData[pxIndex[0]], +// elementData[pyIndex[0]]); +// vec2 p1 = vec2(elementData[pxIndex[1]], +// elementData[pyIndex[1]]); +// vec2 p2 = vec2(elementData[pxIndex[2]], +// elementData[pyIndex[2]]); +// vec2 p3 = vec2(elementData[pxIndex[3]], +// elementData[pyIndex[3]]); + mat4x2 p = mat4x2(elementData[pxIndex[0]], elementData[pyIndex[0]], + elementData[pxIndex[1]], elementData[pyIndex[1]], + elementData[pxIndex[2]],elementData[pyIndex[2]], + elementData[pxIndex[3]], elementData[pyIndex[3]]); +// vec2 p[4] = {vec2(elementData[pxIndex[0]], elementData[pyIndex[0]]), +// vec2(elementData[pxIndex[1]], elementData[pyIndex[1]]), +// vec2(elementData[pxIndex[2]],elementData[pyIndex[2]]), +// vec2(elementData[pxIndex[3]], elementData[pyIndex[3]])}; + if( bound.z==p[0].x && distance(localUV, p[3])<0.01) { debugBVH = vec3(0,0,1); } - else if(distance(localUV, p0)<0.01) + else if(distance(localUV, p[0])<0.01) debugBVH = vec3(1,1,1); - if (p0 == p1 && p2 == p3) - { - num_its += segment_int_test(localUV, p0, p3); - } - - else - num_its += cubic_bezier_int_test(localUV, p0, p1, p2, p3); +// if (p0 == p1 && p2 == p3) +// { +// num_its += segment_int_test(localUV, p0, p3); +// } +// +// else + num_its += cubic_bezier_int_test(localUV, p[0], p[1], p[2], p[3]); } if (num_its % 2 == 1 && elementColor.a<1) diff --git a/ArchitectureColoredPainting/src/CaptionButton.cpp b/ArchitectureColoredPainting/src/CaptionButton.cpp index ec4a2ea..833bb82 100644 --- a/ArchitectureColoredPainting/src/CaptionButton.cpp +++ b/ArchitectureColoredPainting/src/CaptionButton.cpp @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "captionbutton.h" +#include "CaptionButton.h" CaptionButton::CaptionButton(QWidget *parent) : QWidget(parent) { diff --git a/ArchitectureColoredPainting/src/Renderer/BvhTree.h b/ArchitectureColoredPainting/src/Renderer/BvhTree.h index 63a62c9..6faafbc 100644 --- a/ArchitectureColoredPainting/src/Renderer/BvhTree.h +++ b/ArchitectureColoredPainting/src/Renderer/BvhTree.h @@ -20,6 +20,8 @@ struct BvhTreeData { bound.x(), bound.y(), bound.z(), bound.w(), leftSon, rightSon); } + BvhTreeData(QVector4D bound, GLuint leftSon, GLuint rightSon) + : bound(bound), leftSon(leftSon), rightSon(rightSon) {} BvhTreeData() : leftSon(0), rightSon(0) {} ~BvhTreeData() {} diff --git a/ArchitectureColoredPainting/src/Renderer/Model.cpp b/ArchitectureColoredPainting/src/Renderer/Model.cpp index dc010de..38106b3 100644 --- a/ArchitectureColoredPainting/src/Renderer/Model.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Model.cpp @@ -121,7 +121,10 @@ GLuint encodeChild(GLuint index) { return 0x80000000 + index; } - +GLuint encodeZIndexAngle(GLuint zIndex, float angle) +{ + return GLuint(angle / 360 * 65536 + zIndex * 65536); +} Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 model) { aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex]; @@ -173,21 +176,23 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod } } - BvhTree bvhTree; - std::vector initBound; - for (int i = 0; i < 30000; i++) + BvhTree rootBvhTree; + vector rootBvhTreeData; + for (int i = 0; i < 1000; i++) { float x = (float)rand() / RAND_MAX * 2 - 1; float y = (float)rand() / RAND_MAX * 2 - 1; - float z = 0.01 + x;//(float)rand() / RAND_MAX * (0.1) + x; - float w = 0.01 + y;//(float)rand() / RAND_MAX * (0.1) + y; - initBound.push_back(QVector4D(x, y, z, w)); + float z = 0.05 + x;//(float)rand() / RAND_MAX * (0.1) + x; + float w = 0.05 + y;//(float)rand() / RAND_MAX * (0.1) + y; + rootBvhTreeData.push_back(BvhTreeData( QVector4D(x, y, z, w), 0, encodeZIndexAngle(1, (float)rand() / RAND_MAX * 360))); } + //rootBvhTreeData.push_back(BvhTreeData(QVector4D(-0.8, -0.8, -0.2, -0.1), 0, 0)); + //rootBvhTreeData.push_back(BvhTreeData(QVector4D(-0.7, -0.8, -0.2, -0.1), 0, 0)); /* initBound.push_back(QVector4D(-0.8, -0.8, -0.7, -0.7)); initBound.push_back(QVector4D(-0.8, 0.7, -0.7, 0.8)); initBound.push_back(QVector4D(0.7, -0.8, 0.8, -0.7)); initBound.push_back(QVector4D(0.7, 0.7, 0.8, 0.8));*/ - //bvhTree.buildBvhTree(initBound.data(), initBound.size()); + rootBvhTree.buildBvhTree(rootBvhTreeData.data(), rootBvhTreeData.size()); @@ -212,45 +217,51 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod //vector> lineSet = { {Point{-1,-1}, Point{1,-1}},{Point{1,-1}, Point{1,1}}, {Point{1,1}, Point{-1,1}},{Point{-1,1}, Point{-1,-1}} }; //vector> lineSet = { {Point{-1,-1}, Point{1,-1}},{Point{1,-1}, Point{1,1}}, {Point{1,1}, Point{-1,1}},{Point{-1,1}, Point{-1,-1}} }; - ShortCutTree shortCutTree(100); + ShortCutTree shortCutTree(20); shortCutTree.buildShortCutTree(lineSet); vector pointVector; vector lineVector; vector bvhTreeData = shortCutTree.getPointLineAndBvhTree(pointVector, lineVector); - qDebug() << pointVector; - qDebug() << lineVector; - for (BvhTreeData data : bvhTreeData) + qDebug() << "----------------------------------------------"; + qDebug() << "element0CellNum: " << bvhTreeData.size(); + //qDebug() << pointVector; + //qDebug() << lineVector; + /*for (BvhTreeData data : bvhTreeData) { data.show(); - } - - bvhTree.buildBvhTree(bvhTreeData.data(), bvhTreeData.size()); - std::vector children; - std::vector bounds; - bvhTree.getBvhArray(children, bounds); - qDebug() << children; - qDebug() << bounds; - - std::vector bvhChildren = { - //root - 1,2, - 3,4, 5,6, - encodeChild(0),0, encodeChild(0),GLuint(30. / 360 * 65536 + 1 * 65536) /*右儿子用来表示旋转角度和zIndex*/, encodeChild(0),0, encodeChild(0),0 - }; - std::vector bvhBounds = { - //root - QVector4D(-1,-1,1,1), - QVector4D(-0.9,-0.9,-0.1,0.9), QVector4D(0.1, -0.9,0.9,0.9), - QVector4D(-0.8,-0.8,-0.2,-0.1), QVector4D(-0.7,0.2,-0.2,0.7), QVector4D(0.2,-0.8,0.8,-0.1), QVector4D(0.2,0.1,0.8,0.8), - }; - bvhChildren.insert(bvhChildren.end(), children.begin(), children.end()); - bvhBounds.insert(bvhBounds.end(), bounds.begin(), bounds.end()); + }*/ + BvhTree element0Bvh; + element0Bvh.buildBvhTree(bvhTreeData.data(), bvhTreeData.size()); + std::vector element0Children; + std::vector element0Bounds; + element0Bvh.getBvhArray(element0Children, element0Bounds); + //qDebug() << element0Children; + //qDebug() << element0Bounds; + //std::vector bvhChildren = { + // //root + // 1,2, + // 3,4, 5,6, + // encodeChild(0),0, encodeChild(0),GLuint(30. / 360 * 65536 + 1 * 65536) /*右儿子用来表示旋转角度和zIndex*/, encodeChild(0),0, encodeChild(0),0 + //}; + //std::vector bvhBounds = { + // //root + // QVector4D(-1,-1,1,1), + // QVector4D(-0.9,-0.9,-0.1,0.9), QVector4D(0.1, -0.9,0.9,0.9), + // QVector4D(-0.8,-0.8,-0.2,-0.1), QVector4D(-0.7,0.2,-0.2,0.7), QVector4D(0.2,-0.8,0.8,-0.1), QVector4D(0.2,0.1,0.8,0.8), + //}; + std::vector bvhChildren; + std::vector bvhBounds; + rootBvhTree.getBvhArray(bvhChildren, bvhBounds); + + //qDebug() << bvhChildren; + bvhChildren.insert(bvhChildren.end(), element0Children.begin(), element0Children.end()); + bvhBounds.insert(bvhBounds.end(), element0Bounds.begin(), element0Bounds.end()); std::vector elementOffset = { //element0 - 7, //elementBvhRoot - (GLuint)bounds.size(), //elementBvhLength + rootBvhTree.getBvhNodeNum(), //elementBvhRoot + (GLuint)element0Bounds.size(), //elementBvhLength 0, //pointsOffset 0, //linesOffset }; @@ -265,99 +276,99 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod 240/255.,220/255.,160/255., 0.996,0.18, }; elementData.insert(elementData.begin(), pointVector.begin(), pointVector.end()); - qDebug() << elementIndex; - qDebug() << elementData; + //qDebug() << elementIndex; + //qDebug() << elementData; - std::vector bvhChildren0 = { - //root - 1,2, - 3,4, 5,6, - encodeChild(0),0, encodeChild(0),GLuint(30. / 360 * 65536 + 1 * 65536) /*右儿子用来表示旋转角度和zIndex*/, encodeChild(1),0, encodeChild(0),0, - //elememt0 - 1,2, - encodeChild(20)/*contour索引,由于contour不定长,这里需要给到contour在elementIndex中位置*/,14/*style索引,在elementData中位置*/, encodeChild(24), 14, - //elememt1 - encodeChild(0)/*line索引,element中第几条*/, 27 + //std::vector bvhChildren0 = { + // //root + // 1,2, + // 3,4, 5,6, + // encodeChild(0),0, encodeChild(0),GLuint(30. / 360 * 65536 + 1 * 65536) /*右儿子用来表示旋转角度和zIndex*/, encodeChild(1),0, encodeChild(0),0, + // //elememt0 + // 1,2, + // encodeChild(20)/*contour索引,由于contour不定长,这里需要给到contour在elementIndex中位置*/,14/*style索引,在elementData中位置*/, encodeChild(24), 14, + // //elememt1 + // encodeChild(0)/*line索引,element中第几条*/, 27 - }; - std::vector bvhBounds0 = { - //root - QVector4D(-1,-1,1,1), - QVector4D(-0.9,-0.9,-0.1,0.9), QVector4D(0.1, -0.9,0.9,0.9), - QVector4D(-0.8,-0.8,-0.2,-0.1), QVector4D(-0.7,0.2,-0.2,0.7), QVector4D(0.2,-0.8,0.8,-0.1), QVector4D(0.2,0.1,0.8,0.8), - //elememt0 - QVector4D(-1,-1,1,1), - QVector4D(-1,-1,-0.2,1), QVector4D(-0.2,-1,1,1), - //elememt1 - QVector4D(-1,-1,1,1) - }; - std::vector elementOffset0 = { - //element0 - 7, //elementBvhRoot - 3, //elementBvhLength - 0, //pointsOffset - 0, //linesOffset - //element1 - 10, //elementBvhRoot - 1, //elementBvhLength - 21, //pointsOffset - 28, //linesOffset - }; + //}; + //std::vector bvhBounds0 = { + // //root + // QVector4D(-1,-1,1,1), + // QVector4D(-0.9,-0.9,-0.1,0.9), QVector4D(0.1, -0.9,0.9,0.9), + // QVector4D(-0.8,-0.8,-0.2,-0.1), QVector4D(-0.7,0.2,-0.2,0.7), QVector4D(0.2,-0.8,0.8,-0.1), QVector4D(0.2,0.1,0.8,0.8), + // //elememt0 + // QVector4D(-1,-1,1,1), + // QVector4D(-1,-1,-0.2,1), QVector4D(-0.2,-1,1,1), + // //elememt1 + // QVector4D(-1,-1,1,1) + //}; + //std::vector elementOffset0 = { + // //element0 + // 7, //elementBvhRoot + // 3, //elementBvhLength + // 0, //pointsOffset + // 0, //linesOffset + // //element1 + // 10, //elementBvhRoot + // 1, //elementBvhLength + // 21, //pointsOffset + // 28, //linesOffset + //}; - std::vector elementIndex0 = { - //element0 - //lines, 全部当作三阶贝塞尔, 每条线四个点索引 - 0,1,1,2, - 0,0,3,3, - 3,4,4,5, - 2,2,5,5, - 5,5,6,6, - //contours, 第一个元素为线数,后面为轮廓线索引 - 3, 1,2,4, - 3, 0,2,3, - //element1 - //lines - 0,1,1,2 - }; + //std::vector elementIndex0 = { + // //element0 + // //lines, 全部当作三阶贝塞尔, 每条线四个点索引 + // 0,1,1,2, + // 0,0,3,3, + // 3,4,4,5, + // 2,2,5,5, + // 5,5,6,6, + // //contours, 第一个元素为线数,后面为轮廓线索引 + // 3, 1,2,4, + // 3, 0,2,3, + // //element1 + // //lines + // 0,1,1,2 + //}; - std::vector elementData0 = { - //element0 - //points - -0.2,1, -0.2,-0.2, 1,-0.2, -1,1, -1,-1, 1,-1, 1,1, - //fillStyle - //fill - 0, - //fillType - 0, //单色 - //fillColorMetallicRoughness - 1,1,0, 0,0.8, + //std::vector elementData0 = { + // //element0 + // //points + // -0.2,1, -0.2,-0.2, 1,-0.2, -1,1, -1,-1, 1,-1, 1,1, + // //fillStyle + // //fill + // 0, + // //fillType + // 0, //单色 + // //fillColorMetallicRoughness + // 1,1,0, 0,0.8, - //element1 - //points - 0,0.8, 1,0, 0,-0.8, - //strokeStyle - //stroke - 1, - //strokeWidth - 0.02, - //strokeEndType - 0, //圆角 - //strokeFillType - 0, //单色 - //线类型 - 1, //左侧 - //线外描边宽度 - 0, - //线外描边方式 - 0, //单色 - //strokeFillColorMetallicRoughness - 1,0,1, 0,0.8 - }; + // //element1 + // //points + // 0,0.8, 1,0, 0,-0.8, + // //strokeStyle + // //stroke + // 1, + // //strokeWidth + // 0.02, + // //strokeEndType + // 0, //圆角 + // //strokeFillType + // 0, //单色 + // //线类型 + // 1, //左侧 + // //线外描边宽度 + // 0, + // //线外描边方式 + // 0, //单色 + // //strokeFillColorMetallicRoughness + // 1,0,1, 0,0.8 + //}; //m_mesh->paintingIndex = paintingHelper->addPainting(bounds.size(), std::vector(children.begin()+2, children.end()), bounds, // elementOffset, elementIndex, elementData); - m_mesh->paintingIndex = paintingHelper->addPainting(7, bvhChildren, bvhBounds, + m_mesh->paintingIndex = paintingHelper->addPainting(rootBvhTree.getBvhNodeNum(), bvhChildren, bvhBounds, elementOffset, elementIndex, elementData); m_mesh->setupMesh();