diff --git a/ArchitectureColoredPainting/Shaders/painting.comp b/ArchitectureColoredPainting/Shaders/painting.comp index fba3020..3df1c25 100644 --- a/ArchitectureColoredPainting/Shaders/painting.comp +++ b/ArchitectureColoredPainting/Shaders/painting.comp @@ -28,7 +28,7 @@ layout(std430, binding = 4) buffer elementOffsetBuffer { /********************** ** @[0] elementBvhRoot - ** @[1] elementBvhLength + ** @[1] styleOffset ** @[2] pointsOffset ** @[3] linesOffset **********************/ @@ -42,6 +42,7 @@ layout(std430, binding = 6) buffer elementDataBuffer { float elementData[]; //点和Style }; + const float PI = 3.14159265358979; @@ -832,6 +833,49 @@ float cubic_bezier_dis(vec2 uv, vec2 p0, vec2 p1, vec2 p2, vec2 p3, bool roundEn return sqrt(d0); } +void drawLine(in float d, in uint styleIndex, out vec4 elementColor, out vec2 metallicRoughness) +{ + elementColor = vec4(1); + metallicRoughness = vec2(0.8); + switch(int(elementData[styleIndex+3])) + { + case 0: + { + elementColor = vec4(elementData[styleIndex+7],elementData[styleIndex+8],elementData[styleIndex+9],1); + metallicRoughness = vec2(elementData[styleIndex+10],elementData[styleIndex+11]); + break; + } + case 1: + { + elementColor = vec4(mix(vec3(0), vec3(1), d), 1); + metallicRoughness = vec2(0,0.8); + break; + } + case 2: + { + float levels[] = {0.25,0.5,0.75}; + vec3 colors[] = {vec3(1,0,0), vec3(0,1,0), vec3(0,0,1), vec3(1,1,0)}; + int i = 0; + while(i<3) + { + if(d= elementBvhLength) { - if (any(greaterThan(bound.xy+vec2(0.001), localUV)) || any(greaterThan(localUV, bound.zw-vec2(0.001)))) + if (any(greaterThan(bound.xy+vec2(0.003), localUV)) || any(greaterThan(localUV, bound.zw-vec2(0.003)))) + { + debugBVH.g = 0; debugBVH.r += 1; - - uint styleIndex = bvhChildren[elementBvhRoot + elementBvhIndex].y; + } + //uint styleIndex = bvhChildren[elementBvhRoot + elementBvhIndex].y; + uint elementType = bvhChildren[elementBvhRoot + elementBvhIndex].y; + // for(int i = 0; i<200;i++) - if (elementData[styleIndex] == 0.) //面 + if (elementType == 0) //面 { uint contourIndex = linesOffset + leftChild - 0x80000000; @@ -892,12 +942,12 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal // 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, p[0])<0.01) - debugBVH = vec3(1,1,1); +// if( bound.z==p[0].x && distance(localUV, p[3])<0.01) +// { +// debugBVH = vec3(0,0,1); +// } +// 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); @@ -920,7 +970,7 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal } } - else if (elementData[styleIndex] == 1) //线 + else if (elementType == 1) //线 { float strokeWidth = elementData[styleIndex+1]; uint contourIndex = linesOffset + leftChild - 0x80000000; @@ -947,7 +997,7 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal mat4x2 p = mat4x2(elementData[pxIndex[0]], elementData[pyIndex[0]], elementData[pxIndex[1]], elementData[pyIndex[1]], - elementData[pxIndex[2]],elementData[pyIndex[2]], + elementData[pxIndex[2]], elementData[pyIndex[2]], elementData[pxIndex[3]], elementData[pyIndex[3]]); bvec3 signTestResult = cubic_bezier_sign_test(localUV, p[0], p[1], p[2], p[3]); @@ -957,50 +1007,16 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal if(lastSign) signTmp = !signTmp; float lineType = elementData[styleIndex+4]; - if(d<=0.001) + /*if(d<=0.001) { hitElement = true; elementColor = vec4(0,0,0,1); } - else if(d<=strokeWidth && (lineType==2 || signTmp==(lineType==1-reverseFlag))) + else*/ if(d<=strokeWidth && (lineType==2 || signTmp==(lineType==1-reverseFlag))) { d/=strokeWidth; hitElement = true; - elementColor = vec4(1); - metallicRoughness = vec2(0.8); - if(elementData[styleIndex+3]==0) - { - elementColor = vec4(elementData[styleIndex+7],elementData[styleIndex+8],elementData[styleIndex+9],1); - metallicRoughness = vec2(elementData[styleIndex+10],elementData[styleIndex+11]); - } - else if(elementData[styleIndex+3]==1) - { - elementColor = vec4(mix(vec3(0), vec3(1), d), 1); - metallicRoughness = vec2(0,0.8); - } - else if(elementData[styleIndex+3]==2) - { - float levels[] = {0.25,0.5,0.75}; - vec3 colors[] = {vec3(1,0,0), vec3(0,1,0), vec3(0,0,1), vec3(1,1,0)}; - int i = 0; - while(i<3) - { - if(dcolor.w) { - if (zIndex == 1) - debugBVH = vec3(1, 0, 1); + if (any(greaterThan(bound.xy+vec2(0.005), uv)) || any(greaterThan(uv, bound.zw-vec2(0.005)))) + debugBVH.g += 0.3; //uint elementIndex = leftChild - bvhLength; - debugBVH.bg += 0.5 * (localUV + vec2(1)); + //debugBVH.bg += 0.5 * (localUV + vec2(1)); - debugBVH = vec3(0); + //debugBVH = vec3(0); vec3 elementColor; vec2 elementMetallicRoughness; if(drawElement(leftChild - 0x80000000, localUV, elementColor, elementMetallicRoughness, debugBVH)) @@ -1187,7 +1170,9 @@ void main() } else if (all(lessThan(bound.xy, uv)) && all(lessThan(uv, bound.zw))) { - debugBVH.r += 0.02; + if (any(greaterThan(bound.xy+vec2(0.005), uv)) || any(greaterThan(uv, bound.zw-vec2(0.005)))) + debugBVH.g += 0.3; + //debugBVH.r += 0.02; stack.push(index); index = leftChild; } @@ -1205,9 +1190,14 @@ void main() imageStore(gBaseColor, pixelLocation, vec4(color.rgb,1)); imageStore(gMetallicRoughness, pixelLocation, vec4(metallicRoughness, 0, 1)); return; - if (color.a!=-1&&debugBVH==vec3(0)) - imageStore(gBaseColor, pixelLocation, vec4(vec3(1, 1, 0),1)); + if (/*color.a!=-1&&*/debugBVH==vec3(0)) + { + //imageStore(gBaseColor, pixelLocation, vec4(vec3(1, 1, 0),1)); + } else + { imageStore(gBaseColor, pixelLocation, vec4(debugBVH,1)); + imageStore(gMetallicRoughness, pixelLocation, vec4(0,0.8, 0, 1)); + } } \ No newline at end of file diff --git a/ArchitectureColoredPainting/Shaders/shadow_mapping.comp b/ArchitectureColoredPainting/Shaders/shadow_mapping.comp index 6e6c592..56741e5 100644 --- a/ArchitectureColoredPainting/Shaders/shadow_mapping.comp +++ b/ArchitectureColoredPainting/Shaders/shadow_mapping.comp @@ -68,7 +68,7 @@ vec3 fresnelSchlick(float cosTheta, vec3 F0) const int pcfRadius = 3; float getShadowFromLayer(vec3 fragPosWorldSpace, vec3 normal,int layer) { - float normalBias = 4. /** (1+pcfRadius)*/ * shadowBiases[layer]*max((1.0 - dot(normal, mainLightDirection)), 0.1)/textureSize(gShadowMap, 0).x; + float normalBias = 1.2*4. /** (1+pcfRadius)*/ * shadowBiases[layer]*max((1.0 - dot(normal, mainLightDirection)), 0.1)/textureSize(gShadowMap, 0).x; vec4 fragPosLightSpace = lightSpaceMatrices[layer] * vec4(fragPosWorldSpace+normal*normalBias, 1.0); // perform perspective divide vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w; diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp index 1b4dea4..567ccc1 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp @@ -32,6 +32,7 @@ QPainterPath GroupElement::getPaintObject() const if (sourceLayer != nullptr) { sourceLayer->refresh(); return sourceLayer->getCache(); + } else return QPainterPath(); } diff --git a/ArchitectureColoredPainting/src/Renderer/Model.cpp b/ArchitectureColoredPainting/src/Renderer/Model.cpp index 353b67e..7bde75f 100644 --- a/ArchitectureColoredPainting/src/Renderer/Model.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Model.cpp @@ -176,7 +176,7 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod m_mesh->indices.push_back(face.mIndices[j]); } } - + //////////////////////////////////////////////////////////////////////////////////////////////////////////// BvhTree rootBvhTree; vector rootBvhTreeData; for (int i = 0; i < 1000; i++) @@ -185,8 +185,13 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod float y = (float)rand() / RAND_MAX * 2 - 1; 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(x, y, z, w), 0, encodeZIndexAngle(1, (float)rand() / RAND_MAX * 360))); + //rootBvhTreeData.push_back(BvhTreeData(QVector4D(x, y, z, w), 0, encodeZIndexAngle(1, 0))); } + /*rootBvhTreeData.push_back(BvhTreeData(QVector4D(-0.7, -0.7, -0.1, -0.1), 0, encodeZIndexAngle(1, 0))); + rootBvhTreeData.push_back(BvhTreeData(QVector4D(-0.8, 0.2, -0.2, 0.8), 0, encodeZIndexAngle(1, 0))); + rootBvhTreeData.push_back(BvhTreeData(QVector4D(0.2, -0.8, 0.8, -0.2), 0, encodeZIndexAngle(1, 0))); + rootBvhTreeData.push_back(BvhTreeData(QVector4D(0.1, 0.1, 0.7, 0.7), 0, encodeZIndexAngle(1, 0)));*/ //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)); @@ -206,99 +211,99 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod // {{-0.5,0.3}, {-0.420466,0.379534}, {-0.736743,0.6}, {-0.624264,0.6}}, // {{-0.624264,0.6}, {-0.511785,0.6}, {-0.579534,0.979534}, {-0.5,0.9}} //}; - /*vector> lineSet = SvgParser("M377,459.61a11.26,11.26,0,0,1,11.27-11.27H696.12a11.27,11.27,0,0,0,11-8.62A359.84,359.84,0,0,0,708,280.56a11.26,11.26,0,0,0-11-8.73H388.27A11.26,11.26,0,0,1,377,260.57h0a11.26,11.26,0,0,1,11.27-11.26H683.71A11.32,11.32,0,0,0,694.28,234C649.8,113.69,542.57,23.85,412.3,4.12a11.22,11.22,0,0,0-12.76,11.17v158.9a11.26,11.26,0,0,0,11.26,11.27H583.12a11.32,11.32,0,0,0,9.26-17.75c-31.67-46.59-78.51-75.2-109.11-90.07a11.25,11.25,0,0,0-16.13,10.17V115.2a11.24,11.24,0,0,0,6.22,10.07l7.51,3.76a11.28,11.28,0,0,1,5,15.12h0a11.27,11.27,0,0,1-15.11,5l-20-10a11.27,11.27,0,0,1-6.22-10.07V54a11.27,11.27,0,0,1,14.62-10.75c5.11,1.59,125.66,40.35,172.24,149A11.27,11.27,0,0,1,621.11,208H388.27A11.26,11.26,0,0,1,377,196.73V11.36A11.32,11.32,0,0,0,365.89.08C363.34,0,360.79,0,358.22,0s-5.11,0-7.66.08a11.32,11.32,0,0,0-11.11,11.28V196.74A11.26,11.26,0,0,1,328.18,208H95.35A11.27,11.27,0,0,1,85,192.3c46.57-108.67,167.12-147.42,172.23-149A11.26,11.26,0,0,1,271.86,54v75.11a11.25,11.25,0,0,1-6.23,10.07l-20,10a11.27,11.27,0,0,1-15.11-5h0a11.26,11.26,0,0,1,5-15.11l7.52-3.76a11.27,11.27,0,0,0,6.22-10.07V87.82a11.25,11.25,0,0,0-16.14-10.16c-30.6,14.87-77.45,43.48-109.1,90.07a11.3,11.3,0,0,0,9.25,17.74H305.66a11.26,11.26,0,0,0,11.27-11.26V15.31A11.22,11.22,0,0,0,304.17,4.14C173.88,23.86,66.66,113.71,22.17,234a11.32,11.32,0,0,0,10.56,15.29H328.18a11.26,11.26,0,0,1,11.27,11.26v0a11.26,11.26,0,0,1-11.27,11.26H19.52a11.26,11.26,0,0,0-11,8.72,359.84,359.84,0,0,0,.83,159.16,11.26,11.26,0,0,0,11,8.61H328.18a11.26,11.26,0,0,1,11.27,11.27h0a11.26,11.26,0,0,1-11.27,11.26h-294a11.32,11.32,0,0,0-10.53,15.4C69,604.65,175.3,692.78,304.16,712.3a11.21,11.21,0,0,0,12.76-11.16V542.22A11.26,11.26,0,0,0,305.66,531h-166c-9.53,0-14.89,11.22-8.69,18.47,34.09,39.77,74.45,65.66,101.77,80.18a11.25,11.25,0,0,0,16.53-10V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,271.85,591v63.85A11.27,11.27,0,0,1,256.8,665.5c-4.45-1.59-109.58-40-171-139.9a11.27,11.27,0,0,1,9.59-17.17H328.18a11.26,11.26,0,0,1,11.27,11.26V705.08a11.32,11.32,0,0,0,11.11,11.28q3.82.07,7.66.08c2.57,0,5.12,0,7.67-.08A11.32,11.32,0,0,0,377,705.08V519.69a11.25,11.25,0,0,1,11.27-11.26H621.1a11.26,11.26,0,0,1,9.59,17.16c-61.46,99.87-166.59,138.3-171,139.9a11.27,11.27,0,0,1-15-10.61V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,467.14,591v28.6a11.25,11.25,0,0,0,16.53,10c27.33-14.53,67.68-40.42,101.77-80.19,6.2-7.23.85-18.46-8.69-18.46h-166a11.26,11.26,0,0,0-11.26,11.26V701.12a11.21,11.21,0,0,0,12.76,11.17c128.86-19.51,235.14-107.66,280.48-226a11.33,11.33,0,0,0-10.53-15.41h-294A11.25,11.25,0,0,1,377,459.61ZM35.27,399.53V316.9a11.26,11.26,0,0,1,11.27-11.26H669.92a11.25,11.25,0,0,1,11.26,11.26v82.63a11.25,11.25,0,0,1-11.26,11.26H46.54a11.27,11.27,0,0,1-11.27-11.26Z", 716.45, 716.44).parse(); + vector> lineSet = SvgParser("M377,459.61a11.26,11.26,0,0,1,11.27-11.27H696.12a11.27,11.27,0,0,0,11-8.62A359.84,359.84,0,0,0,708,280.56a11.26,11.26,0,0,0-11-8.73H388.27A11.26,11.26,0,0,1,377,260.57h0a11.26,11.26,0,0,1,11.27-11.26H683.71A11.32,11.32,0,0,0,694.28,234C649.8,113.69,542.57,23.85,412.3,4.12a11.22,11.22,0,0,0-12.76,11.17v158.9a11.26,11.26,0,0,0,11.26,11.27H583.12a11.32,11.32,0,0,0,9.26-17.75c-31.67-46.59-78.51-75.2-109.11-90.07a11.25,11.25,0,0,0-16.13,10.17V115.2a11.24,11.24,0,0,0,6.22,10.07l7.51,3.76a11.28,11.28,0,0,1,5,15.12h0a11.27,11.27,0,0,1-15.11,5l-20-10a11.27,11.27,0,0,1-6.22-10.07V54a11.27,11.27,0,0,1,14.62-10.75c5.11,1.59,125.66,40.35,172.24,149A11.27,11.27,0,0,1,621.11,208H388.27A11.26,11.26,0,0,1,377,196.73V11.36A11.32,11.32,0,0,0,365.89.08C363.34,0,360.79,0,358.22,0s-5.11,0-7.66.08a11.32,11.32,0,0,0-11.11,11.28V196.74A11.26,11.26,0,0,1,328.18,208H95.35A11.27,11.27,0,0,1,85,192.3c46.57-108.67,167.12-147.42,172.23-149A11.26,11.26,0,0,1,271.86,54v75.11a11.25,11.25,0,0,1-6.23,10.07l-20,10a11.27,11.27,0,0,1-15.11-5h0a11.26,11.26,0,0,1,5-15.11l7.52-3.76a11.27,11.27,0,0,0,6.22-10.07V87.82a11.25,11.25,0,0,0-16.14-10.16c-30.6,14.87-77.45,43.48-109.1,90.07a11.3,11.3,0,0,0,9.25,17.74H305.66a11.26,11.26,0,0,0,11.27-11.26V15.31A11.22,11.22,0,0,0,304.17,4.14C173.88,23.86,66.66,113.71,22.17,234a11.32,11.32,0,0,0,10.56,15.29H328.18a11.26,11.26,0,0,1,11.27,11.26v0a11.26,11.26,0,0,1-11.27,11.26H19.52a11.26,11.26,0,0,0-11,8.72,359.84,359.84,0,0,0,.83,159.16,11.26,11.26,0,0,0,11,8.61H328.18a11.26,11.26,0,0,1,11.27,11.27h0a11.26,11.26,0,0,1-11.27,11.26h-294a11.32,11.32,0,0,0-10.53,15.4C69,604.65,175.3,692.78,304.16,712.3a11.21,11.21,0,0,0,12.76-11.16V542.22A11.26,11.26,0,0,0,305.66,531h-166c-9.53,0-14.89,11.22-8.69,18.47,34.09,39.77,74.45,65.66,101.77,80.18a11.25,11.25,0,0,0,16.53-10V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,271.85,591v63.85A11.27,11.27,0,0,1,256.8,665.5c-4.45-1.59-109.58-40-171-139.9a11.27,11.27,0,0,1,9.59-17.17H328.18a11.26,11.26,0,0,1,11.27,11.26V705.08a11.32,11.32,0,0,0,11.11,11.28q3.82.07,7.66.08c2.57,0,5.12,0,7.67-.08A11.32,11.32,0,0,0,377,705.08V519.69a11.25,11.25,0,0,1,11.27-11.26H621.1a11.26,11.26,0,0,1,9.59,17.16c-61.46,99.87-166.59,138.3-171,139.9a11.27,11.27,0,0,1-15-10.61V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,467.14,591v28.6a11.25,11.25,0,0,0,16.53,10c27.33-14.53,67.68-40.42,101.77-80.19,6.2-7.23.85-18.46-8.69-18.46h-166a11.26,11.26,0,0,0-11.26,11.26V701.12a11.21,11.21,0,0,0,12.76,11.17c128.86-19.51,235.14-107.66,280.48-226a11.33,11.33,0,0,0-10.53-15.41h-294A11.25,11.25,0,0,1,377,459.61ZM35.27,399.53V316.9a11.26,11.26,0,0,1,11.27-11.26H669.92a11.25,11.25,0,0,1,11.26,11.26v82.63a11.25,11.25,0,0,1-11.26,11.26H46.54a11.27,11.27,0,0,1-11.27-11.26Z", 716.45, 716.44).parse(); qDebug() << lineSet.size(); for (vector& line : lineSet) { for (Point& p : line) p.show(); std::cout << std::endl; + } + + + ShortCutTree shortCutTree(20); + shortCutTree.buildShortCutTree(lineSet); + vector pointVector; + vector lineVector; + vector bvhTreeData = shortCutTree.getPointLineAndBvhTree(pointVector, lineVector); + for (auto& data : bvhTreeData) + data.rightSon = 0; + qDebug() << "----------------------------------------------"; + qDebug() << "element0CellNum: " << bvhTreeData.size(); + //qDebug() << pointVector; + //qDebug() << lineVector; + /*for (BvhTreeData data : bvhTreeData) + { + data.show(); }*/ + 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()); - //ShortCutTree shortCutTree(20); - //shortCutTree.buildShortCutTree(lineSet); - //vector pointVector; - //vector lineVector; - //vector bvhTreeData = shortCutTree.getPointLineAndBvhTree(pointVector, lineVector); - //for (auto& data : bvhTreeData) - // data.rightSon = 0; - //qDebug() << "----------------------------------------------"; - //qDebug() << "element0CellNum: " << bvhTreeData.size(); - ////qDebug() << pointVector; - ////qDebug() << lineVector; - ///*for (BvhTreeData data : bvhTreeData) - //{ - // data.show(); - //}*/ - //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 elementIndex = lineVector; + std::vector elementData = { + //fillStyle + //fill + 0, + //fillType + 0, //单色 + //fillColorMetallicRoughness + 240/255.,220/255.,160/255., 0.996,0.18, + }; + std::vector elementOffset = { + //element0 + rootBvhTree.getBvhNodeNum(), //elementBvhRoot + 0, //styleOffset + (GLuint)elementData.size(), //pointsOffset + 0, //linesOffset + }; + elementData.insert(elementData.end(), pointVector.begin(), pointVector.end()); + //qDebug() << elementIndex; + //qDebug() << elementData; - //std::vector elementIndex = lineVector; - //std::vector elementData = { - // //fillStyle - // //fill - // 0, - // //fillType - // 0, //单色 - // //fillColorMetallicRoughness - // 240/255.,220/255.,160/255., 0.996,0.18, - //}; - //std::vector elementOffset = { - // //element0 - // rootBvhTree.getBvhNodeNum(), //elementBvhRoot - // (GLuint)element0Bounds.size(), //elementBvhLength - // (GLuint)elementData.size(), //pointsOffset - // 0, //linesOffset - //}; - //elementData.insert(elementData.end(), pointVector.begin(), pointVector.end()); - ////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, + encodeChild(2),0, encodeChild(1),GLuint(30. / 360 * 65536 + 1 * 65536) /*右儿子用来表示旋转角度和zIndex*/, encodeChild(3),0, encodeChild(0),0, //elememt0 1,2, - encodeChild(20)/*contour索引,由于contour不定长,这里需要给到contour在elementIndex中位置*/,14/*style索引,在elementData中位置*/, encodeChild(24), 14, + encodeChild(20)/*contour索引,由于contour不定长,这里需要给到contour在elementIndex中位置*/,0/*封闭图形*/, encodeChild(24), 0, //elememt1 - encodeChild(12)/*contour索引*/, 39 + encodeChild(12)/*contour索引*/, 1/*线*/ }; 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), + 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.3,0.2,0.7,0.7), //elememt0 QVector4D(-1,-1,1,1), QVector4D(-1,-1,-0.2,1), QVector4D(-0.2,-1,1,1), @@ -308,12 +313,22 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod std::vector elementOffset0 = { //element0 7, //elementBvhRoot - 3, //elementBvhLength + 14, //styleOffset 0, //pointsOffset 0, //linesOffset //element1 10, //elementBvhRoot - 1, //elementBvhLength + 39, //styleOffset + 21, //pointsOffset + 28, //linesOffset + //element2 + 10, //elementBvhRoot + 51, //styleOffset + 21, //pointsOffset + 28, //linesOffset + //element3 + 10, //elementBvhRoot + 63, //styleOffset 21, //pointsOffset 28, //linesOffset }; @@ -361,6 +376,23 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod //strokeEndType 0, //圆角 //strokeFillType + 0, //单色 + //线类型 + 2, //左侧 + //线外描边宽度 + 0, + //线外描边方式 + 0, //单色 + //strokeFillColorMetallicRoughness + 1,0,1, 0,0.8, + //strokeStyle + //stroke + 1, + //strokeWidth + 0.1, + //strokeEndType + 0, //圆角 + //strokeFillType 2, //单色 //线类型 1, //左侧 @@ -369,13 +401,30 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod //线外描边方式 0, //单色 //strokeFillColorMetallicRoughness - 1,0,1, 0,0.8 + 1,0,1, 0,0.8, + //strokeStyle + //stroke + 1, + //strokeWidth + 0.1, + //strokeEndType + 0, //圆角 + //strokeFillType + 1, //单色 + //线类型 + 0, //左侧 + //线外描边宽度 + 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(rootBvhTree.getBvhNodeNum(), bvhChildren, bvhBounds, - // elementOffset, elementIndex, elementData); + /* m_mesh->paintingIndex = paintingHelper->addPainting(rootBvhTree.getBvhNodeNum(), bvhChildren, bvhBounds, + elementOffset, elementIndex, elementData);*/ m_mesh->paintingIndex = paintingHelper->addPainting(7, bvhChildren0, bvhBounds0, elementOffset0, elementIndex0, elementData0); m_mesh->setupMesh(); diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/ShortCutTree.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/ShortCutTree.cpp index 4bbebfa..7308c33 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/ShortCutTree.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Painting/ShortCutTree.cpp @@ -31,7 +31,7 @@ int ShortCutTree::getPointIndex(Point nowPoint) { bool ShortCutTree::IsBorderValueResonable(double value, set & valueSet) { bool isResonable = true; auto iter = valueSet.lower_bound(value); - if (iter != valueSet.end() && fabs(*iter-value) <= eps) { + if (iter != valueSet.end() && fabs(*iter - value) <= eps) { isResonable = false; } if (iter != valueSet.begin()) { @@ -64,12 +64,12 @@ bool ShortCutTree::isLineEqual(PointIndexVector& a, PointIndexVector& b) const { } void ShortCutTree::monotonization(vector& inLines, vector>& outLines) { - for (PointVector&l: inLines) { + for (PointVector& l : inLines) { std::shared_ptr nowLine; - switch(l.size()) { - case 2: nowLine.reset(new StraightLine(l)); break; - case 3: case 4: nowLine.reset(new CubicBezier(l)); break; - default: break; + switch (l.size()) { + case 2: nowLine.reset(new StraightLine(l)); break; + case 3: case 4: nowLine.reset(new CubicBezier(l)); break; + default: break; } nowLine->monotonization(outLines); outLines.push_back(nowLine); @@ -77,9 +77,9 @@ void ShortCutTree::monotonization(vector& inLines, vector > pointSet; - for (int & lineIndex : nowTreeNode.lineSet) { + for (int& lineIndex : nowTreeNode.lineSet) { int type = allLines[lineIndex]->judgeOneSideIntersection(nowTreeNode.bound.z(), nowTreeNode.bound.y(), nowTreeNode.bound.w(), false), lineIndexBegin, lineIndexEnd; if (type >= 2) { if (type == 2) { @@ -88,7 +88,7 @@ void ShortCutTree::generateShortCutSegment(ShortCutNode& nowTreeNode) { if (type == 3) { p = allLines[lineIndex]->getBegin(); } - lineIndexBegin = getPointIndex({ nowTreeNode.bound.z(), nowTreeNode.bound.w()}); + lineIndexBegin = getPointIndex({ nowTreeNode.bound.z(), nowTreeNode.bound.w() }); lineIndexEnd = getPointIndex({ nowTreeNode.bound.z(), p.y }); auto iter = pointSet.find({ lineIndexBegin, lineIndexEnd }); if (iter != pointSet.end()) { @@ -100,7 +100,7 @@ void ShortCutTree::generateShortCutSegment(ShortCutNode& nowTreeNode) { } } if (nowTreeNode.windingIncrement != 0) { - int lineIndexBegin = getPointIndex({ nowTreeNode.bound.z(), nowTreeNode.bound.y()}); + int lineIndexBegin = getPointIndex({ nowTreeNode.bound.z(), nowTreeNode.bound.y() }); int lineIndexEnd = getPointIndex({ nowTreeNode.bound.z(), nowTreeNode.bound.w() }); auto iter = pointSet.find({ lineIndexBegin, lineIndexEnd }); if (iter != pointSet.end()) { @@ -122,7 +122,7 @@ void ShortCutTree::generateShortCutSegment(ShortCutNode& nowTreeNode) { bool ShortCutTree::handleShortCutNode(ShortCutNode& fa, ShortCutNode& nowTreeNode, double yValue, vector& v, int& sumIncrement) { nowTreeNode.windingIncrement = sumIncrement; - for (int & lineIndex : fa.lineSet) { + for (int& lineIndex : fa.lineSet) { int type = allLines[lineIndex]->judgeOneSideIntersection(yValue, nowTreeNode.bound.x(), nowTreeNode.bound.z(), true); if (type == 2) sumIncrement++; @@ -132,7 +132,7 @@ bool ShortCutTree::handleShortCutNode(ShortCutNode& fa, ShortCutNode& nowTreeNod nowTreeNode.lineSet.push_back(lineIndex); } } - qDebug() << nowTreeNode.lineSet.size() ; + qDebug() << nowTreeNode.lineSet.size(); if (nowTreeNode.lineSet.size() <= requiredLineMin) { if (nowTreeNode.lineSet.empty() && nowTreeNode.windingIncrement == 0) return false; @@ -145,7 +145,7 @@ bool ShortCutTree::handleShortCutNode(ShortCutNode& fa, ShortCutNode& nowTreeNod v.push_back(nowTreeNode); return true; } - + } void ShortCutTree::simplifyLineVector() { @@ -245,7 +245,7 @@ void ShortCutTree::spliteToShortCutTree() { } if (isUpperDivided) { ++eastGroupSize; - lineBound.push({yMid, segment.second}); + lineBound.push({ yMid, segment.second }); for (auto& nowTreeNode : upperTreeNodes) { nowTreeNode.eastGroup = eastGroupSize; Q.push(nowTreeNode); @@ -276,7 +276,7 @@ vector ShortCutTree::getPointLineAndBvhTree(vector& resPoint std::cout << now.windingIncrement << ' '; } for (auto& mapIter : pointMap) { - tmpPoints.push_back({ mapIter.second , mapIter.first}); + tmpPoints.push_back({ mapIter.second , mapIter.first }); } sort(tmpPoints.begin(), tmpPoints.end()); for (auto& vectorIter : tmpPoints) { @@ -295,6 +295,7 @@ vector ShortCutTree::getPointLineAndBvhTree(vector& resPoint BvhTreeData oneData; oneData.leftSon = resLines.size(); //oneData.rightSon = rightSon; + oneData.rightSon = 0; oneData.bound = nowTreeNode.bound; std::cout << nowTreeNode.lineSet.size() << ' '; resLines.push_back(nowTreeNode.lineSet.size()); diff --git a/ArchitectureColoredPainting/src/Renderer/RendererWidget.cpp b/ArchitectureColoredPainting/src/Renderer/RendererWidget.cpp index d8a6bb8..e8cb926 100644 --- a/ArchitectureColoredPainting/src/Renderer/RendererWidget.cpp +++ b/ArchitectureColoredPainting/src/Renderer/RendererWidget.cpp @@ -9,6 +9,8 @@ RendererWidget::RendererWidget(QWidget *parent) ui.openGLWidget, &RendererGLWidget::setMainLightPitch); QObject::connect(ui.horizontalSlider_2, &QSlider::valueChanged, ui.openGLWidget, &RendererGLWidget::setMainLightYaw); + ui.horizontalSlider->setValue(105); + ui.horizontalSlider_2->setValue(80); } RendererWidget::~RendererWidget()