diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2010-02-19 04:10:04 +0300 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2010-02-19 04:10:04 +0300 |
commit | 1234b55330f533ea9e52cd65ff8f9eda37808c6f (patch) | |
tree | 0a592e95dbf2e2eb5c707ecceb6df3fb7e0c63a1 /source/blender/freestyle/intern | |
parent | e5fd2b5bfcd4293a33ba261ee024c9ba80304933 (diff) |
Added support for procedural duplication (such as DupliVerts and DupliFaces).
Diffstat (limited to 'source/blender/freestyle/intern')
-rw-r--r-- | source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp | 81 | ||||
-rw-r--r-- | source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h | 10 |
2 files changed, 57 insertions, 34 deletions
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp index b6b6b50c07c..ab7e58287cf 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp @@ -19,7 +19,6 @@ BlenderFileLoader::~BlenderFileLoader() NodeGroup* BlenderFileLoader::Load() { ObjectInstanceRen *obi; - ObjectRen *obr; cout << "\n=== Importing triangular meshes into Blender ===" << endl; @@ -42,13 +41,14 @@ NodeGroup* BlenderFileLoader::Load() for(obi= (ObjectInstanceRen *) _re->instancetable.first; obi; obi=obi->next) { if (!(obi->lay & _re->scene->lay & _srl->lay)) continue; + char *name = obi->ob->id.name; + //cout << name[0] << name[1] << ":" << (name+2) <<; + //print_m4("obi->mat", obi->mat); - obr= obi->obr; - - if( obr->totvlak > 0) - insertShapeNode(obr, ++id); + if( obi->obr->totvlak > 0) + insertShapeNode(obi, ++id); else - cout << " Sorry, only vlak-based shapes are supported." << endl; + cout << "Warning: " << (name+2) << " is not a vlak-based object (ignored)" << endl; } //Returns the built scene. @@ -61,9 +61,9 @@ NodeGroup* BlenderFileLoader::Load() // check if each vertex of a triangle (V1, V2, V3) is clipped by the near/far plane // and calculate the number of triangles to be generated by clipping -int BlenderFileLoader::countClippedFaces(VertRen *v1, VertRen *v2, VertRen *v3, int clip[3]) +int BlenderFileLoader::countClippedFaces(float v1[3], float v2[3], float v3[3], int clip[3]) { - VertRen *v[3]; + float *v[3]; int numClipped, sum, numTris; v[0] = v1; @@ -71,10 +71,10 @@ int BlenderFileLoader::countClippedFaces(VertRen *v1, VertRen *v2, VertRen *v3, v[2] = v3; numClipped = sum = 0; for (int i = 0; i < 3; i++) { - if (v[i]->co[2] > _z_near) { + if (v[i][2] > _z_near) { clip[i] = CLIPPED_BY_NEAR; numClipped++; - } else if (v[i]->co[2] < _z_far) { + } else if (v[i][2] < _z_far) { clip[i] = CLIPPED_BY_FAR; numClipped++; } else { @@ -109,23 +109,23 @@ int BlenderFileLoader::countClippedFaces(VertRen *v1, VertRen *v2, VertRen *v3, // find the intersection point C between the line segment from V1 to V2 and // a clipping plane at depth Z (i.e., the Z component of C is known, while // the X and Y components are unknown). -void BlenderFileLoader::clipLine(VertRen *v1, VertRen *v2, float c[3], float z) +void BlenderFileLoader::clipLine(float v1[3], float v2[3], float c[3], float z) { double d[3]; for (int i = 0; i < 3; i++) - d[i] = v2->co[i] - v1->co[i]; - double t = (z - v1->co[2]) / d[2]; - c[0] = v1->co[0] + t * d[0]; - c[1] = v1->co[1] + t * d[1]; + d[i] = v2[i] - v1[i]; + double t = (z - v1[2]) / d[2]; + c[0] = v1[0] + t * d[0]; + c[1] = v1[1] + t * d[1]; c[2] = z; } // clip the triangle (V1, V2, V3) by the near and far clipping plane and // obtain a set of vertices after the clipping. The number of vertices // is at most 5. -void BlenderFileLoader::clipTriangle(int numTris, float triCoords[][3], VertRen *v1, VertRen *v2, VertRen *v3, int clip[3]) +void BlenderFileLoader::clipTriangle(int numTris, float triCoords[][3], float v1[3], float v2[3], float v3[3], int clip[3]) { - VertRen *v[3]; + float *v[3]; int i, j, k; v[0] = v1; @@ -135,7 +135,7 @@ void BlenderFileLoader::clipTriangle(int numTris, float triCoords[][3], VertRen for (i = 0; i < 3; i++) { j = (i + 1) % 3; if (clip[i] == NOT_CLIPPED) { - copy_v3_v3(triCoords[k++], v[i]->co); + copy_v3_v3(triCoords[k++], v[i]); if (clip[j] != NOT_CLIPPED) { clipLine(v[i], v[j], triCoords[k++], (clip[j] == CLIPPED_BY_NEAR) ? _z_near : _z_far); } @@ -205,24 +205,37 @@ void BlenderFileLoader::addTriangle(struct LoaderState *ls, float v1[3], float v } } -void BlenderFileLoader::insertShapeNode(ObjectRen *obr, int id) +void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id) { + ObjectRen *obr = obi->obr; + // We parse vlak nodes and count the number of faces after the clipping by // the near and far view planes is applied (Note: mesh vertices are in the // camera coordinate system). VlakRen *vlr; unsigned numFaces = 0; + float v1[3], v2[3], v3[3], v4[3]; int clip_1[3], clip_2[3]; for(int a=0; a < obr->totvlak; a++) { if((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; else vlr++; -// printf("v1 %f, %f, %f\n", vlr->v1->co[0], vlr->v1->co[1], vlr->v1->co[2]); -// printf("v2 %f, %f, %f\n", vlr->v2->co[0], vlr->v2->co[1], vlr->v2->co[2]); -// printf("v3 %f, %f, %f\n", vlr->v3->co[0], vlr->v3->co[1], vlr->v3->co[2]); -// if (vlr->v4) printf("v4 %f, %f, %f\n", vlr->v4->co[0], vlr->v4->co[1], vlr->v4->co[2]); - numFaces += countClippedFaces(vlr->v1, vlr->v2, vlr->v3, clip_1); + copy_v3_v3(v1, vlr->v1->co); + copy_v3_v3(v2, vlr->v2->co); + copy_v3_v3(v3, vlr->v3->co); + if (vlr->v4) copy_v3_v3(v4, vlr->v4->co); + if (obi->flag & R_TRANSFORMED) { + mul_m4_v3(obi->mat, v1); + mul_m4_v3(obi->mat, v2); + mul_m4_v3(obi->mat, v3); + if (vlr->v4) mul_m4_v3(obi->mat, v4); + } +// print_v3("v1", v1); +// print_v3("v2", v2); +// print_v3("v3", v3); +// if (vlr->v4) print_v3("v4", v4); + numFaces += countClippedFaces(v1, v2, v3, clip_1); if (vlr->v4) - numFaces += countClippedFaces(vlr->v1, vlr->v3, vlr->v4, clip_2); + numFaces += countClippedFaces(v1, v3, v4, clip_2); } // cout <<"numFaces " <<numFaces<<endl; if (numFaces == 0) @@ -272,10 +285,20 @@ void BlenderFileLoader::insertShapeNode(ObjectRen *obr, int id) // Lib3dsMaterial *mat=0; if((p & 255)==0) vlr = obr->vlaknodes[p>>8].vlak; else vlr++; + copy_v3_v3(v1, vlr->v1->co); + copy_v3_v3(v2, vlr->v2->co); + copy_v3_v3(v3, vlr->v3->co); + if (vlr->v4) copy_v3_v3(v4, vlr->v4->co); + if (obi->flag & R_TRANSFORMED) { + mul_m4_v3(obi->mat, v1); + mul_m4_v3(obi->mat, v2); + mul_m4_v3(obi->mat, v3); + if (vlr->v4) mul_m4_v3(obi->mat, v4); + } unsigned numTris_1, numTris_2; - numTris_1 = countClippedFaces(vlr->v1, vlr->v2, vlr->v3, clip_1); - numTris_2 = (vlr->v4) ? countClippedFaces(vlr->v1, vlr->v3, vlr->v4, clip_2) : 0; + numTris_1 = countClippedFaces(v1, v2, v3, clip_1); + numTris_2 = (vlr->v4) ? countClippedFaces(v1, v3, v4, clip_2) : 0; if (numTris_1 == 0 && numTris_2 == 0) continue; @@ -320,7 +343,7 @@ void BlenderFileLoader::insertShapeNode(ObjectRen *obr, int id) float triCoords[5][3]; if (numTris_1 > 0) { - clipTriangle(numTris_1, triCoords, vlr->v1, vlr->v2, vlr->v3, clip_1); + clipTriangle(numTris_1, triCoords, v1, v2, v3, clip_1); for (i = 0; i < numTris_1; i++) { addTriangle(&ls, triCoords[0], triCoords[i+1], triCoords[i+2]); _numFacesRead++; @@ -328,7 +351,7 @@ void BlenderFileLoader::insertShapeNode(ObjectRen *obr, int id) } if (numTris_2 > 0) { - clipTriangle(numTris_2, triCoords, vlr->v1, vlr->v3, vlr->v4, clip_2); + clipTriangle(numTris_2, triCoords, v1, v3, v4, clip_2); for (i = 0; i < numTris_2; i++) { addTriangle(&ls, triCoords[0], triCoords[i+1], triCoords[i+2]); _numFacesRead++; diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h index 59fa5923b36..038f4bdd6c8 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h +++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h @@ -62,11 +62,11 @@ public: inline real minEdgeSize() {return _minEdgeSize;} protected: - void insertShapeNode(ObjectRen *obr, int id); - int countClippedFaces(VertRen *v1, VertRen *v2, VertRen *v3, int clipped[3]); - void clipLine(VertRen *v1, VertRen *v2, float c[3], float z); - void clipTriangle(int numTris, float triCoords[][3], VertRen *v1, VertRen *v2, VertRen *v3, int clip[3]); - void addTriangle(struct LoaderState *state, float v1[3], float v2[3], float v3[3]); + void insertShapeNode(ObjectInstanceRen *obi, int id); + int countClippedFaces(float v1[3], float v2[3], float v3[3], int clip[3]); + void clipLine(float v1[3], float v2[3], float c[3], float z); + void clipTriangle(int numTris, float triCoords[][3], float v1[3], float v2[3], float v3[3], int clip[3]); + void addTriangle(struct LoaderState *ls, float v1[3], float v2[3], float v3[3]); protected: Render* _re; |