Fix bone direction parallel with y axis.
parent
0efbc668a3
commit
ecdc896e08
|
@ -52,7 +52,10 @@ I created the test nodes's geometry information from Blender. Here is the render
|
||||||
<img src="screenshot/dust3d_bmesh_skeleton.png" width="124" height="128"> <img src="screenshot/dust3d_bmesh_inbetween.png" width="124" height="128">
|
<img src="screenshot/dust3d_bmesh_skeleton.png" width="124" height="128"> <img src="screenshot/dust3d_bmesh_inbetween.png" width="124" height="128">
|
||||||
*Generate Mesh*
|
*Generate Mesh*
|
||||||
<img src="screenshot/dust3d_generate_quad.png" width="124" height="128">
|
<img src="screenshot/dust3d_generate_quad.png" width="124" height="128">
|
||||||
When I am implementing the B-Mesh algorithm, I am also think in the future, how to create a library of bunch of initial base models. There is a paper [the Skeleton of a Closed 3D Shape](http://www1.idc.ac.il/icgf/GraphicsSeminar2006/DCGskeleton06.pdf) described how to generate skeleton from mesh, this is the reverse progress of what I am doing, I think it can resolve the problem of insufficient initial base models, I can generate from tons of existed models.
|
When I am implementing the B-Mesh algorithm, I am also think in the future, how to create a library of bunch of initial base models. There is a paper [the Skeleton of a Closed 3D Shape](http://www1.idc.ac.il/icgf/GraphicsSeminar2006/DCGskeleton06.pdf) described how to generate skeleton from mesh, this is the reverse progress of what I am doing, I think it can resolve the problem of insufficient initial base models, I can generate from tons of existed models.
|
||||||
|
*Convex Hull*
|
||||||
|
After finish the rotation at the two connected bones, I need implement [3D Convex Hull](https://en.wikipedia.org/wiki/Convex_hull) algorithm at joint ball.
|
||||||
|
|
||||||
- [ ] Export Wavefront .obj
|
- [ ] Export Wavefront .obj
|
||||||
- [ ] Render B-Mesh result
|
- [ ] Render B-Mesh result
|
||||||
- [ ] Design UI for monster parts configuration
|
- [ ] Design UI for monster parts configuration
|
||||||
|
|
|
@ -3,10 +3,12 @@ const float bmeshTest1Balls[][6] = {
|
||||||
{2, -0.91403, 0.77069, 0.62299, 0.5}, {3, 2.25224, 0.74973, 0.85115, 0.5},
|
{2, -0.91403, 0.77069, 0.62299, 0.5}, {3, 2.25224, 0.74973, 0.85115, 0.5},
|
||||||
{4, 0, 0, 0, 0.8, 1},
|
{4, 0, 0, 0, 0.8, 1},
|
||||||
{5, 0.00920, -0.66115, -2.04601, 0.5},
|
{5, 0.00920, -0.66115, -2.04601, 0.5},
|
||||||
{6, 0.01726, -0.88224, -2.87471, 0.2}
|
{6, 0.01726, -0.88224, -2.87471, 0.2},
|
||||||
|
{7, 0, -2, 0.00, 0.2},
|
||||||
|
{8, -0.3, -2.8, 0.13, 0.5},
|
||||||
};
|
};
|
||||||
|
|
||||||
const int bmeshTest1Bones[][2] = {
|
const int bmeshTest1Bones[][2] = {
|
||||||
{0, 2}, {2, 4}, {4, 3}, {3, 1},
|
{0, 2}, {2, 4}, {4, 3}, {3, 1},
|
||||||
{4, 5}, {5, 6}
|
{4, 5}, {5, 6}, {4, 7}, {7, 8}
|
||||||
};
|
};
|
||||||
|
|
41
src/bmesh.c
41
src/bmesh.c
|
@ -205,6 +205,20 @@ static int bmeshGenerateBallCrossSection(bmesh *bm, bmeshBall *ball,
|
||||||
return 0;
|
return 0;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
static void generateYZfromBoneDirection(vec3 *boneDirection,
|
||||||
|
vec3 *localYaxis, vec3 *localZaxis) {
|
||||||
|
vec3 worldYaxis = {0, 1, 0};
|
||||||
|
vec3 worldXaxis = {1, 0, 0};
|
||||||
|
if (0 == vec3Angle(boneDirection, &worldYaxis)) {
|
||||||
|
vec3CrossProduct(&worldXaxis, boneDirection, localYaxis);
|
||||||
|
} else {
|
||||||
|
vec3CrossProduct(&worldYaxis, boneDirection, localYaxis);
|
||||||
|
}
|
||||||
|
vec3Normalize(localYaxis);
|
||||||
|
vec3CrossProduct(localYaxis, boneDirection, localZaxis);
|
||||||
|
vec3Normalize(localZaxis);
|
||||||
|
}
|
||||||
|
|
||||||
static int bmeshGenerateInbetweenBallsBetween(bmesh *bm,
|
static int bmeshGenerateInbetweenBallsBetween(bmesh *bm,
|
||||||
int firstBallIndex, int secondBallIndex) {
|
int firstBallIndex, int secondBallIndex) {
|
||||||
float step;
|
float step;
|
||||||
|
@ -215,6 +229,7 @@ static int bmeshGenerateInbetweenBallsBetween(bmesh *bm,
|
||||||
vec3 boneDirection;
|
vec3 boneDirection;
|
||||||
vec3 normalizedBoneDirection;
|
vec3 normalizedBoneDirection;
|
||||||
vec3 worldYaxis = {0, 1, 0};
|
vec3 worldYaxis = {0, 1, 0};
|
||||||
|
vec3 worldXaxis = {1, 0, 0};
|
||||||
bmeshBall *firstBall = bmeshGetBall(bm, firstBallIndex);
|
bmeshBall *firstBall = bmeshGetBall(bm, firstBallIndex);
|
||||||
bmeshBall *secondBall = bmeshGetBall(bm, secondBallIndex);
|
bmeshBall *secondBall = bmeshGetBall(bm, secondBallIndex);
|
||||||
bmeshBall *newBall;
|
bmeshBall *newBall;
|
||||||
|
@ -227,10 +242,20 @@ static int bmeshGenerateInbetweenBallsBetween(bmesh *bm,
|
||||||
vec3Sub(&firstBall->position, &secondBall->position, &boneDirection);
|
vec3Sub(&firstBall->position, &secondBall->position, &boneDirection);
|
||||||
normalizedBoneDirection = boneDirection;
|
normalizedBoneDirection = boneDirection;
|
||||||
vec3Normalize(&normalizedBoneDirection);
|
vec3Normalize(&normalizedBoneDirection);
|
||||||
vec3CrossProduct(&worldYaxis, &boneDirection, &localYaxis);
|
generateYZfromBoneDirection(&boneDirection,
|
||||||
vec3Normalize(&localYaxis);
|
&localYaxis, &localZaxis);
|
||||||
vec3CrossProduct(&localYaxis, &boneDirection, &localZaxis);
|
|
||||||
vec3Normalize(&localZaxis);
|
glColor3f(0.0, 0.0, 0.0);
|
||||||
|
drawDebugPrintf("<%f,%f,%f> <%f,%f,%f> <%f,%f,%f>",
|
||||||
|
localYaxis.x,
|
||||||
|
localYaxis.y,
|
||||||
|
localYaxis.z,
|
||||||
|
localZaxis.x,
|
||||||
|
localZaxis.y,
|
||||||
|
localZaxis.z,
|
||||||
|
boneDirection.x,
|
||||||
|
boneDirection.y,
|
||||||
|
boneDirection.z);
|
||||||
|
|
||||||
distance = vec3Length(&boneDirection);
|
distance = vec3Length(&boneDirection);
|
||||||
if (distance > BMESH_STEP_DISTANCE) {
|
if (distance > BMESH_STEP_DISTANCE) {
|
||||||
|
@ -425,11 +450,8 @@ static int bmeshSweepFrom(bmesh *bm, bmeshBall *parent, bmeshBall *ball) {
|
||||||
ball->boneDirection = parent->boneDirection;
|
ball->boneDirection = parent->boneDirection;
|
||||||
vec3RotateAlong(&ball->boneDirection, rotateAngle, &rotateAxis,
|
vec3RotateAlong(&ball->boneDirection, rotateAngle, &rotateAxis,
|
||||||
&ball->boneDirection);
|
&ball->boneDirection);
|
||||||
vec3CrossProduct(&worldYaxis, &ball->boneDirection, &ball->localYaxis);
|
generateYZfromBoneDirection(&ball->boneDirection,
|
||||||
vec3Normalize(&ball->localYaxis);
|
&ball->localYaxis, &ball->localZaxis);
|
||||||
vec3CrossProduct(&ball->localYaxis, &ball->boneDirection,
|
|
||||||
&ball->localZaxis);
|
|
||||||
vec3Normalize(&ball->localZaxis);
|
|
||||||
} else {
|
} else {
|
||||||
// TODO:
|
// TODO:
|
||||||
}
|
}
|
||||||
|
@ -470,6 +492,7 @@ static bmeshBall *bmeshFindBallForConvexHull(bmesh *bm, bmeshBall *root,
|
||||||
if (!child) {
|
if (!child) {
|
||||||
return ball;
|
return ball;
|
||||||
}
|
}
|
||||||
|
ball->radius = 0;
|
||||||
return bmeshFindBallForConvexHull(bm, root, child);
|
return bmeshFindBallForConvexHull(bm, root, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -258,6 +258,7 @@ void Render::paintGL() {
|
||||||
|
|
||||||
bmeshGenerateInbetweenBalls(bm);
|
bmeshGenerateInbetweenBalls(bm);
|
||||||
bmeshSweep(bm);
|
bmeshSweep(bm);
|
||||||
|
bmeshStitch(bm);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawBmeshBallRecursively(bm, bmeshGetRootBall(bm));
|
drawBmeshBallRecursively(bm, bmeshGetRootBall(bm));
|
||||||
|
|
Loading…
Reference in New Issue