格式支持图元zIndex
parent
38bd57c4c9
commit
4aa40addd1
|
@ -105,7 +105,7 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod
|
|||
|
||||
if (paintingProgram != nullptr && std::strcmp(str.C_Str(), "17876391417123941155.jpg") == 0)
|
||||
{
|
||||
qDebug() << str.C_Str();
|
||||
qDebug() << str.C_Str() << "Replaced";
|
||||
// 初始化网格
|
||||
PaintingMesh* m_mesh = new PaintingMesh(glFunc, paintingProgram, model);
|
||||
// 遍历网格的每个顶点
|
||||
|
@ -144,7 +144,7 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod
|
|||
//root
|
||||
1,2,
|
||||
3,4, 5,6,
|
||||
7,0, 7,30./360* 4294967296 /*右儿子用来表示旋转角度*/, 8,0, 7,0,
|
||||
7,0, 7,30./360* 65536 + 1*65536 /*右儿子用来表示旋转角度和层数*/, 8,0, 7,0,
|
||||
//elememt0
|
||||
1,2,
|
||||
5+28/*contour索引,由于contour不定长,这里需要给到contour在elementIndex中位置*/,5+12/*style索引,在elementData中位置*/, 3,4,
|
||||
|
|
|
@ -532,36 +532,9 @@ struct Stack
|
|||
}
|
||||
} stack, elementStack;
|
||||
|
||||
void main()
|
||||
vec3 drawElement(uint elementIndex, vec2 localUV, inout vec3 debugBVH = vec3(0))
|
||||
{
|
||||
// gBaseColor = vec4(TexCoords,1,1);
|
||||
// gBaseColor = vec4(240./255, 220./255,157./255,1);
|
||||
// gBaseColor = vec4(bvh[0].bound==vec4(0,0,1,1));
|
||||
|
||||
vec2 uv = vec2(1., 1.) - TexCoords * 2;
|
||||
vec3 debugBVH = vec3(0);
|
||||
bool debugHit = false;
|
||||
stack.top = 0;
|
||||
uint index = 0;
|
||||
while (index < bvhLength || !stack.empty())
|
||||
{
|
||||
while (index < bvhLength)
|
||||
{
|
||||
vec4 bound = bvhBound[index];
|
||||
uint leftChild = bvhChildren[index].x;
|
||||
if (leftChild >= bvhLength)
|
||||
{
|
||||
float angle = float(bvhChildren[index].y) / 4294967296. * 2 * PI;
|
||||
mat2 rotation = {{cos(angle), -sin(angle)}, {sin(angle), cos(angle)}};
|
||||
vec2 localUV = uv - (bound.xy + bound.zw) / 2;
|
||||
localUV = rotation * localUV;
|
||||
localUV /= (bound.zw - bound.xy) / 2;
|
||||
if (all(lessThan(vec2(-1), localUV)) && all(lessThan(localUV, vec2(1))))
|
||||
{
|
||||
uint elementIndex = leftChild - bvhLength;
|
||||
//debugBVH.bg += 0.5 * (localUV + vec2(1));
|
||||
debugBVH = vec3(0);
|
||||
////////////////////////////ͼԪÄÚBVH/////////////////////////////////
|
||||
vec4 elementColor = vec4(0);
|
||||
|
||||
uvec4 currentOffset = elementOffset[elementIndex];
|
||||
uint elementBvhRoot = currentOffset.x;
|
||||
|
@ -585,15 +558,16 @@ void main()
|
|||
{
|
||||
debugBVH.g += 0.5;
|
||||
|
||||
|
||||
uint styleIndex = bvhChildren[elementBvhRoot + elementBvhIndex].y - elementBvhLength;
|
||||
|
||||
// for(int i = 0; i<200;i++)
|
||||
if (elementData[styleIndex] == 0.) //Ãæ
|
||||
{
|
||||
|
||||
uint lineCount = elementIndexs[leftChild - elementBvhLength];
|
||||
uint num_its = 0;
|
||||
for(uint contourIterator = leftChild-elementBvhLength+1; contourIterator<=leftChild-elementBvhLength+lineCount; contourIterator++ )
|
||||
|
||||
for (uint contourIterator = leftChild - elementBvhLength + 1;
|
||||
contourIterator <= leftChild - elementBvhLength + lineCount; contourIterator++)
|
||||
{
|
||||
uint lineIndex = elementIndexs[contourIterator];
|
||||
uint p0Index = elementIndexs[linesOffset + 4 * lineIndex];
|
||||
|
@ -601,12 +575,14 @@ void main()
|
|||
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]);
|
||||
|
||||
|
||||
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 (p0 == p1 && p2 == p3)
|
||||
{
|
||||
|
@ -617,20 +593,14 @@ void main()
|
|||
num_its += cubic_bezier_int_test(localUV, p0, p1, p2, p3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (num_its % 2 == 1)
|
||||
{
|
||||
debugHit = true;
|
||||
elementColor = vec4(1);
|
||||
//debugHit = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
else if (elementData[styleIndex] == 1) //Ïß
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
elementBvhIndex = elementBvhLength;
|
||||
|
@ -641,7 +611,6 @@ void main()
|
|||
elementStack.push(elementBvhIndex);
|
||||
elementBvhIndex = leftChild;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
elementBvhIndex = elementBvhLength;
|
||||
|
@ -653,7 +622,46 @@ void main()
|
|||
elementBvhIndex = bvhChildren[elementBvhRoot + elementBvhIndex].y;
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////
|
||||
return elementColor.xyz;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
// gBaseColor = vec4(TexCoords,1,1);
|
||||
// gBaseColor = vec4(240./255, 220./255,157./255,1);
|
||||
// gBaseColor = vec4(bvh[0].bound==vec4(0,0,1,1));
|
||||
|
||||
vec2 uv = vec2(1., 1.) - TexCoords * 2;
|
||||
vec3 debugBVH = vec3(0);
|
||||
bool debugHit = false;
|
||||
stack.top = 0;
|
||||
uint index = 0;
|
||||
while (index < bvhLength || !stack.empty())
|
||||
{
|
||||
while (index < bvhLength)
|
||||
{
|
||||
vec4 bound = bvhBound[index];
|
||||
uint leftChild = bvhChildren[index].x;
|
||||
if (leftChild >= bvhLength)
|
||||
{
|
||||
uint zIndex = bvhChildren[index].y / 65535;
|
||||
float angle = (bvhChildren[index].y / 65535. - zIndex) * 2 * PI;
|
||||
|
||||
mat2 rotation = {{cos(angle), -sin(angle)}, {sin(angle), cos(angle)}};
|
||||
vec2 localUV = uv - (bound.xy + bound.zw) / 2;
|
||||
localUV = rotation * localUV;
|
||||
localUV /= (bound.zw - bound.xy) / 2;
|
||||
if (all(lessThan(vec2(-1), localUV)) && all(lessThan(localUV, vec2(1))))
|
||||
{
|
||||
if (zIndex == 1)
|
||||
debugBVH = vec3(1, 0, 1);
|
||||
uint elementIndex = leftChild - bvhLength;
|
||||
// debugBVH.bg += 0.5 * (localUV + vec2(1));
|
||||
// debugBVH = vec3(0);
|
||||
|
||||
debugHit = drawElement(leftChild - bvhLength, localUV, debugBVH) == vec3(1);
|
||||
|
||||
|
||||
// mainImage(debugBVH,localUV);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "MainWindow.h"
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QGuiApplication>
|
||||
|
||||
extern "C" {
|
||||
_declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
|
||||
|
|
Loading…
Reference in New Issue