格式支持图元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)
|
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);
|
PaintingMesh* m_mesh = new PaintingMesh(glFunc, paintingProgram, model);
|
||||||
// 遍历网格的每个顶点
|
// 遍历网格的每个顶点
|
||||||
|
@ -144,7 +144,7 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod
|
||||||
//root
|
//root
|
||||||
1,2,
|
1,2,
|
||||||
3,4, 5,6,
|
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
|
//elememt0
|
||||||
1,2,
|
1,2,
|
||||||
5+28/*contour索引,由于contour不定长,这里需要给到contour在elementIndex中位置*/,5+12/*style索引,在elementData中位置*/, 3,4,
|
5+28/*contour索引,由于contour不定长,这里需要给到contour在elementIndex中位置*/,5+12/*style索引,在elementData中位置*/, 3,4,
|
||||||
|
|
|
@ -532,36 +532,9 @@ struct Stack
|
||||||
}
|
}
|
||||||
} stack, elementStack;
|
} stack, elementStack;
|
||||||
|
|
||||||
void main()
|
vec3 drawElement(uint elementIndex, vec2 localUV, inout vec3 debugBVH = vec3(0))
|
||||||
{
|
{
|
||||||
// gBaseColor = vec4(TexCoords,1,1);
|
vec4 elementColor = vec4(0);
|
||||||
// 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/////////////////////////////////
|
|
||||||
|
|
||||||
uvec4 currentOffset = elementOffset[elementIndex];
|
uvec4 currentOffset = elementOffset[elementIndex];
|
||||||
uint elementBvhRoot = currentOffset.x;
|
uint elementBvhRoot = currentOffset.x;
|
||||||
|
@ -581,34 +554,37 @@ void main()
|
||||||
|
|
||||||
if (all(lessThan(bound.xy, localUV)) && all(lessThan(localUV, bound.zw)))
|
if (all(lessThan(bound.xy, localUV)) && all(lessThan(localUV, bound.zw)))
|
||||||
{
|
{
|
||||||
if (leftChild >= elementBvhLength )
|
if (leftChild >= elementBvhLength)
|
||||||
{
|
{
|
||||||
debugBVH.g += 0.5;
|
debugBVH.g += 0.5;
|
||||||
|
|
||||||
|
uint styleIndex = bvhChildren[elementBvhRoot + elementBvhIndex].y - elementBvhLength;
|
||||||
uint styleIndex = bvhChildren[elementBvhRoot + elementBvhIndex].y-elementBvhLength;
|
// for(int i = 0; i<200;i++)
|
||||||
|
if (elementData[styleIndex] == 0.) //Ãæ
|
||||||
if(elementData[styleIndex]==0. )//Ãæ
|
|
||||||
{
|
{
|
||||||
|
|
||||||
uint lineCount = elementIndexs[leftChild-elementBvhLength];
|
uint lineCount = elementIndexs[leftChild - elementBvhLength];
|
||||||
uint num_its = 0;
|
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 lineIndex = elementIndexs[contourIterator];
|
||||||
uint p0Index = elementIndexs[linesOffset+4*lineIndex];
|
uint p0Index = elementIndexs[linesOffset + 4 * lineIndex];
|
||||||
uint p1Index = elementIndexs[linesOffset+4*lineIndex+1];
|
uint p1Index = elementIndexs[linesOffset + 4 * lineIndex + 1];
|
||||||
uint p2Index = elementIndexs[linesOffset+4*lineIndex+2];
|
uint p2Index = elementIndexs[linesOffset + 4 * lineIndex + 2];
|
||||||
uint p3Index = elementIndexs[linesOffset+4*lineIndex+3];
|
uint p3Index = elementIndexs[linesOffset + 4 * lineIndex + 3];
|
||||||
|
|
||||||
vec2 p0 = vec2(elementData[pointsOffset+2*p0Index], elementData[pointsOffset+2*p0Index+1]);
|
vec2 p0 = vec2(elementData[pointsOffset + 2 * p0Index],
|
||||||
vec2 p1 = vec2(elementData[pointsOffset+2*p1Index], elementData[pointsOffset+2*p1Index+1]);
|
elementData[pointsOffset + 2 * p0Index + 1]);
|
||||||
vec2 p2 = vec2(elementData[pointsOffset+2*p2Index], elementData[pointsOffset+2*p2Index+1]);
|
vec2 p1 = vec2(elementData[pointsOffset + 2 * p1Index],
|
||||||
vec2 p3 = vec2(elementData[pointsOffset+2*p3Index], elementData[pointsOffset+2*p3Index+1]);
|
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)
|
||||||
|
|
||||||
if(p0==p1 && p2==p3)
|
|
||||||
{
|
{
|
||||||
num_its += segment_int_test(localUV, p0, p3);
|
num_its += segment_int_test(localUV, p0, p3);
|
||||||
}
|
}
|
||||||
|
@ -617,31 +593,24 @@ void main()
|
||||||
num_its += cubic_bezier_int_test(localUV, p0, p1, p2, p3);
|
num_its += cubic_bezier_int_test(localUV, p0, p1, p2, p3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (num_its % 2 == 1)
|
if (num_its % 2 == 1)
|
||||||
{
|
{
|
||||||
debugHit = true;
|
elementColor = vec4(1);
|
||||||
|
//debugHit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(elementData[styleIndex]==1)//Ïß
|
else if (elementData[styleIndex] == 1) //Ïß
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
elementBvhIndex = elementBvhLength;
|
elementBvhIndex = elementBvhLength;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//debugBVH.b += 0.2;
|
// debugBVH.b += 0.2;
|
||||||
elementStack.push(elementBvhIndex);
|
elementStack.push(elementBvhIndex);
|
||||||
elementBvhIndex = leftChild;
|
elementBvhIndex = leftChild;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
elementBvhIndex = elementBvhLength;
|
elementBvhIndex = elementBvhLength;
|
||||||
|
@ -653,7 +622,46 @@ void main()
|
||||||
elementBvhIndex = bvhChildren[elementBvhRoot + elementBvhIndex].y;
|
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);
|
// mainImage(debugBVH,localUV);
|
||||||
|
@ -661,7 +669,7 @@ void main()
|
||||||
// for(uint i=elementOffset[elementIndex][1];i<elementOffset[elementIndex][2];i+=7)
|
// for(uint i=elementOffset[elementIndex][1];i<elementOffset[elementIndex][2];i+=7)
|
||||||
// {
|
// {
|
||||||
// if(tri_test(localUV, vec2(elementData[i],elementData[i+1]),
|
// if(tri_test(localUV, vec2(elementData[i],elementData[i+1]),
|
||||||
//vec2(elementData[i+2],elementData[i+3]), vec2(elementData[i+4],elementData[i+5]), true))
|
// vec2(elementData[i+2],elementData[i+3]), vec2(elementData[i+4],elementData[i+5]), true))
|
||||||
// {
|
// {
|
||||||
// if(elementData[i+6]==0)
|
// if(elementData[i+6]==0)
|
||||||
// {
|
// {
|
||||||
|
@ -670,13 +678,13 @@ void main()
|
||||||
// else if(elementData[i+6]==1)
|
// else if(elementData[i+6]==1)
|
||||||
// {
|
// {
|
||||||
// if(-bezier_sd(localUV, vec2(elementData[i],elementData[i+1]),
|
// if(-bezier_sd(localUV, vec2(elementData[i],elementData[i+1]),
|
||||||
//vec2(elementData[i+2],elementData[i+3]), vec2(elementData[i+4],elementData[i+5]))>0)
|
// vec2(elementData[i+2],elementData[i+3]), vec2(elementData[i+4],elementData[i+5]))>0)
|
||||||
// debugHit=true;
|
// debugHit=true;
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
// if(bezier_sd(localUV, vec2(elementData[i],elementData[i+1]),
|
// if(bezier_sd(localUV, vec2(elementData[i],elementData[i+1]),
|
||||||
//vec2(elementData[i+2],elementData[i+3]), vec2(elementData[i+4],elementData[i+5]))>0)
|
// vec2(elementData[i+2],elementData[i+3]), vec2(elementData[i+4],elementData[i+5]))>0)
|
||||||
// debugHit=true;
|
// debugHit=true;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
|
#include <QGuiApplication>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
_declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
|
_declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
|
||||||
|
|
Loading…
Reference in New Issue