解决绘制线单侧时的一些问题
parent
3a3374a886
commit
cbc4c2ebf5
|
@ -99,6 +99,7 @@
|
|||
<ItemGroup>
|
||||
<ClCompile Include="src\CaptionButton.cpp" />
|
||||
<ClCompile Include="src\Editor\EditorWidget.cpp" />
|
||||
<ClCompile Include="src\Editor\GraphicElement.cpp" />
|
||||
<ClCompile Include="src\IconWidget.cpp" />
|
||||
<ClCompile Include="src\main.cpp" />
|
||||
<ClCompile Include="src\MainWindow.cpp" />
|
||||
|
@ -150,6 +151,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtMoc Include="src\MainWindow.h" />
|
||||
<ClInclude Include="src\Editor\GraphicElement.h" />
|
||||
<ClInclude Include="src\Renderer\Painting\Element.h" />
|
||||
<ClInclude Include="src\Renderer\Painting\Painting.h" />
|
||||
<ClInclude Include="src\SvgParser.h" />
|
||||
|
|
|
@ -126,6 +126,9 @@
|
|||
<ClCompile Include="src\Renderer\Painting\Element.cpp">
|
||||
<Filter>Source Files\Renderer\Painting</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Editor\GraphicElement.cpp">
|
||||
<Filter>Source Files\Editor</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtMoc Include="src\Renderer\RendererGLWidget.h">
|
||||
|
@ -266,6 +269,9 @@
|
|||
<ClInclude Include="src\Renderer\Painting\Element.h">
|
||||
<Filter>Header Files\Renderer\Painting</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Editor\GraphicElement.h">
|
||||
<Filter>Header Files\Editor</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtRcc Include="MainWindow.qrc">
|
||||
|
|
|
@ -251,8 +251,65 @@ int cubic_bezier_int_test(vec2 uv, vec2 p0, vec2 p1, vec2 p2, vec2 p3)
|
|||
return n_ints;
|
||||
}
|
||||
|
||||
bool cubic_bezier_sign_test(vec2 uv, vec2 p0, vec2 p1, vec2 p2, vec2 p3)
|
||||
bvec3 cubic_bezier_sign_test(vec2 uv, vec2 p0, vec2 p1, vec2 p2, vec2 p3)
|
||||
{
|
||||
// float cu = (-p0.y + 3. * p1.y - 3. * p2.y + p3.y);
|
||||
// float qu = (3. * p0.y - 6. * p1.y + 3. * p2.y);
|
||||
// float li = (-3. * p0.y + 3. * p1.y);
|
||||
// float co = p0.y - uv.y;
|
||||
|
||||
// vec3 roots = vec3(1e38);
|
||||
// int n_roots;
|
||||
|
||||
// int n_ints = 0;
|
||||
// bvec3 result = bvec3(false);
|
||||
|
||||
// if (uv.x < min(min(p0.x, p1.x), min(p2.x, p3.x)))
|
||||
// {
|
||||
// if (uv.y >= min(p0.y, p3.y) && uv.y <= max(p0.y, p3.y))
|
||||
// {
|
||||
// n_ints = 1;
|
||||
// result[1] = !result[1];
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
|
||||
// if (abs(cu) < .0001)
|
||||
// {
|
||||
// n_roots = solve_quadric(vec2(co / qu, li / qu), roots.xy);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// n_roots = solve_cubic(vec3(co / cu, li / cu, qu / cu), roots);
|
||||
// }
|
||||
|
||||
// for (int i = 0; i < n_roots; i++)
|
||||
// {
|
||||
// //if (roots[i] >= 0. && roots[i] <= 1.)
|
||||
// {
|
||||
// float x_pos = -p0.x + 3. * p1.x - 3. * p2.x + p3.x;
|
||||
// x_pos = x_pos * roots[i] + 3. * p0.x - 6. * p1.x + 3. * p2.x;
|
||||
// x_pos = x_pos * roots[i] + -3. * p0.x + 3. * p1.x;
|
||||
// x_pos = x_pos * roots[i] + p0.x;
|
||||
|
||||
// if (x_pos > uv.x)
|
||||
// {
|
||||
// if(roots[i] >= 0. && roots[i] <= 1.){
|
||||
// result[1] = !result[1];
|
||||
// }
|
||||
// else if(roots[i] < 0.)
|
||||
// {
|
||||
// result[0]=!result[0];
|
||||
// }
|
||||
// else
|
||||
// result[2]=!result[2];
|
||||
// //n_ints++;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
float cu = (-p0.y + 3. * p1.y - 3. * p2.y + p3.y);
|
||||
float qu = (3. * p0.y - 6. * p1.y + 3. * p2.y);
|
||||
float li = (-3. * p0.y + 3. * p1.y);
|
||||
|
@ -261,24 +318,52 @@ bool cubic_bezier_sign_test(vec2 uv, vec2 p0, vec2 p1, vec2 p2, vec2 p3)
|
|||
vec3 roots = vec3(1e38);
|
||||
int n_roots = solve_cubic(vec3(co/cu,li/cu,qu/cu),roots);
|
||||
|
||||
int n_ints = 0;
|
||||
|
||||
//int n_ints = 0;
|
||||
bvec3 result = bvec3(false);
|
||||
for(int i=0;i<3;i++){
|
||||
if(i < n_roots){
|
||||
//if(roots[i] >= 0. && roots[i] <= 1.){
|
||||
if(roots[i] >= 0. && roots[i] <= 1.){
|
||||
float x_pos = -p0.x + 3. * p1.x - 3. * p2.x + p3.x;
|
||||
x_pos = x_pos * roots[i] + 3. * p0.x - 6. * p1.x + 3. * p2.x;
|
||||
x_pos = x_pos * roots[i] + -3. * p0.x + 3. * p1.x;
|
||||
x_pos = x_pos * roots[i] + p0.x;
|
||||
|
||||
if(x_pos < uv.x){
|
||||
n_ints++;
|
||||
if(x_pos > uv.x){
|
||||
result[1] = !result[1];
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return n_ints%2==0;
|
||||
vec2 tang1 = p0.xy - p1.xy;
|
||||
vec2 tang2 = p2.xy - p3.xy;
|
||||
|
||||
vec2 nor1 = vec2(tang1.y,-tang1.x);
|
||||
vec2 nor2 = vec2(tang2.y,-tang2.x);
|
||||
|
||||
if(p0.y < p1.y){
|
||||
if((uv.y<=p0.y) && (dot(uv-p0.xy,nor1)>0.)){
|
||||
result[0]=!result[0];
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(!(uv.y<=p0.y) && !(dot(uv-p0.xy,nor1)>0.)){
|
||||
result[0]=!result[0];
|
||||
}
|
||||
}
|
||||
|
||||
if(p2.y<p3.y){
|
||||
if(!(uv.y<=p3.y) && dot(uv-p3.xy,nor2)>0.){
|
||||
result[2]=!result[2];
|
||||
}
|
||||
}
|
||||
else{
|
||||
if((uv.y<=p3.y) && !(dot(uv-p3.xy,nor2)>0.)){
|
||||
result[2]=!result[2];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
// if(n_ints==0 || n_ints==2 || n_ints==4){
|
||||
// return 1;
|
||||
// }
|
||||
|
@ -840,11 +925,12 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal
|
|||
float strokeWidth = elementData[styleIndex+1];
|
||||
uint contourIndex = linesOffset + leftChild - 0x80000000;
|
||||
float d = 1e38;
|
||||
uint signTmp=0;
|
||||
bool signTmp=false;
|
||||
uint lineCountTmp=0;
|
||||
uint lastPIndex = -1;
|
||||
bool lastSign = false;
|
||||
uint lineCount = elementIndexs[contourIndex];
|
||||
|
||||
uint reverseFlag = 0;
|
||||
for ( uint contourIterator = contourIndex + 1;contourIterator < contourIndex + 1 + lineCount; contourIterator++)
|
||||
{
|
||||
uint lineIndex = elementIndexs[contourIterator];
|
||||
|
@ -854,6 +940,7 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal
|
|||
reverse = true;
|
||||
lineIndex -= 0x80000000;
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -863,52 +950,122 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal
|
|||
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]);
|
||||
|
||||
if(lastPIndex!=pxIndex[0])
|
||||
{
|
||||
if(lastSign)
|
||||
signTmp = !signTmp;
|
||||
float lineType = elementData[styleIndex+4];
|
||||
if(d<=0.001)
|
||||
{
|
||||
hitElement = true;
|
||||
elementColor = vec4(0,0,0,1);
|
||||
}
|
||||
else if(d<=strokeWidth && signTmp==lineCountTmp)
|
||||
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(d<levels[i])
|
||||
{
|
||||
elementColor = vec4(colors[i], 1);
|
||||
metallicRoughness = vec2(0,0.8);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if(i==3)
|
||||
{
|
||||
elementColor = vec4(colors[i], 1);
|
||||
metallicRoughness = vec2(0,0.8);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
if(reverse)
|
||||
reverseFlag = 1;
|
||||
d = 1e38;
|
||||
signTmp=0;
|
||||
signTmp=signTestResult[0];
|
||||
lineCountTmp = 0;
|
||||
|
||||
}
|
||||
lastPIndex = pxIndex[3];
|
||||
lastSign = signTestResult[2];
|
||||
lineCountTmp++;
|
||||
float lineType = elementData[styleIndex+4];
|
||||
d = min(d, cubic_bezier_dis(localUV, p[0], p[1], p[2], p[3], elementData[styleIndex+2]==0));
|
||||
if(lineType==2 || cubic_bezier_sign_test(localUV, p[0], p[1], p[2], p[3])==(reverse? lineType==0: lineType==1))
|
||||
++signTmp;
|
||||
if(signTestResult[1])
|
||||
signTmp = !signTmp;
|
||||
|
||||
|
||||
}
|
||||
if(lastSign)
|
||||
signTmp = !signTmp;
|
||||
float lineType = elementData[styleIndex+4];
|
||||
if(d<=0.001)
|
||||
{
|
||||
hitElement = true;
|
||||
elementColor = vec4(0,0,0,1);
|
||||
}
|
||||
else if(d<=strokeWidth && signTmp==lineCountTmp)
|
||||
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(d<levels[i])
|
||||
{
|
||||
elementColor = vec4(colors[i], 1);
|
||||
metallicRoughness = vec2(0,0.8);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if(i==3)
|
||||
{
|
||||
elementColor = vec4(colors[i], 1);
|
||||
metallicRoughness = vec2(0,0.8);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// float strokeWidth = elementData[styleIndex+1];
|
||||
|
|
|
@ -291,7 +291,7 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod
|
|||
1,2,
|
||||
encodeChild(20)/*contour索引,由于contour不定长,这里需要给到contour在elementIndex中位置*/,14/*style索引,在elementData中位置*/, encodeChild(24), 14,
|
||||
//elememt1
|
||||
encodeChild(12)/*contour乞多*/, 35
|
||||
encodeChild(12)/*contour乞多*/, 39
|
||||
|
||||
};
|
||||
std::vector<QVector4D> bvhBounds0 = {
|
||||
|
@ -331,11 +331,11 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod
|
|||
3, 0,2,3,
|
||||
//element1
|
||||
//lines
|
||||
0,0,1,1,
|
||||
0,7,8,1,
|
||||
1,2,3,4,
|
||||
5,5,6,6,
|
||||
//contours
|
||||
3, 0+ 0x80000000 ,1,2
|
||||
2, 0 ,1
|
||||
};
|
||||
|
||||
std::vector<GLfloat> elementData0 = {
|
||||
|
@ -352,16 +352,16 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod
|
|||
|
||||
//element1
|
||||
//points
|
||||
-0.5,-0.5, -0.5,0.5, 0.2,0.5, 0.5,0.2, 0.5,-0.5, -0.8,-0.5, -0.8,0.5,
|
||||
0.5,-0.5, 0.5,0.5, -0.2,0.5, -0.5,0.2, -0.5,-0.5, -0.8,-0.5, -0.8,0.5, 0.5,-0.4, 0.5,0.4,
|
||||
//strokeStyle
|
||||
//stroke
|
||||
1,
|
||||
//strokeWidth
|
||||
0.02,
|
||||
0.1,
|
||||
//strokeEndType
|
||||
0, //圆角
|
||||
//strokeFillType
|
||||
0, //데<>
|
||||
2, //데<>
|
||||
//线类型
|
||||
1, //左侧
|
||||
//线外描边宽度
|
||||
|
|
Loading…
Reference in New Issue