Fix bone direction parallel with y axis.

master
Jeremy Hu 2016-12-25 18:59:42 +09:30
parent 0efbc668a3
commit ecdc896e08
4 changed files with 41 additions and 12 deletions

View File

@ -53,6 +53,9 @@ I created the test nodes's geometry information from Blender. Here is the render
*Generate Mesh*
<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.
*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
- [ ] Render B-Mesh result
- [ ] Design UI for monster parts configuration

View File

@ -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},
{4, 0, 0, 0, 0.8, 1},
{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] = {
{0, 2}, {2, 4}, {4, 3}, {3, 1},
{4, 5}, {5, 6}
{4, 5}, {5, 6}, {4, 7}, {7, 8}
};

View File

@ -205,6 +205,20 @@ static int bmeshGenerateBallCrossSection(bmesh *bm, bmeshBall *ball,
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,
int firstBallIndex, int secondBallIndex) {
float step;
@ -215,6 +229,7 @@ static int bmeshGenerateInbetweenBallsBetween(bmesh *bm,
vec3 boneDirection;
vec3 normalizedBoneDirection;
vec3 worldYaxis = {0, 1, 0};
vec3 worldXaxis = {1, 0, 0};
bmeshBall *firstBall = bmeshGetBall(bm, firstBallIndex);
bmeshBall *secondBall = bmeshGetBall(bm, secondBallIndex);
bmeshBall *newBall;
@ -227,10 +242,20 @@ static int bmeshGenerateInbetweenBallsBetween(bmesh *bm,
vec3Sub(&firstBall->position, &secondBall->position, &boneDirection);
normalizedBoneDirection = boneDirection;
vec3Normalize(&normalizedBoneDirection);
vec3CrossProduct(&worldYaxis, &boneDirection, &localYaxis);
vec3Normalize(&localYaxis);
vec3CrossProduct(&localYaxis, &boneDirection, &localZaxis);
vec3Normalize(&localZaxis);
generateYZfromBoneDirection(&boneDirection,
&localYaxis, &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);
if (distance > BMESH_STEP_DISTANCE) {
@ -425,11 +450,8 @@ static int bmeshSweepFrom(bmesh *bm, bmeshBall *parent, bmeshBall *ball) {
ball->boneDirection = parent->boneDirection;
vec3RotateAlong(&ball->boneDirection, rotateAngle, &rotateAxis,
&ball->boneDirection);
vec3CrossProduct(&worldYaxis, &ball->boneDirection, &ball->localYaxis);
vec3Normalize(&ball->localYaxis);
vec3CrossProduct(&ball->localYaxis, &ball->boneDirection,
&ball->localZaxis);
vec3Normalize(&ball->localZaxis);
generateYZfromBoneDirection(&ball->boneDirection,
&ball->localYaxis, &ball->localZaxis);
} else {
// TODO:
}
@ -470,6 +492,7 @@ static bmeshBall *bmeshFindBallForConvexHull(bmesh *bm, bmeshBall *root,
if (!child) {
return ball;
}
ball->radius = 0;
return bmeshFindBallForConvexHull(bm, root, child);
}

View File

@ -258,6 +258,7 @@ void Render::paintGL() {
bmeshGenerateInbetweenBalls(bm);
bmeshSweep(bm);
bmeshStitch(bm);
}
drawBmeshBallRecursively(bm, bmeshGetRootBall(bm));