Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/freestyle/intern/blender_interface')
-rw-r--r--source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp584
-rw-r--r--source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h122
-rw-r--r--source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp397
-rw-r--r--source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h65
-rw-r--r--source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h51
-rw-r--r--source/blender/freestyle/intern/blender_interface/BlenderTextureManager.cpp137
-rw-r--r--source/blender/freestyle/intern/blender_interface/BlenderTextureManager.h54
-rw-r--r--source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp1351
8 files changed, 1557 insertions, 1204 deletions
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
index 8f2c00bf0f7..ea20f8255b1 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
+++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
@@ -1,7 +1,38 @@
-#include "BlenderFileLoader.h"
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
+ * \ingroup freestyle
+ */
#include <assert.h>
+#include "BlenderFileLoader.h"
+
BlenderFileLoader::BlenderFileLoader(Render *re, SceneRenderLayer* srl)
{
_re = re;
@@ -26,20 +57,20 @@ NodeGroup* BlenderFileLoader::Load()
// creation of the scene root node
_Scene = new NodeGroup;
- _viewplane_left= _re->viewplane.xmin;
- _viewplane_right= _re->viewplane.xmax;
- _viewplane_bottom= _re->viewplane.ymin;
- _viewplane_top= _re->viewplane.ymax;
- _z_near= -_re->clipsta;
- _z_far= -_re->clipend;
+ _viewplane_left = _re->viewplane.xmin;
+ _viewplane_right = _re->viewplane.xmax;
+ _viewplane_bottom = _re->viewplane.ymin;
+ _viewplane_top = _re->viewplane.ymax;
+ _z_near = -_re->clipsta;
+ _z_far = -_re->clipend;
#if 0
cout << "Frustum: l " << _viewplane_left << " r " << _viewplane_right
- << " b " << _viewplane_bottom << " t " << _viewplane_top
- << " n " << _z_near << " f " << _z_far << endl;
+ << " b " << _viewplane_bottom << " t " << _viewplane_top
+ << " n " << _z_near << " f " << _z_far << endl;
#endif
int id = 0;
- for(obi= (ObjectInstanceRen *) _re->instancetable.first; obi; obi=obi->next) {
+ for (obi = (ObjectInstanceRen *)_re->instancetable.first; obi; obi = obi->next) {
if (_pRenderMonitor && _pRenderMonitor->testBreak())
break;
if (!(obi->lay & _srl->lay))
@@ -48,13 +79,13 @@ NodeGroup* BlenderFileLoader::Load()
//cout << name[0] << name[1] << ":" << (name+2) <<;
//print_m4("obi->mat", obi->mat);
- if( obi->obr->totvlak > 0)
+ if (obi->obr->totvlak > 0)
insertShapeNode(obi, ++id);
else
cout << "Warning: " << (name+2) << " is not a vlak-based object (ignored)" << endl;
}
- //Returns the built scene.
+ // Return the built scene.
return _Scene;
}
@@ -77,13 +108,15 @@ int BlenderFileLoader::countClippedFaces(float v1[3], float v2[3], float v3[3],
if (v[i][2] > _z_near) {
clip[i] = CLIPPED_BY_NEAR;
numClipped++;
- } else if (v[i][2] < _z_far) {
+ }
+ else if (v[i][2] < _z_far) {
clip[i] = CLIPPED_BY_FAR;
numClipped++;
- } else {
+ }
+ else {
clip[i] = NOT_CLIPPED;
}
-// printf("%d %s\n", i, (clip[i] == NOT_CLIPPED) ? "not" : (clip[i] == CLIPPED_BY_NEAR) ? "near" : "far");
+ //printf("%d %s\n", i, (clip[i] == NOT_CLIPPED) ? "not" : (clip[i] == CLIPPED_BY_NEAR) ? "near" : "far");
sum += clip[i];
}
switch (numClipped) {
@@ -120,7 +153,8 @@ void BlenderFileLoader::clipLine(float v1[3], float v2[3], float c[3], float z)
if (v1[2] < v2[2]) {
p = v1;
q = v2;
- } else {
+ }
+ else {
p = v2;
q = v1;
}
@@ -137,8 +171,8 @@ void BlenderFileLoader::clipLine(float v1[3], float v2[3], float c[3], float z)
// obtain a set of vertices after the clipping. The number of vertices
// is at most 5.
void BlenderFileLoader::clipTriangle(int numTris, float triCoords[][3], float v1[3], float v2[3], float v3[3],
- float triNormals[][3], float n1[3], float n2[3], float n3[3],
- bool edgeMarks[], bool em1, bool em2, bool em3, int clip[3])
+ float triNormals[][3], float n1[3], float n2[3], float n3[3],
+ bool edgeMarks[], bool em1, bool em2, bool em3, int clip[3])
{
float *v[3], *n[3];
bool em[3];
@@ -164,13 +198,15 @@ void BlenderFileLoader::clipTriangle(int numTris, float triCoords[][3], float v1
edgeMarks[k] = false;
k++;
}
- } else if (clip[i] != clip[j]) {
+ }
+ else if (clip[i] != clip[j]) {
if (clip[j] == NOT_CLIPPED) {
clipLine(v[i], v[j], triCoords[k], (clip[i] == CLIPPED_BY_NEAR) ? _z_near : _z_far);
copy_v3_v3(triNormals[k], n[i]);
edgeMarks[k] = em[i];
k++;
- } else {
+ }
+ else {
clipLine(v[i], v[j], triCoords[k], (clip[i] == CLIPPED_BY_NEAR) ? _z_near : _z_far);
copy_v3_v3(triNormals[k], n[i]);
edgeMarks[k] = em[i];
@@ -182,15 +218,15 @@ void BlenderFileLoader::clipTriangle(int numTris, float triCoords[][3], float v1
}
}
}
- assert (k == 2 + numTris);
+ assert(k == 2 + numTris);
}
void BlenderFileLoader::addTriangle(struct LoaderState *ls, float v1[3], float v2[3], float v3[3],
- float n1[3], float n2[3], float n3[3],
- bool fm, bool em1, bool em2, bool em3)
+ float n1[3], float n2[3], float n3[3],
+ bool fm, bool em1, bool em2, bool em3)
{
float *fv[3], *fn[3], len;
- unsigned i, j;
+ unsigned int i, j;
IndexedFaceSet::FaceEdgeMark marks = 0;
// initialize the bounding box by the first vertex
@@ -208,24 +244,23 @@ void BlenderFileLoader::addTriangle(struct LoaderState *ls, float v1[3], float v
copy_v3_v3(ls->pn, fn[i]);
// update the bounding box
- for (j = 0; j < 3; j++)
- {
- if (ls->minBBox[j] > ls->pv[j])
- ls->minBBox[j] = ls->pv[j];
+ for (j = 0; j < 3; j++) {
+ if (ls->minBBox[j] > ls->pv[j])
+ ls->minBBox[j] = ls->pv[j];
- if (ls->maxBBox[j] < ls->pv[j])
- ls->maxBBox[j] = ls->pv[j];
+ if (ls->maxBBox[j] < ls->pv[j])
+ ls->maxBBox[j] = ls->pv[j];
}
len = len_v3v3(fv[i], fv[(i + 1) % 3]);
if (_minEdgeSize > len)
- _minEdgeSize = len;
-
+ _minEdgeSize = len;
+
*ls->pvi = ls->currentIndex;
*ls->pni = ls->currentIndex;
*ls->pmi = ls->currentMIndex;
- ls->currentIndex +=3;
+ ls->currentIndex += 3;
ls->pv += 3;
ls->pn += 3;
@@ -233,11 +268,16 @@ void BlenderFileLoader::addTriangle(struct LoaderState *ls, float v1[3], float v
ls->pni++;
ls->pmi++;
}
- if (fm) marks |= IndexedFaceSet::FACE_MARK;
- if (em1) marks |= IndexedFaceSet::EDGE_MARK_V1V2;
- if (em2) marks |= IndexedFaceSet::EDGE_MARK_V2V3;
- if (em3) marks |= IndexedFaceSet::EDGE_MARK_V3V1;
- *ls->pm++ = marks;
+
+ if (fm)
+ marks |= IndexedFaceSet::FACE_MARK;
+ if (em1)
+ marks |= IndexedFaceSet::EDGE_MARK_V1V2;
+ if (em2)
+ marks |= IndexedFaceSet::EDGE_MARK_V2V3;
+ if (em3)
+ marks |= IndexedFaceSet::EDGE_MARK_V3V1;
+ *(ls->pm++) = marks;
}
// With A, B and P indicating the three vertices of a given triangle, returns:
@@ -246,20 +286,32 @@ void BlenderFileLoader::addTriangle(struct LoaderState *ls, float v1[3], float v
// zero otherwise.
int BlenderFileLoader::testDegenerateTriangle(float v1[3], float v2[3], float v3[3])
{
- //float area = area_tri_v3(v1, v2, v3);
- //bool verbose = (area < 1e-6);
+#if 0
+ float area = area_tri_v3(v1, v2, v3);
+ bool verbose = (area < 1.0e-6);
+#endif
if (equals_v3v3(v1, v2) || equals_v3v3(v2, v3) || equals_v3v3(v1, v3)) {
- //if (verbose) printf("BlenderFileLoader::testDegenerateTriangle = 1\n");
+#if 0
+ if (verbose)
+ printf("BlenderFileLoader::testDegenerateTriangle = 1\n");
+#endif
return 1;
}
- if (dist_to_line_segment_v3(v1, v2, v3) < 1e-6 ||
- dist_to_line_segment_v3(v2, v1, v3) < 1e-6 ||
- dist_to_line_segment_v3(v3, v1, v2) < 1e-6) {
- //if (verbose) printf("BlenderFileLoader::testDegenerateTriangle = 2\n");
+ if (dist_to_line_segment_v3(v1, v2, v3) < 1.0e-6 ||
+ dist_to_line_segment_v3(v2, v1, v3) < 1.0e-6 ||
+ dist_to_line_segment_v3(v3, v1, v2) < 1.0e-6)
+ {
+#if 0
+ if (verbose)
+ printf("BlenderFileLoader::testDegenerateTriangle = 2\n");
+#endif
return 2;
}
- //if (verbose) printf("BlenderFileLoader::testDegenerateTriangle = 0\n");
+#if 0
+ if (verbose)
+ printf("BlenderFileLoader::testDegenerateTriangle = 0\n");
+#endif
return 0;
}
@@ -280,7 +332,7 @@ bool BlenderFileLoader::testEdgeRotation(float v1[3], float v2[3], float v3[3],
void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
{
ObjectRen *obr = obi->obr;
- char *name = obi->ob->id.name+2;
+ char *name = obi->ob->id.name + 2;
// 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
@@ -291,9 +343,11 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
float n1[3], n2[3], n3[3], n4[3], facenormal[3];
int clip_1[3], clip_2[3];
int wire_material = 0;
- for(int a=0; a < obr->totvlak; a++) {
- if((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak;
- else vlr++;
+ for (int a = 0; a < obr->totvlak; a++) {
+ if ((a & 255) == 0)
+ vlr = obr->vlaknodes[a>>8].vlak;
+ else
+ vlr++;
if (vlr->mat->material_type == MA_TYPE_WIRE) {
wire_material = 1;
continue;
@@ -301,58 +355,64 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
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 (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);
+ 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);
+#if 0
+ print_v3("v1", v1);
+ print_v3("v2", v2);
+ print_v3("v3", v3);
+ if (vlr->v4)
+ print_v3("v4", v4);
+#endif
if (!vlr->v4 || !testEdgeRotation(v1, v2, v3, v4)) {
numFaces += countClippedFaces(v1, v2, v3, clip_1);
if (vlr->v4)
numFaces += countClippedFaces(v1, v3, v4, clip_2);
- } else {
+ }
+ else {
numFaces += countClippedFaces(v1, v2, v4, clip_1);
numFaces += countClippedFaces(v2, v3, v4, clip_2);
}
}
if (wire_material)
printf("Warning: Object %s has wire materials (ignored)\n", name);
-// cout <<"numFaces " <<numFaces<<endl;
+// cout << "numFaces " << numFaces << endl;
if (numFaces == 0)
return;
// We allocate memory for the meshes to be imported
NodeTransform *currentMesh = new NodeTransform;
- NodeShape * shape = new NodeShape;
+ NodeShape *shape = new NodeShape;
- unsigned vSize = 3*3*numFaces;
+ unsigned vSize = 3 * 3 * numFaces;
float *vertices = new float[vSize];
unsigned nSize = vSize;
float *normals = new float[nSize];
unsigned *numVertexPerFaces = new unsigned[numFaces];
vector<FrsMaterial> meshFrsMaterials;
-
+
IndexedFaceSet::TRIANGLES_STYLE *faceStyle = new IndexedFaceSet::TRIANGLES_STYLE[numFaces];
unsigned i;
for (i = 0; i <numFaces; i++) {
- faceStyle[i] = IndexedFaceSet::TRIANGLES;
- numVertexPerFaces[i] = 3;
+ faceStyle[i] = IndexedFaceSet::TRIANGLES;
+ numVertexPerFaces[i] = 3;
}
IndexedFaceSet::FaceEdgeMark *faceEdgeMarks = new IndexedFaceSet::FaceEdgeMark[numFaces];
-
- unsigned viSize = 3*numFaces;
+
+ unsigned viSize = 3 * numFaces;
unsigned *VIndices = new unsigned[viSize];
unsigned niSize = viSize;
unsigned *NIndices = new unsigned[niSize];
unsigned *MIndices = new unsigned[viSize]; // Material Indices
-
+
struct LoaderState ls;
ls.pv = vertices;
ls.pn = normals;
@@ -362,185 +422,190 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
ls.pmi = MIndices;
ls.currentIndex = 0;
ls.currentMIndex = 0;
-
+
FrsMaterial tmpMat;
// We parse the vlak nodes again and import meshes while applying the clipping
// by the near and far view planes.
int p;
- for(p=0; p < obr->totvlak; ++p) // we parse the faces of the mesh
- {
- // Lib3dsFace *f=&mesh->faceL[p];
- // 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);
+ for (p = 0; p < obr->totvlak; ++p) { // we parse the faces of the mesh
+#if 0
+ Lib3dsFace *f = &mesh->faceL[p];
+ Lib3dsMaterial *mat = NULL;
+#endif
+ 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);
+ }
+ if (_smooth && (vlr->flag & R_SMOOTH)) {
+ copy_v3_v3(n1, vlr->v1->n);
+ copy_v3_v3(n2, vlr->v2->n);
+ copy_v3_v3(n3, vlr->v3->n);
+ if (vlr->v4)
+ copy_v3_v3(n4, vlr->v4->n);
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);
- }
- if (_smooth && (vlr->flag & R_SMOOTH)) {
- copy_v3_v3(n1, vlr->v1->n);
- copy_v3_v3(n2, vlr->v2->n);
- copy_v3_v3(n3, vlr->v3->n);
- if (vlr->v4) copy_v3_v3(n4, vlr->v4->n);
- if (obi->flag & R_TRANSFORMED) {
- mul_m3_v3(obi->nmat, n1);
- mul_m3_v3(obi->nmat, n2);
- mul_m3_v3(obi->nmat, n3);
- normalize_v3(n1);
- normalize_v3(n2);
- normalize_v3(n3);
- if (vlr->v4) {
- mul_m3_v3(obi->nmat, n4);
- normalize_v3(n4);
- }
+ mul_m3_v3(obi->nmat, n1);
+ mul_m3_v3(obi->nmat, n2);
+ mul_m3_v3(obi->nmat, n3);
+ normalize_v3(n1);
+ normalize_v3(n2);
+ normalize_v3(n3);
+ if (vlr->v4) {
+ mul_m3_v3(obi->nmat, n4);
+ normalize_v3(n4);
}
- } else {
- RE_vlakren_get_normal(_re, obi, vlr, facenormal);
- copy_v3_v3(n1, facenormal);
- copy_v3_v3(n2, facenormal);
- copy_v3_v3(n3, facenormal);
- if (vlr->v4) copy_v3_v3(n4, facenormal);
}
+ }
+ else {
+ RE_vlakren_get_normal(_re, obi, vlr, facenormal);
+ copy_v3_v3(n1, facenormal);
+ copy_v3_v3(n2, facenormal);
+ copy_v3_v3(n3, facenormal);
+ if (vlr->v4)
+ copy_v3_v3(n4, facenormal);
+ }
- unsigned numTris_1, numTris_2;
- bool edge_rotation;
- if (!vlr->v4 || !testEdgeRotation(v1, v2, v3, v4)) {
- numTris_1 = countClippedFaces(v1, v2, v3, clip_1);
- numTris_2 = (!vlr->v4) ? 0 : countClippedFaces(v1, v3, v4, clip_2);
- edge_rotation = false;
- } else {
- numTris_1 = countClippedFaces(v1, v2, v4, clip_1);
- numTris_2 = countClippedFaces(v2, v3, v4, clip_2);
- edge_rotation = true;
- printf("BlenderFileLoader::insertShapeNode: edge rotation is performed.\n");
- }
- if (numTris_1 == 0 && numTris_2 == 0)
- continue;
- bool fm, em1, em2, em3, em4;
- fm = (vlr->flag & ME_FREESTYLE_FACE) != 0;
- em1= (vlr->freestyle_edge_mark & R_EDGE_V1V2) != 0;
- em2= (vlr->freestyle_edge_mark & R_EDGE_V2V3) != 0;
- if (!vlr->v4) {
- em3= (vlr->freestyle_edge_mark & R_EDGE_V3V1) != 0;
- em4= false;
- } else {
- em3= (vlr->freestyle_edge_mark & R_EDGE_V3V4) != 0;
- em4= (vlr->freestyle_edge_mark & R_EDGE_V4V1) != 0;
- }
+ unsigned int numTris_1, numTris_2;
+ bool edge_rotation;
+ if (!vlr->v4 || !testEdgeRotation(v1, v2, v3, v4)) {
+ numTris_1 = countClippedFaces(v1, v2, v3, clip_1);
+ numTris_2 = (!vlr->v4) ? 0 : countClippedFaces(v1, v3, v4, clip_2);
+ edge_rotation = false;
+ }
+ else {
+ numTris_1 = countClippedFaces(v1, v2, v4, clip_1);
+ numTris_2 = countClippedFaces(v2, v3, v4, clip_2);
+ edge_rotation = true;
+ printf("BlenderFileLoader::insertShapeNode: edge rotation is performed.\n");
+ }
+ if (numTris_1 == 0 && numTris_2 == 0)
+ continue;
+ bool fm, em1, em2, em3, em4;
+ fm = (vlr->flag & ME_FREESTYLE_FACE) != 0;
+ em1 = (vlr->freestyle_edge_mark & R_EDGE_V1V2) != 0;
+ em2 = (vlr->freestyle_edge_mark & R_EDGE_V2V3) != 0;
+ if (!vlr->v4) {
+ em3 = (vlr->freestyle_edge_mark & R_EDGE_V3V1) != 0;
+ em4 = false;
+ }
+ else {
+ em3 = (vlr->freestyle_edge_mark & R_EDGE_V3V4) != 0;
+ em4 = (vlr->freestyle_edge_mark & R_EDGE_V4V1) != 0;
+ }
+
+ Material *mat = vlr->mat;
+ if (mat) {
+ tmpMat.setDiffuse(mat->r, mat->g, mat->b, mat->alpha);
+ tmpMat.setSpecular(mat->specr, mat->specg, mat->specb, mat->spectra);
+ float s = 1.0 * (mat->har + 1) / 4 ; // in Blender: [1;511] => in OpenGL: [0;128]
+ if (s > 128.f)
+ s = 128.f;
+ tmpMat.setShininess(s);
+ }
- Material *mat = vlr->mat;
-
- if (mat)
+ if (meshFrsMaterials.empty()) {
+ meshFrsMaterials.push_back(tmpMat);
+ shape->setFrsMaterial(tmpMat);
+ }
+ else {
+ // find if the material is aleady in the list
+ unsigned int i = 0;
+ bool found = false;
+
+ for (vector<FrsMaterial>::iterator it = meshFrsMaterials.begin(), itend = meshFrsMaterials.end();
+ it != itend;
+ it++, i++)
{
- tmpMat.setDiffuse( mat->r, mat->g, mat->b, mat->alpha );
- tmpMat.setSpecular( mat->specr, mat->specg, mat->specb, mat->spectra);
- float s = 1.0 * (mat->har + 1) / 4 ; // in Blender: [1;511] => in OpenGL: [0;128]
- if(s > 128.f)
- s = 128.f;
- tmpMat.setShininess(s);
+ if (*it == tmpMat) {
+ ls.currentMIndex = i;
+ found = true;
+ break;
+ }
}
-
- if(meshFrsMaterials.empty())
- {
+
+ if (!found) {
meshFrsMaterials.push_back(tmpMat);
- shape->setFrsMaterial(tmpMat);
- } else {
- // find if the material is aleady in the list
- unsigned i=0;
- bool found = false;
-
- for(vector<FrsMaterial>::iterator it=meshFrsMaterials.begin(), itend=meshFrsMaterials.end();
- it!=itend;
- ++it){
- if(*it == tmpMat){
- ls.currentMIndex = i;
- found = true;
- break;
- }
- ++i;
- }
-
- if(!found){
- meshFrsMaterials.push_back(tmpMat);
- ls.currentMIndex = meshFrsMaterials.size()-1;
- }
- }
-
- float triCoords[5][3], triNormals[5][3];
- bool edgeMarks[5]; // edgeMarks[i] is for the edge between i-th and (i+1)-th vertices
-
- if (numTris_1 > 0) {
- if (!edge_rotation)
- clipTriangle(numTris_1, triCoords, v1, v2, v3, triNormals, n1, n2, n3,
- edgeMarks, em1, em2, (!vlr->v4) ? em3 : false, clip_1);
- else
- clipTriangle(numTris_1, triCoords, v1, v2, v4, triNormals, n1, n2, n4,
- edgeMarks, em1, false, em4, clip_1);
- for (i = 0; i < numTris_1; i++) {
- addTriangle(&ls, triCoords[0], triCoords[i+1], triCoords[i+2],
- triNormals[0], triNormals[i+1], triNormals[i+2],
- fm, (i == 0) ? edgeMarks[0] : false, edgeMarks[i+1],
- (i == numTris_1 - 1) ? edgeMarks[i+2] : false);
- _numFacesRead++;
- }
+ ls.currentMIndex = meshFrsMaterials.size() - 1;
}
+ }
- if (numTris_2 > 0) {
- if (!edge_rotation)
- clipTriangle(numTris_2, triCoords, v1, v3, v4, triNormals, n1, n3, n4,
- edgeMarks, false, em3, em4, clip_2);
- else
- clipTriangle(numTris_2, triCoords, v2, v3, v4, triNormals, n2, n3, n4,
- edgeMarks, em2, em3, false, clip_2);
- for (i = 0; i < numTris_2; i++) {
- addTriangle(&ls, triCoords[0], triCoords[i+1], triCoords[i+2],
- triNormals[0], triNormals[i+1], triNormals[i+2],
- fm, (i == 0) ? edgeMarks[0] : false, edgeMarks[i+1],
- (i == numTris_2 - 1) ? edgeMarks[i+2] : false);
- _numFacesRead++;
- }
+ float triCoords[5][3], triNormals[5][3];
+ bool edgeMarks[5]; // edgeMarks[i] is for the edge between i-th and (i+1)-th vertices
+
+ if (numTris_1 > 0) {
+ if (!edge_rotation) {
+ clipTriangle(numTris_1, triCoords, v1, v2, v3, triNormals, n1, n2, n3,
+ edgeMarks, em1, em2, (!vlr->v4) ? em3 : false, clip_1);
+ }
+ else {
+ clipTriangle(numTris_1, triCoords, v1, v2, v4, triNormals, n1, n2, n4,
+ edgeMarks, em1, false, em4, clip_1);
+ }
+ for (i = 0; i < numTris_1; i++) {
+ addTriangle(&ls, triCoords[0], triCoords[i+1], triCoords[i+2],
+ triNormals[0], triNormals[i+1], triNormals[i+2],
+ fm, (i == 0) ? edgeMarks[0] : false, edgeMarks[i+1],
+ (i == numTris_1 - 1) ? edgeMarks[i+2] : false);
+ _numFacesRead++;
}
+ }
+
+ if (numTris_2 > 0) {
+ if (!edge_rotation) {
+ clipTriangle(numTris_2, triCoords, v1, v3, v4, triNormals, n1, n3, n4,
+ edgeMarks, false, em3, em4, clip_2);
+ }
+ else {
+ clipTriangle(numTris_2, triCoords, v2, v3, v4, triNormals, n2, n3, n4,
+ edgeMarks, em2, em3, false, clip_2);
+ }
+ for (i = 0; i < numTris_2; i++) {
+ addTriangle(&ls, triCoords[0], triCoords[i+1], triCoords[i+2],
+ triNormals[0], triNormals[i+1], triNormals[i+2],
+ fm, (i == 0) ? edgeMarks[0] : false, edgeMarks[i+1],
+ (i == numTris_2 - 1) ? edgeMarks[i+2] : false);
+ _numFacesRead++;
+ }
+ }
}
-
+
// We might have several times the same vertex. We want a clean
- // shape with no real-vertex. Here, we are making a cleaning
- // pass.
+ // shape with no real-vertex. Here, we are making a cleaning pass.
real *cleanVertices = NULL;
- unsigned cvSize;
- unsigned *cleanVIndices = NULL;
-
- GeomCleaner::CleanIndexedVertexArray(
- vertices, vSize,
- VIndices, viSize,
- &cleanVertices, &cvSize,
- &cleanVIndices);
-
+ unsigned int cvSize;
+ unsigned int *cleanVIndices = NULL;
+
+ GeomCleaner::CleanIndexedVertexArray(vertices, vSize, VIndices, viSize, &cleanVertices, &cvSize, &cleanVIndices);
+
real *cleanNormals = NULL;
- unsigned cnSize;
- unsigned *cleanNIndices = NULL;
-
- GeomCleaner::CleanIndexedVertexArray(
- normals, nSize,
- NIndices, niSize,
- &cleanNormals, &cnSize,
- &cleanNIndices);
-
+ unsigned int cnSize;
+ unsigned int *cleanNIndices = NULL;
+
+ GeomCleaner::CleanIndexedVertexArray(normals, nSize, NIndices, niSize, &cleanNormals, &cnSize, &cleanNIndices);
+
// format materials array
FrsMaterial** marray = new FrsMaterial*[meshFrsMaterials.size()];
- unsigned mindex=0;
- for(vector<FrsMaterial>::iterator m=meshFrsMaterials.begin(), mend=meshFrsMaterials.end();
- m!=mend;
- ++m){
- marray[mindex] = new FrsMaterial(*m);
- ++mindex;
+ unsigned int mindex = 0;
+ for (vector<FrsMaterial>::iterator m = meshFrsMaterials.begin(), mend = meshFrsMaterials.end();
+ m!=mend;
+ ++m)
+ {
+ marray[mindex] = new FrsMaterial(*m);
+ ++mindex;
}
+
// deallocates memory:
delete [] vertices;
delete [] normals;
@@ -568,21 +633,28 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
if (v0 == v1 || v0 == v2 || v1 == v2) {
continue; // do nothing for now
}
- else if (GeomUtils::distPointSegment<Vec3r>(v0, v1, v2) < 1e-6) {
- detri.viP = vi0; detri.viA = vi1; detri.viB = vi2;
+ else if (GeomUtils::distPointSegment<Vec3r>(v0, v1, v2) < 1.0e-6) {
+ detri.viP = vi0;
+ detri.viA = vi1;
+ detri.viB = vi2;
}
- else if (GeomUtils::distPointSegment<Vec3r>(v1, v0, v2) < 1e-6) {
- detri.viP = vi1; detri.viA = vi0; detri.viB = vi2;
+ else if (GeomUtils::distPointSegment<Vec3r>(v1, v0, v2) < 1.0e-6) {
+ detri.viP = vi1;
+ detri.viA = vi0;
+ detri.viB = vi2;
}
- else if (GeomUtils::distPointSegment<Vec3r>(v2, v0, v1) < 1e-6) {
- detri.viP = vi2; detri.viA = vi0; detri.viB = vi1;
+ else if (GeomUtils::distPointSegment<Vec3r>(v2, v0, v1) < 1.0e-6) {
+ detri.viP = vi2;
+ detri.viA = vi0;
+ detri.viB = vi1;
}
else {
continue;
}
+
detri.v = zero;
detri.n = 0;
- for (unsigned j = 0; j < viSize; j += 3) {
+ for (unsigned int j = 0; j < viSize; j += 3) {
if (i == j)
continue;
vi0 = cleanVIndices[j];
@@ -594,19 +666,24 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
if (detri.viP == vi0 && (detri.viA == vi1 || detri.viB == vi1)) {
detri.v += (v2 - v0);
detri.n++;
- } else if (detri.viP == vi0 && (detri.viA == vi2 || detri.viB == vi2)) {
+ }
+ else if (detri.viP == vi0 && (detri.viA == vi2 || detri.viB == vi2)) {
detri.v += (v1 - v0);
detri.n++;
- } else if (detri.viP == vi1 && (detri.viA == vi0 || detri.viB == vi0)) {
+ }
+ else if (detri.viP == vi1 && (detri.viA == vi0 || detri.viB == vi0)) {
detri.v += (v2 - v1);
detri.n++;
- } else if (detri.viP == vi1 && (detri.viA == vi2 || detri.viB == vi2)) {
+ }
+ else if (detri.viP == vi1 && (detri.viA == vi2 || detri.viB == vi2)) {
detri.v += (v0 - v1);
detri.n++;
- } else if (detri.viP == vi2 && (detri.viA == vi0 || detri.viB == vi0)) {
+ }
+ else if (detri.viP == vi2 && (detri.viA == vi0 || detri.viB == vi0)) {
detri.v += (v1 - v2);
detri.n++;
- } else if (detri.viP == vi2 && (detri.viA == vi1 || detri.viB == vi1)) {
+ }
+ else if (detri.viP == vi2 && (detri.viA == vi1 || detri.viB == vi1)) {
detri.v += (v0 - v2);
detri.n++;
}
@@ -616,6 +693,7 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
}
detriList.push_back(detri);
}
+
if (detriList.size() > 0) {
vector<detri_t>::iterator v;
for (v = detriList.begin(); v != detriList.end(); v++) {
@@ -624,43 +702,35 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
cleanVertices[detri.viP] = cleanVertices[detri.viA];
cleanVertices[detri.viP+1] = cleanVertices[detri.viA+1];
cleanVertices[detri.viP+2] = cleanVertices[detri.viA+2];
- } else if (detri.v.norm() > 0.0) {
- cleanVertices[detri.viP] += 1e-5 * detri.v.x();
- cleanVertices[detri.viP+1] += 1e-5 * detri.v.y();
- cleanVertices[detri.viP+2] += 1e-5 * detri.v.z();
+ }
+ else if (detri.v.norm() > 0.0) {
+ cleanVertices[detri.viP] += 1.0e-5 * detri.v.x();
+ cleanVertices[detri.viP+1] += 1.0e-5 * detri.v.y();
+ cleanVertices[detri.viP+2] += 1.0e-5 * detri.v.z();
}
}
printf("Warning: Object %s contains %lu degenerated triangle%s (strokes may be incorrect)\n",
- name, detriList.size(), (detriList.size() > 1) ? "s" : "");
+ name, detriList.size(), (detriList.size() > 1) ? "s" : "");
}
// Create the IndexedFaceSet with the retrieved attributes
IndexedFaceSet *rep;
- rep = new IndexedFaceSet(cleanVertices, cvSize,
- cleanNormals, cnSize,
- marray, meshFrsMaterials.size(),
- 0, 0,
- numFaces, numVertexPerFaces, faceStyle,
- faceEdgeMarks,
- cleanVIndices, viSize,
- cleanNIndices, niSize,
- MIndices, viSize,
- 0,0,
- 0);
+ rep = new IndexedFaceSet(cleanVertices, cvSize, cleanNormals, cnSize, marray, meshFrsMaterials.size(), 0, 0,
+ numFaces, numVertexPerFaces, faceStyle, faceEdgeMarks, cleanVIndices, viSize,
+ cleanNIndices, niSize, MIndices, viSize, 0, 0, 0);
// sets the id of the rep
rep->setId(Id(id, 0));
- rep->setName(obi->ob->id.name+2);
-
- const BBox<Vec3r> bbox = BBox<Vec3r>(Vec3r(ls.minBBox[0], ls.minBBox[1], ls.minBBox[2]),
+ rep->setName(obi->ob->id.name + 2);
+
+ const BBox<Vec3r> bbox = BBox<Vec3r>(Vec3r(ls.minBBox[0], ls.minBBox[1], ls.minBBox[2]),
Vec3r(ls.maxBBox[0], ls.maxBBox[1], ls.maxBBox[2]));
rep->setBBox(bbox);
shape->AddRep(rep);
-
+
Matrix44r meshMat = Matrix44r::identity();
currentMesh->setMatrix(meshMat);
- currentMesh->Translate(0,0,0);
-
+ currentMesh->Translate(0, 0, 0);
+
currentMesh->AddChild(shape);
_Scene->AddChild(currentMesh);
-
}
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h
index c5c06567c41..316cf93a617 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h
+++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h
@@ -1,34 +1,68 @@
-#ifndef BLENDER_FILE_LOADER_H
-# define BLENDER_FILE_LOADER_H
-
-# include <string.h>
-# include <float.h>
-
-# include "../system/FreestyleConfig.h"
-# include "../system/RenderMonitor.h"
-# include "../scene_graph/NodeGroup.h"
-# include "../scene_graph/NodeTransform.h"
-# include "../scene_graph/NodeShape.h"
-# include "../scene_graph/IndexedFaceSet.h"
-# include "../geometry/BBox.h"
-# include "../geometry/Geom.h"
-# include "../geometry/GeomCleaner.h"
-# include "../geometry/GeomUtils.h"
-
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BLENDER_FILE_LOADER_H__
+#define __BLENDER_FILE_LOADER_H__
+
+/** \file blender/freestyle/intern/blender_interface/BlenderFileLoader.h
+ * \ingroup freestyle
+ */
+
+#include <string.h>
+#include <float.h>
+
+#include "../geometry/BBox.h"
+#include "../geometry/Geom.h"
+#include "../geometry/GeomCleaner.h"
+#include "../geometry/GeomUtils.h"
+#include "../scene_graph/IndexedFaceSet.h"
+#include "../scene_graph/NodeGroup.h"
+#include "../scene_graph/NodeTransform.h"
+#include "../scene_graph/NodeShape.h"
+#include "../system/FreestyleConfig.h"
+#include "../system/RenderMonitor.h"
+
+// XXX Are those "ifdef __cplusplus" useful here?
#ifdef __cplusplus
extern "C" {
#endif
- #include "DNA_material_types.h"
- #include "DNA_meshdata_types.h"
- #include "DNA_scene_types.h"
- #include "render_types.h"
- #include "renderdatabase.h"
-
- #include "BKE_mesh.h"
- #include "BKE_scene.h"
- #include "BLI_math.h"
-
+#include "DNA_material_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_scene_types.h"
+
+#include "renderdatabase.h"
+#include "render_types.h"
+
+#include "BKE_mesh.h"
+#include "BKE_scene.h"
+
+#include "BLI_math.h"
+
#ifdef __cplusplus
}
#endif
@@ -52,21 +86,21 @@ struct LoaderState {
class LIB_SCENE_GRAPH_EXPORT BlenderFileLoader
{
public:
- /*! Builds a MaxFileLoader */
+ /*! Builds a MaxFileLoader */
BlenderFileLoader(Render *re, SceneRenderLayer* srl);
- virtual ~BlenderFileLoader();
+ virtual ~BlenderFileLoader();
- /*! Loads the 3D scene and returns a pointer to the scene root node */
- NodeGroup * Load();
+ /*! Loads the 3D scene and returns a pointer to the scene root node */
+ NodeGroup * Load();
- /*! Gets the number of read faces */
- inline unsigned int numFacesRead() {return _numFacesRead;}
+ /*! Gets the number of read faces */
+ inline unsigned int numFacesRead() {return _numFacesRead;}
- /*! Gets the smallest edge size read */
- inline real minEdgeSize() {return _minEdgeSize;}
+ /*! Gets the smallest edge size read */
+ inline real minEdgeSize() {return _minEdgeSize;}
- /*! Modifiers */
- inline void setRenderMonitor(RenderMonitor *iRenderMonitor) {_pRenderMonitor = iRenderMonitor;}
+ /*! Modifiers */
+ inline void setRenderMonitor(RenderMonitor *iRenderMonitor) {_pRenderMonitor = iRenderMonitor;}
protected:
void insertShapeNode(ObjectInstanceRen *obi, int id);
@@ -75,10 +109,10 @@ protected:
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],
- float triNormals[][3], float n1[3], float n2[3], float n3[3],
- bool edgeMarks[5], bool em1, bool em2, bool em3, int clip[3]);
+ float triNormals[][3], float n1[3], float n2[3], float n3[3],
+ bool edgeMarks[5], bool em1, bool em2, bool em3, int clip[3]);
void addTriangle(struct LoaderState *ls, float v1[3], float v2[3], float v3[3],
- float n1[3], float n2[3], float n3[3], bool fm, bool em1, bool em2, bool em3);
+ float n1[3], float n2[3], float n3[3], bool fm, bool em1, bool em2, bool em3);
protected:
struct detri_t {
@@ -86,9 +120,9 @@ protected:
Vec3r v;
unsigned n;
};
- Render* _re;
- SceneRenderLayer* _srl;
- NodeGroup* _Scene;
+ Render *_re;
+ SceneRenderLayer *_srl;
+ NodeGroup *_Scene;
unsigned _numFacesRead;
real _minEdgeSize;
bool _smooth; /* if true, face smoothness is taken into account */
@@ -101,4 +135,4 @@ protected:
RenderMonitor *_pRenderMonitor;
};
-#endif // BLENDER_FILE_LOADER_H
+#endif // __BLENDER_FILE_LOADER_H__
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
index 656d7a23659..e7f97405390 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
+++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
@@ -1,9 +1,41 @@
-# include "BlenderStrokeRenderer.h"
-# include "../stroke/Canvas.h"
-# include "../application/AppConfig.h"
-
-# include "BlenderTextureManager.h"
-
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
+ * \ingroup freestyle
+ */
+
+#include "BlenderStrokeRenderer.h"
+#include "BlenderTextureManager.h"
+
+#include "../application/AppConfig.h"
+#include "../stroke/Canvas.h"
+
+// XXX Are those "ifdef __cplusplus" useful here?
#ifdef __cplusplus
extern "C" {
#endif
@@ -13,16 +45,16 @@ extern "C" {
#include "DNA_camera_types.h"
#include "DNA_customdata_types.h"
#include "DNA_listBase.h"
-#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
+#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "DNA_screen_types.h"
#include "BKE_customdata.h"
#include "BKE_global.h"
#include "BKE_library.h" /* free_libblock */
-#include "BKE_material.h"
#include "BKE_main.h" /* struct Main */
+#include "BKE_material.h"
#include "BKE_mesh.h"
#include "BKE_object.h"
#include "BKE_scene.h"
@@ -33,79 +65,79 @@ extern "C" {
}
#endif
-
-BlenderStrokeRenderer::BlenderStrokeRenderer(Render* re, int render_count)
-:StrokeRenderer(){
-
+BlenderStrokeRenderer::BlenderStrokeRenderer(Render* re, int render_count) : StrokeRenderer()
+{
// TEMPORARY - need a texture manager
_textureManager = new BlenderTextureManager;
_textureManager->load();
- _width = re->winx; _height = re->winy; // for stroke mesh generation
+ // for stroke mesh generation
+ _width = re->winx;
+ _height = re->winy;
- // Scene.New("FreestyleStrokes")
+ //Scene.New("FreestyleStrokes")
old_scene = re->scene;
char name[22];
- snprintf(name, sizeof(name), "FRS%d_%s", render_count, re->scene->id.name+2);
+ BLI_snprintf(name, sizeof(name), "FRS%d_%s", render_count, re->scene->id.name + 2);
freestyle_scene = BKE_scene_add(name);
freestyle_scene->r.cfra = old_scene->r.cfra;
- freestyle_scene->r.mode= old_scene->r.mode &
- ~( R_EDGE_FRS | R_SHADOW | R_SSS | R_PANORAMA | R_ENVMAP | R_MBLUR | R_BORDER );
- freestyle_scene->r.xsch= re->rectx; // old_scene->r.xsch
- freestyle_scene->r.ysch= re->recty; // old_scene->r.ysch
- freestyle_scene->r.xasp= 1.f; // old_scene->r.xasp;
- freestyle_scene->r.yasp= 1.f; // old_scene->r.yasp;
- freestyle_scene->r.tilex= old_scene->r.tilex;
- freestyle_scene->r.tiley= old_scene->r.tiley;
- freestyle_scene->r.size= 100; // old_scene->r.size
- freestyle_scene->r.maximsize= old_scene->r.maximsize;
+ freestyle_scene->r.mode = old_scene->r.mode &
+ ~(R_EDGE_FRS | R_SHADOW | R_SSS | R_PANORAMA | R_ENVMAP | R_MBLUR | R_BORDER);
+ freestyle_scene->r.xsch = re->rectx; // old_scene->r.xsch
+ freestyle_scene->r.ysch = re->recty; // old_scene->r.ysch
+ freestyle_scene->r.xasp = 1.0f; // old_scene->r.xasp;
+ freestyle_scene->r.yasp = 1.0f; // old_scene->r.yasp;
+ freestyle_scene->r.tilex = old_scene->r.tilex;
+ freestyle_scene->r.tiley = old_scene->r.tiley;
+ freestyle_scene->r.size = 100; // old_scene->r.size
+ freestyle_scene->r.maximsize = old_scene->r.maximsize;
freestyle_scene->r.ocres = old_scene->r.ocres;
freestyle_scene->r.color_mgt_flag = 0; // old_scene->r.color_mgt_flag;
- freestyle_scene->r.scemode= old_scene->r.scemode & ~( R_SINGLE_LAYER );
- freestyle_scene->r.flag= old_scene->r.flag;
- freestyle_scene->r.threads= old_scene->r.threads;
- freestyle_scene->r.border.xmin= old_scene->r.border.xmin;
- freestyle_scene->r.border.ymin= old_scene->r.border.ymin;
- freestyle_scene->r.border.xmax= old_scene->r.border.xmax;
- freestyle_scene->r.border.ymax= old_scene->r.border.ymax;
+ freestyle_scene->r.scemode = old_scene->r.scemode & ~(R_SINGLE_LAYER);
+ freestyle_scene->r.flag = old_scene->r.flag;
+ freestyle_scene->r.threads = old_scene->r.threads;
+ freestyle_scene->r.border.xmin = old_scene->r.border.xmin;
+ freestyle_scene->r.border.ymin = old_scene->r.border.ymin;
+ freestyle_scene->r.border.xmax = old_scene->r.border.xmax;
+ freestyle_scene->r.border.ymax = old_scene->r.border.ymax;
strcpy(freestyle_scene->r.pic, old_scene->r.pic);
- freestyle_scene->r.safety.xmin= old_scene->r.safety.xmin;
- freestyle_scene->r.safety.ymin= old_scene->r.safety.ymin;
- freestyle_scene->r.safety.xmax= old_scene->r.safety.xmax;
- freestyle_scene->r.safety.ymax= old_scene->r.safety.ymax;
- freestyle_scene->r.osa= old_scene->r.osa;
- freestyle_scene->r.filtertype= old_scene->r.filtertype;
- freestyle_scene->r.gauss= old_scene->r.gauss;
- freestyle_scene->r.dither_intensity= old_scene->r.dither_intensity;
+ freestyle_scene->r.safety.xmin = old_scene->r.safety.xmin;
+ freestyle_scene->r.safety.ymin = old_scene->r.safety.ymin;
+ freestyle_scene->r.safety.xmax = old_scene->r.safety.xmax;
+ freestyle_scene->r.safety.ymax = old_scene->r.safety.ymax;
+ freestyle_scene->r.osa = old_scene->r.osa;
+ freestyle_scene->r.filtertype = old_scene->r.filtertype;
+ freestyle_scene->r.gauss = old_scene->r.gauss;
+ freestyle_scene->r.dither_intensity = old_scene->r.dither_intensity;
BLI_strncpy(freestyle_scene->r.engine, old_scene->r.engine, sizeof(freestyle_scene->r.engine));
freestyle_scene->r.im_format.planes = R_IMF_PLANES_RGBA;
freestyle_scene->r.im_format.imtype = R_IMF_IMTYPE_PNG;
BKE_scene_disable_color_management(freestyle_scene);
- BKE_scene_set_background( G.main, freestyle_scene );
+ BKE_scene_set_background(G.main, freestyle_scene);
// Camera
Object* object_camera = BKE_object_add(freestyle_scene, OB_CAMERA);
-
- Camera* camera = (Camera *) object_camera->data;
+
+ Camera* camera = (Camera *)object_camera->data;
camera->type = CAM_ORTHO;
camera->ortho_scale = max(re->rectx, re->recty);
- camera->clipsta = 0.1f;
- camera->clipend = 100.0f;
+ camera->clipsta = 0.1f;
+ camera->clipend = 100.0f;
- _z_delta = 0.00001f;
- _z = camera->clipsta + _z_delta;
+ _z_delta = 0.00001f;
+ _z = camera->clipsta + _z_delta;
- // test
- //_z = 999.90f; _z_delta = 0.01f;
+ // test
+ //_z = 999.90f; _z_delta = 0.01f;
object_camera->loc[0] = re->disprect.xmin + 0.5f * re->rectx;
object_camera->loc[1] = re->disprect.ymin + 0.5f * re->recty;
- object_camera->loc[2] = 1.f;
-
+ object_camera->loc[2] = 1.0f;
+
freestyle_scene->camera = object_camera;
-
+
// Material
material = BKE_material_add("stroke_material");
material->mode |= MA_VERTEXCOLP;
@@ -114,12 +146,11 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render* re, int render_count)
material->vcol_alpha = 1;
}
-BlenderStrokeRenderer::~BlenderStrokeRenderer(){
-
- if(0 != _textureManager)
- {
+BlenderStrokeRenderer::~BlenderStrokeRenderer()
+{
+ if (0 != _textureManager) {
delete _textureManager;
- _textureManager = 0;
+ _textureManager = NULL;
}
// The freestyle_scene object is not released here. Instead,
@@ -128,8 +159,7 @@ BlenderStrokeRenderer::~BlenderStrokeRenderer(){
// compositor has finished.
// release objects and data blocks
- Base *b = (Base *)freestyle_scene->base.first;
- while(b) {
+ for (Base *b = (Base*)freestyle_scene->base.first; b; b = b->next) {
Object *ob = b->object;
void *data = ob->data;
char name[24];
@@ -137,58 +167,58 @@ BlenderStrokeRenderer::~BlenderStrokeRenderer(){
//cout << "removing " << name[0] << name[1] << ":" << (name+2) << endl;
switch (ob->type) {
case OB_MESH:
- BKE_libblock_free( &G.main->object, ob );
- BKE_libblock_free( &G.main->mesh, data );
+ BKE_libblock_free(&G.main->object, ob);
+ BKE_libblock_free(&G.main->mesh, data);
break;
case OB_CAMERA:
- BKE_libblock_free( &G.main->object, ob );
- BKE_libblock_free( &G.main->camera, data );
+ BKE_libblock_free(&G.main->object, ob);
+ BKE_libblock_free(&G.main->camera, data);
freestyle_scene->camera = NULL;
break;
default:
cerr << "Warning: unexpected object in the scene: " << name[0] << name[1] << ":" << (name+2) << endl;
}
- b = b->next;
}
- BLI_freelistN( &freestyle_scene->base );
+ BLI_freelistN(&freestyle_scene->base);
// release material
- BKE_libblock_free( &G.main->mat, material );
-
- BKE_scene_set_background( G.main, old_scene );
+ BKE_libblock_free(&G.main->mat, material);
+
+ BKE_scene_set_background(G.main, old_scene);
}
-float BlenderStrokeRenderer::get_stroke_vertex_z(void) const {
- float z = _z;
- BlenderStrokeRenderer *self = const_cast<BlenderStrokeRenderer *>(this);
- if (!(_z < _z_delta * 100000.0f))
- self->_z_delta *= 10.0f;
- self->_z += _z_delta;
- return -z;
+float BlenderStrokeRenderer::get_stroke_vertex_z(void) const
+{
+ float z = _z;
+ BlenderStrokeRenderer *self = const_cast<BlenderStrokeRenderer *>(this);
+ if (!(_z < _z_delta * 100000.0f))
+ self->_z_delta *= 10.0f;
+ self->_z += _z_delta;
+ return -z;
}
-void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const{
- RenderStrokeRepBasic(iStrokeRep);
+void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const
+{
+ RenderStrokeRepBasic(iStrokeRep);
}
-void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const{
-
+void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const
+{
////////////////////
// Build up scene
////////////////////
-
- vector<Strip*>& strips = iStrokeRep->getStrips();
- Strip::vertex_container::iterator v[3];
- StrokeVertexRep *svRep[3];
- Vec3r color[3];
- unsigned int vertex_index, edge_index, loop_index;
- Vec2r p;
-
- for(vector<Strip*>::iterator s=strips.begin(), send=strips.end();
- s!=send;
- ++s){
-
- Strip::vertex_container& strip_vertices = (*s)->vertices();
+
+ vector<Strip*>& strips = iStrokeRep->getStrips();
+ Strip::vertex_container::iterator v[3];
+ StrokeVertexRep *svRep[3];
+ Vec3r color[3];
+ unsigned int vertex_index, edge_index, loop_index;
+ Vec2r p;
+
+ for (vector<Strip*>::iterator s = strips.begin(), send = strips.end();
+ s != send;
+ ++s){
+ Strip::vertex_container& strip_vertices = (*s)->vertices();
int strip_vertex_count = (*s)->sizeStrip();
int xl, xu, yl, yu, n, visible_faces, visible_segments;
bool visible;
@@ -197,108 +227,120 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const{
// (note: a strip segment is a series of visible faces, while two strip
// segments are separated by one or more invisible faces)
v[0] = strip_vertices.begin();
- v[1] = v[0]; ++(v[1]);
- v[2] = v[1]; ++(v[2]);
+ v[1] = v[0] + 1;
+ v[2] = v[0] + 2;
visible_faces = visible_segments = 0;
visible = false;
- for (n = 2; n < strip_vertex_count; n++)
- {
+ for (n = 2; n < strip_vertex_count; n++, v[0]++, v[1]++, v[2]++) {
svRep[0] = *(v[0]);
svRep[1] = *(v[1]);
svRep[2] = *(v[2]);
xl = xu = yl = yu = 0;
for (int j = 0; j < 3; j++) {
p = svRep[j]->point2d();
- if (p[0] < 0.0) xl++; else if (p[0] > _width) xu++;
- if (p[1] < 0.0) yl++; else if (p[1] > _height) yu++;
+ if (p[0] < 0.0)
+ xl++;
+ else if (p[0] > _width)
+ xu++;
+ if (p[1] < 0.0)
+ yl++;
+ else if (p[1] > _height)
+ yu++;
}
if (xl == 3 || xu == 3 || yl == 3 || yu == 3) {
visible = false;
- } else {
+ }
+ else {
visible_faces++;
if (!visible)
visible_segments++;
visible = true;
}
- ++v[0]; ++v[1]; ++v[2];
}
if (visible_faces == 0)
continue;
- // me = Mesh.New()
+ //me = Mesh.New()
#if 0
Object* object_mesh = BKE_object_add(freestyle_scene, OB_MESH);
#else
Object* object_mesh = NewMesh();
#endif
- Mesh* mesh = (Mesh *) object_mesh->data;
- // MEM_freeN(mesh->bb);
- // mesh->bb= NULL;
- // mesh->id.us = 0;
-
+ Mesh* mesh = (Mesh*)object_mesh->data;
+#if 0
+ MEM_freeN(mesh->bb);
+ mesh->bb = NULL;
+ mesh->id.us = 0;
+#endif
#if 1
- // me.materials = [mat]
- mesh->mat = ( Material ** ) MEM_mallocN( 1 * sizeof( Material * ), "MaterialList" );
+ //me.materials = [mat]
+ mesh->mat = (Material**)MEM_mallocN(1 * sizeof(Material*), "MaterialList");
mesh->mat[0] = material;
mesh->totcol = 1;
- test_object_materials( (ID*) mesh );
+ test_object_materials((ID*)mesh);
#else
- assign_material(object_mesh, material, object_mesh->totcol+1);
- object_mesh->actcol= object_mesh->totcol;
+ assign_material(object_mesh, material, object_mesh->totcol + 1);
+ object_mesh->actcol = object_mesh->totcol;
#endif
// vertices allocation
mesh->totvert = visible_faces + visible_segments * 2;
- mesh->mvert = (MVert*) CustomData_add_layer( &mesh->vdata, CD_MVERT, CD_CALLOC, NULL, mesh->totvert);
-
+ mesh->mvert = (MVert*)CustomData_add_layer(&mesh->vdata, CD_MVERT, CD_CALLOC, NULL, mesh->totvert);
+
// edges allocation
mesh->totedge = visible_faces * 2 + visible_segments;
- mesh->medge = (MEdge*) CustomData_add_layer( &mesh->edata, CD_MEDGE, CD_CALLOC, NULL, mesh->totedge);
+ mesh->medge = (MEdge*)CustomData_add_layer(&mesh->edata, CD_MEDGE, CD_CALLOC, NULL, mesh->totedge);
// faces allocation
mesh->totpoly = visible_faces;
- mesh->mpoly= (MPoly*) CustomData_add_layer( &mesh->pdata, CD_MPOLY, CD_CALLOC, NULL, mesh->totpoly);
+ mesh->mpoly = (MPoly*)CustomData_add_layer(&mesh->pdata, CD_MPOLY, CD_CALLOC, NULL, mesh->totpoly);
// loops allocation
mesh->totloop = visible_faces * 3;
- mesh->mloop= (MLoop*) CustomData_add_layer( &mesh->ldata, CD_MLOOP, CD_CALLOC, NULL, mesh->totloop);
-
+ mesh->mloop = (MLoop*)CustomData_add_layer(&mesh->ldata, CD_MLOOP, CD_CALLOC, NULL, mesh->totloop);
+
// colors allocation
- mesh->mloopcol = (MLoopCol *) CustomData_add_layer( &mesh->ldata, CD_MLOOPCOL, CD_CALLOC, NULL, mesh->totloop);
+ mesh->mloopcol = (MLoopCol*)CustomData_add_layer(&mesh->ldata, CD_MLOOPCOL, CD_CALLOC, NULL, mesh->totloop);
////////////////////
// Data copy
////////////////////
-
- MVert* vertices = mesh->mvert;
- MEdge* edges = mesh->medge;
- MPoly* polys = mesh->mpoly;
- MLoop* loops = mesh->mloop;
- MLoopCol* colors = mesh->mloopcol;
+
+ MVert *vertices = mesh->mvert;
+ MEdge *edges = mesh->medge;
+ MPoly *polys = mesh->mpoly;
+ MLoop *loops = mesh->mloop;
+ MLoopCol *colors = mesh->mloopcol;
v[0] = strip_vertices.begin();
- v[1] = v[0]; ++(v[1]);
- v[2] = v[1]; ++(v[2]);
+ v[1] = v[0] + 1;
+ v[2] = v[0] + 2;
vertex_index = edge_index = loop_index = 0;
visible = false;
// Note: Mesh generation in the following loop assumes stroke strips
// to be triangle strips.
- for (n = 2; n < strip_vertex_count; n++)
- {
+ for (n = 2; n < strip_vertex_count; n++, v[0]++, v[1]++, v[2]++) {
svRep[0] = *(v[0]);
svRep[1] = *(v[1]);
svRep[2] = *(v[2]);
xl = xu = yl = yu = 0;
for (int j = 0; j < 3; j++) {
p = svRep[j]->point2d();
- if (p[0] < 0.0) xl++; else if (p[0] > _width) xu++;
- if (p[1] < 0.0) yl++; else if (p[1] > _height) yu++;
+ if (p[0] < 0.0)
+ xl++;
+ else if (p[0] > _width)
+ xu++;
+ if (p[1] < 0.0)
+ yl++;
+ else if (p[1] > _height)
+ yu++;
}
if (xl == 3 || xu == 3 || yl == 3 || yu == 3) {
visible = false;
- } else {
+ }
+ else {
if (!visible) {
// first vertex
vertices->co[0] = svRep[0]->point2d()[0];
@@ -306,7 +348,7 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const{
vertices->co[2] = get_stroke_vertex_z();
++vertices;
++vertex_index;
-
+
// second vertex
vertices->co[0] = svRep[1]->point2d()[0];
vertices->co[1] = svRep[1]->point2d()[1];
@@ -355,7 +397,8 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const{
loops[2].v = vertex_index - 3;
loops[2].e = edge_index - 2;
- } else {
+ }
+ else {
loops[0].v = vertex_index - 1;
loops[0].e = edge_index - 2;
@@ -370,52 +413,49 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const{
// colors
if (n % 2 == 0) {
- colors[0].r = (short)(255.0f*svRep[2]->color()[0]);
- colors[0].g = (short)(255.0f*svRep[2]->color()[1]);
- colors[0].b = (short)(255.0f*svRep[2]->color()[2]);
- colors[0].a = (short)(255.0f*svRep[2]->alpha());
-
- colors[1].r = (short)(255.0f*svRep[1]->color()[0]);
- colors[1].g = (short)(255.0f*svRep[1]->color()[1]);
- colors[1].b = (short)(255.0f*svRep[1]->color()[2]);
- colors[1].a = (short)(255.0f*svRep[1]->alpha());
-
- colors[2].r = (short)(255.0f*svRep[0]->color()[0]);
- colors[2].g = (short)(255.0f*svRep[0]->color()[1]);
- colors[2].b = (short)(255.0f*svRep[0]->color()[2]);
- colors[2].a = (short)(255.0f*svRep[0]->alpha());
- } else {
- colors[0].r = (short)(255.0f*svRep[2]->color()[0]);
- colors[0].g = (short)(255.0f*svRep[2]->color()[1]);
- colors[0].b = (short)(255.0f*svRep[2]->color()[2]);
- colors[0].a = (short)(255.0f*svRep[2]->alpha());
-
- colors[1].r = (short)(255.0f*svRep[0]->color()[0]);
- colors[1].g = (short)(255.0f*svRep[0]->color()[1]);
- colors[1].b = (short)(255.0f*svRep[0]->color()[2]);
- colors[1].a = (short)(255.0f*svRep[0]->alpha());
-
- colors[2].r = (short)(255.0f*svRep[1]->color()[0]);
- colors[2].g = (short)(255.0f*svRep[1]->color()[1]);
- colors[2].b = (short)(255.0f*svRep[1]->color()[2]);
- colors[2].a = (short)(255.0f*svRep[1]->alpha());
+ colors[0].r = (short)(255.0f * svRep[2]->color()[0]);
+ colors[0].g = (short)(255.0f * svRep[2]->color()[1]);
+ colors[0].b = (short)(255.0f * svRep[2]->color()[2]);
+ colors[0].a = (short)(255.0f * svRep[2]->alpha());
+
+ colors[1].r = (short)(255.0f * svRep[1]->color()[0]);
+ colors[1].g = (short)(255.0f * svRep[1]->color()[1]);
+ colors[1].b = (short)(255.0f * svRep[1]->color()[2]);
+ colors[1].a = (short)(255.0f * svRep[1]->alpha());
+
+ colors[2].r = (short)(255.0f * svRep[0]->color()[0]);
+ colors[2].g = (short)(255.0f * svRep[0]->color()[1]);
+ colors[2].b = (short)(255.0f * svRep[0]->color()[2]);
+ colors[2].a = (short)(255.0f * svRep[0]->alpha());
+ }
+ else {
+ colors[0].r = (short)(255.0f * svRep[2]->color()[0]);
+ colors[0].g = (short)(255.0f * svRep[2]->color()[1]);
+ colors[0].b = (short)(255.0f * svRep[2]->color()[2]);
+ colors[0].a = (short)(255.0f * svRep[2]->alpha());
+
+ colors[1].r = (short)(255.0f * svRep[0]->color()[0]);
+ colors[1].g = (short)(255.0f * svRep[0]->color()[1]);
+ colors[1].b = (short)(255.0f * svRep[0]->color()[2]);
+ colors[1].a = (short)(255.0f * svRep[0]->alpha());
+
+ colors[2].r = (short)(255.0f * svRep[1]->color()[0]);
+ colors[2].g = (short)(255.0f * svRep[1]->color()[1]);
+ colors[2].b = (short)(255.0f * svRep[1]->color()[2]);
+ colors[2].a = (short)(255.0f * svRep[1]->alpha());
}
colors += 3;
-
}
- ++v[0]; ++v[1]; ++v[2];
-
- } // loop over strip vertices
+ } // loop over strip vertices
#if 0
BKE_mesh_validate(mesh, TRUE);
#endif
-
- } // loop over strips
-
+ } // loop over strips
}
// A replacement of BKE_object_add() for better performance.
-Object* BlenderStrokeRenderer::NewMesh() const {
+Object *BlenderStrokeRenderer::NewMesh() const
+{
Object *ob;
Base *base;
char name[MAX_ID_NAME];
@@ -428,8 +468,10 @@ Object* BlenderStrokeRenderer::NewMesh() const {
ob->lay = 1;
base = BKE_scene_base_add(freestyle_scene, ob);
- //BKE_scene_base_deselect_all(scene);
- //BKE_scene_base_select(scene, base);
+#if 0
+ BKE_scene_base_deselect_all(scene);
+ BKE_scene_base_select(scene, base);
+#endif
ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME;
--mesh_id;
@@ -437,11 +479,12 @@ Object* BlenderStrokeRenderer::NewMesh() const {
return ob;
}
-Render* BlenderStrokeRenderer::RenderScene( Render *re ) {
- Camera *camera = (Camera *)freestyle_scene->camera->data;
- if (camera->clipend < _z)
- camera->clipend = _z + _z_delta * 100.0f;
- //cout << "clipsta " << camera->clipsta << ", clipend " << camera->clipend << endl;
+Render* BlenderStrokeRenderer::RenderScene(Render *re)
+{
+ Camera *camera = (Camera*)freestyle_scene->camera->data;
+ if (camera->clipend < _z)
+ camera->clipend = _z + _z_delta * 100.0f;
+ //cout << "clipsta " << camera->clipsta << ", clipend " << camera->clipend << endl;
Render *freestyle_render = RE_NewRender(freestyle_scene->id.name);
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h
index 022a115456f..d1c82e7a3b4 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h
+++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h
@@ -1,9 +1,41 @@
-#ifndef BLENDERSTROKERENDERER_H
-# define BLENDERSTROKERENDERER_H
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
-# include "../stroke/StrokeRenderer.h"
-# include "../system/FreestyleConfig.h"
+#ifndef __BLENDERSTROKERENDERER_H__
+#define __BLENDERSTROKERENDERER_H__
+/** \file blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h
+ * \ingroup freestyle
+ */
+
+#include "../stroke/StrokeRenderer.h"
+#include "../system/FreestyleConfig.h"
+
+// XXX Are those "ifdef __cplusplus" useful here?
#ifdef __cplusplus
extern "C" {
#endif
@@ -17,31 +49,28 @@ extern "C" {
}
#endif
-
-
class LIB_STROKE_EXPORT BlenderStrokeRenderer : public StrokeRenderer
{
public:
- BlenderStrokeRenderer(Render *re, int render_count);
- virtual ~BlenderStrokeRenderer();
+ BlenderStrokeRenderer(Render *re, int render_count);
+ virtual ~BlenderStrokeRenderer();
- /*! Renders a stroke rep */
- virtual void RenderStrokeRep(StrokeRep *iStrokeRep) const;
- virtual void RenderStrokeRepBasic(StrokeRep *iStrokeRep) const;
+ /*! Renders a stroke rep */
+ virtual void RenderStrokeRep(StrokeRep *iStrokeRep) const;
+ virtual void RenderStrokeRepBasic(StrokeRep *iStrokeRep) const;
- Object* NewMesh() const;
+ Object *NewMesh() const;
- Render* RenderScene(Render *re);
+ Render *RenderScene(Render *re);
protected:
- Scene* old_scene;
- Scene* freestyle_scene;
- Material* material;
+ Scene *old_scene;
+ Scene *freestyle_scene;
+ Material *material;
float _width, _height;
float _z, _z_delta;
float get_stroke_vertex_z(void) const;
};
-#endif // BLENDERSTROKERENDERER_H
-
+#endif // __BLENDERSTROKERENDERER_H__
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h b/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h
index 93b5f694eb6..4c6f7e02722 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h
+++ b/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h
@@ -1,5 +1,36 @@
-#ifndef BLENDERSTYLEMODULE_H
-#define BLENDERSTYLEMODULE_H
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BLENDERSTYLEMODULE_H__
+#define __BLENDERSTYLEMODULE_H__
+
+/** \file blender/freestyle/intern/blender_interface/BlenderStyleModule.h
+ * \ingroup freestyle
+ */
#include "../stroke/StyleModule.h"
#include "../system/PythonInterpreter.h"
@@ -12,21 +43,21 @@ extern "C" {
class BlenderStyleModule : public StyleModule
{
-public:
-
- BlenderStyleModule(struct Text *text, const string &name,
- Interpreter *inter) : StyleModule(name, inter) {
+public:
+ BlenderStyleModule(struct Text *text, const string &name, Interpreter *inter) : StyleModule(name, inter)
+ {
_text = text;
}
- virtual ~BlenderStyleModule() {
+ virtual ~BlenderStyleModule()
+ {
BKE_text_unlink(G.main, _text);
BKE_libblock_free(&G.main->text, _text);
}
protected:
-
- virtual int interpret() {
+ virtual int interpret()
+ {
PythonInterpreter* py_inter = dynamic_cast<PythonInterpreter*>(_inter);
assert(py_inter != 0);
return py_inter->interpretText(_text, getFileName());
@@ -36,4 +67,4 @@ private:
struct Text *_text;
};
-#endif // BLENDERSTYLEMODULE_H
+#endif // __BLENDERSTYLEMODULE_H__
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderTextureManager.cpp b/source/blender/freestyle/intern/blender_interface/BlenderTextureManager.cpp
index d731af42d0e..053ad636837 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderTextureManager.cpp
+++ b/source/blender/freestyle/intern/blender_interface/BlenderTextureManager.cpp
@@ -1,71 +1,98 @@
-#include "BlenderTextureManager.h"
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/freestyle/intern/blender_interface/BlenderTextureManager.cpp
+ * \ingroup freestyle
+ */
+#include "BlenderTextureManager.h"
-BlenderTextureManager::BlenderTextureManager ()
+BlenderTextureManager::BlenderTextureManager()
: TextureManager()
{
- //_brushes_path = Config::getInstance()...
+ //_brushes_path = Config::getInstance()...
}
-BlenderTextureManager::~BlenderTextureManager ()
+BlenderTextureManager::~BlenderTextureManager()
{
}
void BlenderTextureManager::loadStandardBrushes()
{
- // getBrushTextureIndex(TEXTURES_DIR "/brushes/charcoalAlpha.bmp", Stroke::HUMID_MEDIUM);
- // getBrushTextureIndex(TEXTURES_DIR "/brushes/washbrushAlpha.bmp", Stroke::HUMID_MEDIUM);
- // getBrushTextureIndex(TEXTURES_DIR "/brushes/oil.bmp", Stroke::HUMID_MEDIUM);
- // getBrushTextureIndex(TEXTURES_DIR "/brushes/oilnoblend.bmp", Stroke::HUMID_MEDIUM);
- // getBrushTextureIndex(TEXTURES_DIR "/brushes/charcoalAlpha.bmp", Stroke::DRY_MEDIUM);
- // getBrushTextureIndex(TEXTURES_DIR "/brushes/washbrushAlpha.bmp", Stroke::DRY_MEDIUM);
- // getBrushTextureIndex(TEXTURES_DIR "/brushes/opaqueDryBrushAlpha.bmp", Stroke::OPAQUE_MEDIUM);
- // getBrushTextureIndex(TEXTURES_DIR "/brushes/opaqueBrushAlpha.bmp", Stroke::OPAQUE_MEDIUM);
- //_defaultTextureId = getBrushTextureIndex("smoothAlpha.bmp", Stroke::OPAQUE_MEDIUM);
+#if 0
+ getBrushTextureIndex(TEXTURES_DIR "/brushes/charcoalAlpha.bmp", Stroke::HUMID_MEDIUM);
+ getBrushTextureIndex(TEXTURES_DIR "/brushes/washbrushAlpha.bmp", Stroke::HUMID_MEDIUM);
+ getBrushTextureIndex(TEXTURES_DIR "/brushes/oil.bmp", Stroke::HUMID_MEDIUM);
+ getBrushTextureIndex(TEXTURES_DIR "/brushes/oilnoblend.bmp", Stroke::HUMID_MEDIUM);
+ getBrushTextureIndex(TEXTURES_DIR "/brushes/charcoalAlpha.bmp", Stroke::DRY_MEDIUM);
+ getBrushTextureIndex(TEXTURES_DIR "/brushes/washbrushAlpha.bmp", Stroke::DRY_MEDIUM);
+ getBrushTextureIndex(TEXTURES_DIR "/brushes/opaqueDryBrushAlpha.bmp", Stroke::OPAQUE_MEDIUM);
+ getBrushTextureIndex(TEXTURES_DIR "/brushes/opaqueBrushAlpha.bmp", Stroke::OPAQUE_MEDIUM);
+ _defaultTextureId = getBrushTextureIndex("smoothAlpha.bmp", Stroke::OPAQUE_MEDIUM);
+#endif
}
-
-unsigned
-BlenderTextureManager::loadBrush(string sname, Stroke::MediumType mediumType)
+unsigned int BlenderTextureManager::loadBrush(string sname, Stroke::MediumType mediumType)
{
-// GLuint texId;
-// glGenTextures(1, &texId);
-// bool found = false;
-// vector<string> pathnames;
-// string path; //soc
-// StringUtils::getPathName(TextureManager::Options::getBrushesPath(),
-// sname,
-// pathnames);
-// for (vector<string>::const_iterator j = pathnames.begin(); j != pathnames.end(); j++) {
-// path = j->c_str();
-// //soc if(QFile::exists(path)){
-// if( BLI_exists( const_cast<char *>(path.c_str()) ) ) {
-// found = true;
-// break;
-// }
-// }
-// if(!found)
-// return 0;
-// // Brush texture
-// cout << "Loading brush texture..." << endl;
-// switch(mediumType){
-// case Stroke::DRY_MEDIUM:
-// //soc prepareTextureLuminance((const char*)path.toAscii(), texId);
-// prepareTextureLuminance(StringUtils::toAscii(path), texId);
-// break;
-// case Stroke::HUMID_MEDIUM:
-// case Stroke::OPAQUE_MEDIUM:
-// default:
-// //soc prepareTextureAlpha((const char*)path.toAscii(), texId);
-// prepareTextureAlpha(StringUtils::toAscii(path), texId);
-// break;
-// }
-// cout << "Done." << endl << endl;
-//
-// return texId;
-//
+#if 0
+ GLuint texId;
+ glGenTextures(1, &texId);
+ bool found = false;
+ vector<string> pathnames;
+ string path; //soc
+ StringUtils::getPathName(TextureManager::Options::getBrushesPath(), sname, pathnames);
+ for (vector<string>::const_iterator j = pathnames.begin(); j != pathnames.end(); j++) {
+ path = j->c_str();
+ //soc if (QFile::exists(path)) {
+ if (BLI_exists( const_cast<char *>(path.c_str()))) {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ return 0;
+ // Brush texture
+ cout << "Loading brush texture..." << endl;
+ switch (mediumType) {
+ case Stroke::DRY_MEDIUM:
+ //soc prepareTextureLuminance((const char*)path.toAscii(), texId);
+ prepareTextureLuminance(StringUtils::toAscii(path), texId);
+ break;
+ case Stroke::HUMID_MEDIUM:
+ case Stroke::OPAQUE_MEDIUM:
+ default:
+ //soc prepareTextureAlpha((const char*)path.toAscii(), texId);
+ prepareTextureAlpha(StringUtils::toAscii(path), texId);
+ break;
+ }
+ cout << "Done." << endl << endl;
+
+ return texId;
+#else
return 0;
+#endif
}
-
-
-
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderTextureManager.h b/source/blender/freestyle/intern/blender_interface/BlenderTextureManager.h
index fac33c139e1..bd6f377b1eb 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderTextureManager.h
+++ b/source/blender/freestyle/intern/blender_interface/BlenderTextureManager.h
@@ -1,23 +1,53 @@
-#ifndef BLENDERTEXTUREMANAGER_H
-#define BLENDERTEXTUREMANAGER_H
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BLENDERTEXTUREMANAGER_H__
+#define __BLENDERTEXTUREMANAGER_H__
+
+/** \file blender/freestyle/intern/blender_interface/BlenderTextureManager.h
+ * \ingroup freestyle
+ */
# include "../stroke/StrokeRenderer.h"
# include "../stroke/StrokeRep.h"
# include "../system/FreestyleConfig.h"
-/*! Class to load textures
- */
+/*! Class to load textures */
class LIB_RENDERING_EXPORT BlenderTextureManager : public TextureManager
{
- public:
- BlenderTextureManager ();
- virtual ~BlenderTextureManager ();
+public:
+ BlenderTextureManager();
+ virtual ~BlenderTextureManager();
+
protected:
- virtual unsigned loadBrush(string fileName, Stroke::MediumType = Stroke::OPAQUE_MEDIUM);
-
- protected:
- virtual void loadStandardBrushes();
+ virtual unsigned int loadBrush(string fileName, Stroke::MediumType=Stroke::OPAQUE_MEDIUM);
+protected:
+ virtual void loadStandardBrushes();
};
-#endif // BLENDERTEXTUREMANAGER_H
+#endif // __BLENDERTEXTUREMANAGER_H__
diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
index e432815a30f..759bf09380f 100644
--- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
+++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
@@ -1,13 +1,46 @@
-#include "../application/Controller.h"
-#include "../application/AppView.h"
-#include "../application/AppConfig.h"
-#include "../application/AppCanvas.h"
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
+ * \ingroup freestyle
+ */
#include <iostream>
#include <map>
#include <set>
+
+#include "../application/AppCanvas.h"
+#include "../application/AppConfig.h"
+#include "../application/AppView.h"
+#include "../application/Controller.h"
+
using namespace std;
+// XXX Are those "ifdef __cplusplus" useful here?
#ifdef __cplusplus
extern "C" {
#endif
@@ -15,725 +48,781 @@ extern "C" {
#include "MEM_guardedalloc.h"
#include "DNA_camera_types.h"
-#include "DNA_text_types.h"
-#include "DNA_group_types.h"
#include "DNA_freestyle_types.h"
+#include "DNA_group_types.h"
+#include "DNA_text_types.h"
#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_linestyle.h"
#include "BKE_main.h"
#include "BKE_text.h"
+
#include "BLI_blenlib.h"
#include "BLI_math.h"
+
#include "BPY_extern.h"
#include "renderpipeline.h"
#include "pixelblending.h"
-#include "../../FRS_freestyle.h"
-#include "../../FRS_freestyle_config.h"
-
-#define DEFAULT_SPHERE_RADIUS 1.0f
-#define DEFAULT_DKR_EPSILON 0.0f
-
- // Freestyle configuration
- static short freestyle_is_initialized = 0;
- static Config::Path *pathconfig = NULL;
- static Controller *controller = NULL;
- static AppView *view = NULL;
-
- // line set buffer for copy & paste
- static FreestyleLineSet lineset_buffer;
- static bool lineset_copied = false;
-
- // camera information
- float freestyle_viewpoint[3];
- float freestyle_mv[4][4];
- float freestyle_proj[4][4];
- int freestyle_viewport[4];
-
- // current scene
- Scene *freestyle_scene;
-
- string default_module_path;
-
- //=======================================================
- // Initialization
- //=======================================================
-
- void FRS_initialize() {
-
- if( freestyle_is_initialized )
- return;
-
- pathconfig = new Config::Path;
- controller = new Controller();
- view = new AppView;
- controller->setView(view);
- controller->Clear();
- freestyle_scene = NULL;
- lineset_copied = false;
-
- default_module_path = pathconfig->getProjectDir() + Config::DIR_SEP + "style_modules" + Config::DIR_SEP + "contour.py";
-
- freestyle_is_initialized = 1;
- }
-
- void FRS_set_context(bContext* C) {
- cout << "FRS_set_context: context 0x" << C << " scene 0x" << CTX_data_scene(C) << endl;
- controller->setContext(C);
- }
+#include "FRS_freestyle.h"
+#include "FRS_freestyle_config.h"
- void FRS_read_file(bContext* C) {
- lineset_copied = false;
- }
+#define DEFAULT_SPHERE_RADIUS 1.0f
+#define DEFAULT_DKR_EPSILON 0.0f
- void FRS_exit() {
- delete pathconfig;
- delete controller;
- delete view;
- }
+// Freestyle configuration
+static short freestyle_is_initialized = 0;
+static Config::Path *pathconfig = NULL;
+static Controller *controller = NULL;
+static AppView *view = NULL;
- //=======================================================
- // Rendering
- //=======================================================
-
- static void init_view(Render* re){
- int width = re->winx;
- int height = re->winy;
- int xmin = re->disprect.xmin;
- int ymin = re->disprect.ymin;
- int xmax = re->disprect.xmax;
- int ymax = re->disprect.ymax;
-
- float thickness = 1.f;
- switch (re->r.line_thickness_mode) {
- case R_LINE_THICKNESS_ABSOLUTE:
- thickness = re->r.unit_line_thickness * (re->r.size / 100.f);
- break;
- case R_LINE_THICKNESS_RELATIVE:
- thickness = height / 480.f;
- break;
- }
+// line set buffer for copy & paste
+static FreestyleLineSet lineset_buffer;
+static bool lineset_copied = false;
- freestyle_viewport[0] = freestyle_viewport[1] = 0;
- freestyle_viewport[2] = width;
- freestyle_viewport[3] = height;
-
- view->setWidth( width );
- view->setHeight( height );
- view->setBorder( xmin, ymin, xmax, ymax );
- view->setThickness( thickness );
-
- cout << "\n=== Dimensions of the 2D image coordinate system ===" << endl;
- cout << "Width : " << width << endl;
- cout << "Height : " << height << endl;
- if (re->r.mode & R_BORDER)
- cout << "Border : (" << xmin << ", " << ymin << ") - (" << xmax << ", " << ymax << ")" << endl;
- cout << "Unit line thickness : " << thickness << " pixel(s)" << endl;
- }
+// camera information
+float freestyle_viewpoint[3];
+float freestyle_mv[4][4];
+float freestyle_proj[4][4];
+int freestyle_viewport[4];
- static void init_camera(Render* re){
- // It is assumed that imported meshes are in the camera coordinate system.
- // Therefore, the view point (i.e., camera position) is at the origin, and
- // the the model-view matrix is simply the identity matrix.
-
- freestyle_viewpoint[0] = 0.0;
- freestyle_viewpoint[1] = 0.0;
- freestyle_viewpoint[2] = 0.0;
-
- for( int i = 0; i < 4; i++ )
- for( int j = 0; j < 4; j++ )
- freestyle_mv[i][j] = (i == j) ? 1.0 : 0.0;
-
- for( int i = 0; i < 4; i++ )
- for( int j = 0; j < 4; j++ )
- freestyle_proj[i][j] = re->winmat[i][j];
+// current scene
+Scene *freestyle_scene;
- //print_m4("mv", freestyle_mv);
- //print_m4("proj", freestyle_proj);
- }
+string default_module_path;
- static char *escape_quotes(char *name)
- {
- char *s= (char *)MEM_mallocN(strlen(name) * 2 + 1, "escape_quotes");
- char *p= s;
- while (*name) {
- if (*name == '\'')
- *p++= '\\';
- *p++ = *name++;
- }
- *p = '\0';
- return s;
+//=======================================================
+// Initialization
+//=======================================================
+
+void FRS_initialize()
+{
+ if (freestyle_is_initialized)
+ return;
+
+ pathconfig = new Config::Path;
+ controller = new Controller();
+ view = new AppView;
+ controller->setView(view);
+ controller->Clear();
+ freestyle_scene = NULL;
+ lineset_copied = false;
+
+ default_module_path = pathconfig->getProjectDir() + Config::DIR_SEP + "style_modules" +
+ Config::DIR_SEP + "contour.py";
+
+ freestyle_is_initialized = 1;
+}
+
+void FRS_set_context(bContext *C)
+{
+ cout << "FRS_set_context: context 0x" << C << " scene 0x" << CTX_data_scene(C) << endl;
+ controller->setContext(C);
+}
+
+void FRS_read_file(bContext *C)
+{
+ lineset_copied = false;
+}
+
+void FRS_exit()
+{
+ delete pathconfig;
+ delete controller;
+ delete view;
+}
+
+//=======================================================
+// Rendering
+//=======================================================
+
+static void init_view(Render *re)
+{
+ int width = re->winx;
+ int height = re->winy;
+ int xmin = re->disprect.xmin;
+ int ymin = re->disprect.ymin;
+ int xmax = re->disprect.xmax;
+ int ymax = re->disprect.ymax;
+
+ float thickness = 1.0f;
+ switch (re->r.line_thickness_mode) {
+ case R_LINE_THICKNESS_ABSOLUTE:
+ thickness = re->r.unit_line_thickness * (re->r.size / 100.f);
+ break;
+ case R_LINE_THICKNESS_RELATIVE:
+ thickness = height / 480.f;
+ break;
+ }
+
+ freestyle_viewport[0] = freestyle_viewport[1] = 0;
+ freestyle_viewport[2] = width;
+ freestyle_viewport[3] = height;
+
+ view->setWidth(width);
+ view->setHeight(height);
+ view->setBorder(xmin, ymin, xmax, ymax);
+ view->setThickness(thickness);
+
+ cout << "\n=== Dimensions of the 2D image coordinate system ===" << endl;
+ cout << "Width : " << width << endl;
+ cout << "Height : " << height << endl;
+ if (re->r.mode & R_BORDER)
+ cout << "Border : (" << xmin << ", " << ymin << ") - (" << xmax << ", " << ymax << ")" << endl;
+ cout << "Unit line thickness : " << thickness << " pixel(s)" << endl;
+}
+
+static void init_camera(Render *re)
+{
+ // It is assumed that imported meshes are in the camera coordinate system.
+ // Therefore, the view point (i.e., camera position) is at the origin, and
+ // the the model-view matrix is simply the identity matrix.
+
+ freestyle_viewpoint[0] = 0.0;
+ freestyle_viewpoint[1] = 0.0;
+ freestyle_viewpoint[2] = 0.0;
+
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++)
+ freestyle_mv[i][j] = (i == j) ? 1.0 : 0.0;
}
- static Text *create_lineset_handler(char *layer_name, char *lineset_name)
- {
- char *s1= escape_quotes(layer_name);
- char *s2= escape_quotes(lineset_name);
- Text *text= BKE_text_add(lineset_name);
- BKE_text_write(text, "import parameter_editor; parameter_editor.process('");
- BKE_text_write(text, s1);
- BKE_text_write(text, "', '");
- BKE_text_write(text, s2);
- BKE_text_write(text, "')\n");
- MEM_freeN(s1);
- MEM_freeN(s2);
- return text;
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++)
+ freestyle_proj[i][j] = re->winmat[i][j];
}
- struct edge_type_condition {
- int edge_type, value;
- };
-
- // examines the conditions and returns true if the target edge type needs to be computed
- static bool test_edge_type_conditions(struct edge_type_condition *conditions,
- int num_edge_types, bool logical_and, int target, bool distinct)
- {
- int target_condition = 0;
- int num_non_target_positive_conditions = 0;
- int num_non_target_negative_conditions = 0;
-
- for (int i = 0; i < num_edge_types; i++) {
- if (conditions[i].edge_type == target)
- target_condition = conditions[i].value;
- else if (conditions[i].value > 0)
- ++num_non_target_positive_conditions;
- else if (conditions[i].value < 0)
- ++num_non_target_negative_conditions;
+#if 0
+ print_m4("mv", freestyle_mv);
+ print_m4("proj", freestyle_proj);
+#endif
+}
+
+static char *escape_quotes(char *name)
+{
+ char *s = (char*)MEM_mallocN(strlen(name) * 2 + 1, "escape_quotes");
+ char *p = s;
+ while (*name) {
+ if (*name == '\'')
+ *(p++) = '\\';
+ *(p++) = *(name++);
+ }
+ *p = '\0';
+ return s;
+}
+
+static Text *create_lineset_handler(char *layer_name, char *lineset_name)
+{
+ char *s1 = escape_quotes(layer_name);
+ char *s2 = escape_quotes(lineset_name);
+ Text *text = BKE_text_add(lineset_name);
+ BKE_text_write(text, "import parameter_editor; parameter_editor.process('");
+ BKE_text_write(text, s1);
+ BKE_text_write(text, "', '");
+ BKE_text_write(text, s2);
+ BKE_text_write(text, "')\n");
+ MEM_freeN(s1);
+ MEM_freeN(s2);
+ return text;
+}
+
+struct edge_type_condition
+{
+ int edge_type, value;
+};
+
+// examines the conditions and returns true if the target edge type needs to be computed
+static bool test_edge_type_conditions(struct edge_type_condition *conditions,
+ int num_edge_types, bool logical_and, int target, bool distinct)
+{
+ int target_condition = 0;
+ int num_non_target_positive_conditions = 0;
+ int num_non_target_negative_conditions = 0;
+
+ for (int i = 0; i < num_edge_types; i++) {
+ if (conditions[i].edge_type == target)
+ target_condition = conditions[i].value;
+ else if (conditions[i].value > 0)
+ ++num_non_target_positive_conditions;
+ else if (conditions[i].value < 0)
+ ++num_non_target_negative_conditions;
+ }
+ if (distinct) {
+ // In this case, the 'target' edge type is assumed to appear on distinct edge
+ // of its own and never together with other edge types.
+ if (logical_and) {
+ if (num_non_target_positive_conditions > 0)
+ return false;
+ if (target_condition > 0)
+ return true;
+ if (target_condition < 0)
+ return false;
+ if (num_non_target_negative_conditions > 0)
+ return true;
}
- if (distinct) {
- // In this case, the 'target' edge type is assumed to appear on distinct edge
- // of its own and never together with other edge types.
- if (logical_and) {
- if (num_non_target_positive_conditions > 0)
- return false;
- if (target_condition > 0)
- return true;
- if (target_condition < 0)
- return false;
- if (num_non_target_negative_conditions > 0)
- return true;
- } else {
- if (target_condition > 0)
- return true;
- if (num_non_target_negative_conditions > 0)
- return true;
- if (target_condition < 0)
- return false;
- if (num_non_target_positive_conditions > 0)
- return false;
- }
- } else {
- // In this case, the 'target' edge type may appear together with other edge types.
+ else {
if (target_condition > 0)
return true;
+ if (num_non_target_negative_conditions > 0)
+ return true;
if (target_condition < 0)
+ return false;
+ if (num_non_target_positive_conditions > 0)
+ return false;
+ }
+ }
+ else {
+ // In this case, the 'target' edge type may appear together with other edge types.
+ if (target_condition > 0)
+ return true;
+ if (target_condition < 0)
+ return true;
+ if (logical_and) {
+ if (num_non_target_positive_conditions > 0)
+ return false;
+ if (num_non_target_negative_conditions > 0)
return true;
- if (logical_and) {
- if (num_non_target_positive_conditions > 0)
- return false;
- if (num_non_target_negative_conditions > 0)
- return true;
- } else {
- if (num_non_target_negative_conditions > 0)
- return true;
- if (num_non_target_positive_conditions > 0)
- return false;
- }
}
- return true;
+ else {
+ if (num_non_target_negative_conditions > 0)
+ return true;
+ if (num_non_target_positive_conditions > 0)
+ return false;
+ }
}
+ return true;
+}
- static void prepare(Render* re, SceneRenderLayer* srl ) {
-
- // load mesh
- re->i.infostr= "Freestyle: Mesh loading";
- re->stats_draw(re->sdh, &re->i);
- re->i.infostr= NULL;
- if( controller->LoadMesh(re, srl) ) // returns if scene cannot be loaded or if empty
- return;
- if( re->test_break(re->tbh) )
- return;
-
- // add style modules
- FreestyleConfig* config = &srl->freestyleConfig;
-
- cout << "\n=== Rendering options ===" << endl;
- int layer_count = 0;
-
- switch (config->mode) {
- case FREESTYLE_CONTROL_SCRIPT_MODE:
- cout << "Modules :"<< endl;
- for (FreestyleModuleConfig* module_conf = (FreestyleModuleConfig *)config->modules.first; module_conf; module_conf = module_conf->next) {
- if( module_conf->is_displayed ) {
- cout << " " << layer_count+1 << ": " << module_conf->module_path << endl;
- controller->InsertStyleModule( layer_count, module_conf->module_path );
- controller->toggleLayer(layer_count, true);
- layer_count++;
- }
+static void prepare(Render *re, SceneRenderLayer *srl)
+{
+ // load mesh
+ re->i.infostr = "Freestyle: Mesh loading";
+ re->stats_draw(re->sdh, &re->i);
+ re->i.infostr = NULL;
+ if (controller->LoadMesh(re, srl)) // returns if scene cannot be loaded or if empty
+ return;
+ if (re->test_break(re->tbh))
+ return;
+
+ // add style modules
+ FreestyleConfig *config = &srl->freestyleConfig;
+
+ cout << "\n=== Rendering options ===" << endl;
+ int layer_count = 0;
+
+ switch (config->mode) {
+ case FREESTYLE_CONTROL_SCRIPT_MODE:
+ cout << "Modules :" << endl;
+ for (FreestyleModuleConfig *module_conf = (FreestyleModuleConfig*)config->modules.first;
+ module_conf;
+ module_conf = module_conf->next)
+ {
+ if(module_conf->is_displayed) {
+ cout << " " << layer_count+1 << ": " << module_conf->module_path << endl;
+ controller->InsertStyleModule(layer_count, module_conf->module_path);
+ controller->toggleLayer(layer_count, true);
+ layer_count++;
}
- cout << endl;
- controller->setComputeRidgesAndValleysFlag( (config->flags & FREESTYLE_RIDGES_AND_VALLEYS_FLAG) ? true : false);
- controller->setComputeSuggestiveContoursFlag( (config->flags & FREESTYLE_SUGGESTIVE_CONTOURS_FLAG) ? true : false);
- controller->setComputeMaterialBoundariesFlag( (config->flags & FREESTYLE_MATERIAL_BOUNDARIES_FLAG) ? true : false);
- break;
- case FREESTYLE_CONTROL_EDITOR_MODE:
- int use_ridges_and_valleys = 0;
- int use_suggestive_contours = 0;
- int use_material_boundaries = 0;
- struct edge_type_condition conditions[] = {
- {FREESTYLE_FE_SILHOUETTE, 0},
- {FREESTYLE_FE_BORDER, 0},
- {FREESTYLE_FE_CREASE, 0},
- {FREESTYLE_FE_RIDGE_VALLEY, 0},
- {FREESTYLE_FE_SUGGESTIVE_CONTOUR, 0},
- {FREESTYLE_FE_MATERIAL_BOUNDARY, 0},
- {FREESTYLE_FE_CONTOUR, 0},
- {FREESTYLE_FE_EXTERNAL_CONTOUR, 0},
- {FREESTYLE_FE_EDGE_MARK, 0}};
- int num_edge_types = sizeof(conditions) / sizeof(struct edge_type_condition);
- cout << "Linesets:"<< endl;
- for (FreestyleLineSet *lineset = (FreestyleLineSet *)config->linesets.first; lineset; lineset = lineset->next) {
- if (lineset->flags & FREESTYLE_LINESET_ENABLED) {
- cout << " " << layer_count+1 << ": " << lineset->name << " - " << lineset->linestyle->id.name+2 << endl;
- Text *text = create_lineset_handler(srl->name, lineset->name);
- controller->InsertStyleModule( layer_count, lineset->name, text );
- controller->toggleLayer(layer_count, true);
- if (!(lineset->selection & FREESTYLE_SEL_EDGE_TYPES) || !lineset->edge_types) {
+ }
+ cout << endl;
+ controller->setComputeRidgesAndValleysFlag((config->flags & FREESTYLE_RIDGES_AND_VALLEYS_FLAG) ? true : false);
+ controller->setComputeSuggestiveContoursFlag((config->flags & FREESTYLE_SUGGESTIVE_CONTOURS_FLAG) ? true : false);
+ controller->setComputeMaterialBoundariesFlag((config->flags & FREESTYLE_MATERIAL_BOUNDARIES_FLAG) ? true : false);
+ break;
+ case FREESTYLE_CONTROL_EDITOR_MODE:
+ int use_ridges_and_valleys = 0;
+ int use_suggestive_contours = 0;
+ int use_material_boundaries = 0;
+ struct edge_type_condition conditions[] = {
+ {FREESTYLE_FE_SILHOUETTE, 0},
+ {FREESTYLE_FE_BORDER, 0},
+ {FREESTYLE_FE_CREASE, 0},
+ {FREESTYLE_FE_RIDGE_VALLEY, 0},
+ {FREESTYLE_FE_SUGGESTIVE_CONTOUR, 0},
+ {FREESTYLE_FE_MATERIAL_BOUNDARY, 0},
+ {FREESTYLE_FE_CONTOUR, 0},
+ {FREESTYLE_FE_EXTERNAL_CONTOUR, 0},
+ {FREESTYLE_FE_EDGE_MARK, 0}
+ };
+ int num_edge_types = sizeof(conditions) / sizeof(struct edge_type_condition);
+ cout << "Linesets:" << endl;
+ for (FreestyleLineSet *lineset = (FreestyleLineSet*)config->linesets.first;
+ lineset;
+ lineset = lineset->next)
+ {
+ if (lineset->flags & FREESTYLE_LINESET_ENABLED) {
+ cout << " " << layer_count+1 << ": " << lineset->name << " - "
+ << lineset->linestyle->id.name+2 << endl;
+ Text *text = create_lineset_handler(srl->name, lineset->name);
+ controller->InsertStyleModule(layer_count, lineset->name, text);
+ controller->toggleLayer(layer_count, true);
+ if (!(lineset->selection & FREESTYLE_SEL_EDGE_TYPES) || !lineset->edge_types) {
+ ++use_ridges_and_valleys;
+ ++use_suggestive_contours;
+ ++use_material_boundaries;
+ }
+ else {
+ // conditions for feature edge selection by edge types
+ for (int i = 0; i < num_edge_types; i++) {
+ if (!(lineset->edge_types & conditions[i].edge_type))
+ conditions[i].value = 0; // no condition specified
+ else if (!(lineset->exclude_edge_types & conditions[i].edge_type))
+ conditions[i].value = 1; // condition: X
+ else
+ conditions[i].value = -1; // condition: NOT X
+ }
+ // logical operator for the selection conditions
+ bool logical_and = ((lineset->flags & FREESTYLE_LINESET_FE_AND) != 0);
+ // negation operator
+ if (lineset->flags & FREESTYLE_LINESET_FE_NOT) {
+ // convert an Exclusive condition into an Inclusive equivalent using De Morgan's laws:
+ // NOT (X OR Y) --> (NOT X) AND (NOT Y)
+ // NOT (X AND Y) --> (NOT X) OR (NOT Y)
+ for (int i = 0; i < num_edge_types; i++)
+ conditions[i].value *= -1;
+ logical_and = !logical_and;
+ }
+ if (test_edge_type_conditions(conditions, num_edge_types, logical_and,
+ FREESTYLE_FE_RIDGE_VALLEY, true))
+ {
++use_ridges_and_valleys;
+ }
+ if (test_edge_type_conditions(conditions, num_edge_types, logical_and,
+ FREESTYLE_FE_SUGGESTIVE_CONTOUR, true))
+ {
++use_suggestive_contours;
+ }
+ if (test_edge_type_conditions(conditions, num_edge_types, logical_and,
+ FREESTYLE_FE_MATERIAL_BOUNDARY, true))
+ {
++use_material_boundaries;
- } else {
- // conditions for feature edge selection by edge types
- for (int i = 0; i < num_edge_types; i++) {
- if (!(lineset->edge_types & conditions[i].edge_type))
- conditions[i].value = 0; // no condition specified
- else if (!(lineset->exclude_edge_types & conditions[i].edge_type))
- conditions[i].value = 1; // condition: X
- else
- conditions[i].value = -1; // condition: NOT X
- }
- // logical operator for the selection conditions
- bool logical_and = ((lineset->flags & FREESTYLE_LINESET_FE_AND) != 0);
- // negation operator
- if (lineset->flags & FREESTYLE_LINESET_FE_NOT) {
- // convert an Exclusive condition into an Inclusive equivalent using De Morgan's laws:
- // NOT (X OR Y) --> (NOT X) AND (NOT Y)
- // NOT (X AND Y) --> (NOT X) OR (NOT Y)
- for (int i = 0; i < num_edge_types; i++)
- conditions[i].value *= -1;
- logical_and = !logical_and;
- }
- if (test_edge_type_conditions(conditions, num_edge_types, logical_and, FREESTYLE_FE_RIDGE_VALLEY, true))
- ++use_ridges_and_valleys;
- if (test_edge_type_conditions(conditions, num_edge_types, logical_and, FREESTYLE_FE_SUGGESTIVE_CONTOUR, true))
- ++use_suggestive_contours;
- if (test_edge_type_conditions(conditions, num_edge_types, logical_and, FREESTYLE_FE_MATERIAL_BOUNDARY, true))
- ++use_material_boundaries;
}
- layer_count++;
}
+ layer_count++;
}
- controller->setComputeRidgesAndValleysFlag( use_ridges_and_valleys > 0 );
- controller->setComputeSuggestiveContoursFlag( use_suggestive_contours > 0 );
- controller->setComputeMaterialBoundariesFlag( use_material_boundaries > 0 );
- break;
}
-
- // set parameters
- if (config->flags & FREESTYLE_ADVANCED_OPTIONS_FLAG) {
- controller->setSphereRadius( config->sphere_radius );
- controller->setSuggestiveContourKrDerivativeEpsilon( config->dkr_epsilon );
- } else {
- controller->setSphereRadius( DEFAULT_SPHERE_RADIUS );
- controller->setSuggestiveContourKrDerivativeEpsilon( DEFAULT_DKR_EPSILON );
+ controller->setComputeRidgesAndValleysFlag(use_ridges_and_valleys > 0);
+ controller->setComputeSuggestiveContoursFlag(use_suggestive_contours > 0);
+ controller->setComputeMaterialBoundariesFlag(use_material_boundaries > 0);
+ break;
+ }
+
+ // set parameters
+ if (config->flags & FREESTYLE_ADVANCED_OPTIONS_FLAG) {
+ controller->setSphereRadius(config->sphere_radius);
+ controller->setSuggestiveContourKrDerivativeEpsilon(config->dkr_epsilon);
+ }
+ else {
+ controller->setSphereRadius(DEFAULT_SPHERE_RADIUS);
+ controller->setSuggestiveContourKrDerivativeEpsilon(DEFAULT_DKR_EPSILON);
+ }
+ controller->setFaceSmoothness((config->flags & FREESTYLE_FACE_SMOOTHNESS_FLAG) ? true : false);
+ controller->setCreaseAngle(RAD2DEGF(config->crease_angle));
+ controller->setVisibilityAlgo((config->flags & FREESTYLE_CULLING) ?
+ FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE :
+ FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE);
+
+ cout << "Crease angle : " << controller->getCreaseAngle() << endl;
+ cout << "Sphere radius : " << controller->getSphereRadius() << endl;
+ cout << "Face smoothness : " << (controller->getFaceSmoothness() ? "enabled" : "disabled") << endl;
+ cout << "Redges and valleys : " << (controller->getComputeRidgesAndValleysFlag() ? "enabled" : "disabled") << endl;
+ cout << "Suggestive contours : " << (controller->getComputeSuggestiveContoursFlag() ? "enabled" : "disabled")
+ << endl;
+ cout << "Suggestive contour Kr derivative epsilon : " << controller->getSuggestiveContourKrDerivativeEpsilon()
+ << endl;
+ cout << "Material boundaries : " << (controller->getComputeMaterialBoundariesFlag() ? "enabled" : "disabled")
+ << endl;
+ cout << endl;
+
+ // set diffuse and z depth passes
+ RenderLayer *rl = RE_GetRenderLayer(re->result, srl->name);
+ bool diffuse = false, z = false;
+ for (RenderPass *rpass = (RenderPass*)rl->passes.first; rpass; rpass = rpass->next) {
+ switch (rpass->passtype) {
+ case SCE_PASS_DIFFUSE:
+ controller->setPassDiffuse(rpass->rect, rpass->rectx, rpass->recty);
+ diffuse = true;
+ break;
+ case SCE_PASS_Z:
+ controller->setPassZ(rpass->rect, rpass->rectx, rpass->recty);
+ z = true;
+ break;
}
- controller->setFaceSmoothness( (config->flags & FREESTYLE_FACE_SMOOTHNESS_FLAG) ? true : false);
- controller->setCreaseAngle( RAD2DEGF(config->crease_angle) );
- controller->setVisibilityAlgo( (config->flags & FREESTYLE_CULLING) ?
- FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE : FREESTYLE_ALGO_ADAPTIVE_CUMULATIVE );
-
- cout << "Crease angle : " << controller->getCreaseAngle() << endl;
- cout << "Sphere radius : " << controller->getSphereRadius() << endl;
- cout << "Face smoothness : " << (controller->getFaceSmoothness() ? "enabled" : "disabled") << endl;
- cout << "Redges and valleys : " << (controller->getComputeRidgesAndValleysFlag() ? "enabled" : "disabled") << endl;
- cout << "Suggestive contours : " << (controller->getComputeSuggestiveContoursFlag() ? "enabled" : "disabled") << endl;
- cout << "Suggestive contour Kr derivative epsilon : " << controller->getSuggestiveContourKrDerivativeEpsilon() << endl;
- cout << "Material boundaries : " << (controller->getComputeMaterialBoundariesFlag() ? "enabled" : "disabled") << endl;
- cout << endl;
+ }
+ cout << "Passes :" << endl;
+ cout << " Diffuse = " << (diffuse ? "enabled" : "disabled") << endl;
+ cout << " Z = " << (z ? "enabled" : "disabled") << endl;
- // set diffuse and z depth passes
- RenderLayer *rl = RE_GetRenderLayer(re->result, srl->name);
- bool diffuse = false, z = false;
- for (RenderPass *rpass = (RenderPass *)rl->passes.first; rpass; rpass = rpass->next) {
- switch (rpass->passtype) {
- case SCE_PASS_DIFFUSE:
- controller->setPassDiffuse(rpass->rect, rpass->rectx, rpass->recty);
- diffuse = true;
- break;
- case SCE_PASS_Z:
- controller->setPassZ(rpass->rect, rpass->rectx, rpass->recty);
- z = true;
- break;
- }
- }
- cout << "Passes :" << endl;
- cout << " Diffuse = " << (diffuse ? "enabled" : "disabled") << endl;
- cout << " Z = " << (z ? "enabled" : "disabled") << endl;
+ // compute view map
+ re->i.infostr = "Freestyle: View map creation";
+ re->stats_draw(re->sdh, &re->i);
+ re->i.infostr = NULL;
+ controller->ComputeViewMap();
+}
- // compute view map
- re->i.infostr= "Freestyle: View map creation";
- re->stats_draw(re->sdh, &re->i);
- re->i.infostr= NULL;
- controller->ComputeViewMap();
- }
-
- void FRS_composite_result(Render* re, SceneRenderLayer* srl, Render* freestyle_render)
- {
- RenderLayer *rl;
- float *src, *dest, *pixSrc, *pixDest;
- int x, y, rectx, recty;
-
- if( freestyle_render == NULL || freestyle_render->result == NULL )
- return;
-
- rl = render_get_active_layer( freestyle_render, freestyle_render->result );
- if( !rl || rl->rectf == NULL) { cout << "Cannot find Freestyle result image" << endl; return; }
- src = rl->rectf;
- //cout << "src: " << rl->rectx << " x " << rl->recty << endl;
-
- rl = RE_GetRenderLayer(re->result, srl->name);
- if( !rl || rl->rectf == NULL) { cout << "No layer to composite to" << endl; return; }
- dest = rl->rectf;
- //cout << "dest: " << rl->rectx << " x " << rl->recty << endl;
-
- rectx = re->rectx;
- recty = re->recty;
- for( y = 0; y < recty; y++) {
- for( x = 0; x < rectx; x++) {
- pixSrc = src + 4 * (rectx * y + x);
- if( pixSrc[3] > 0.0) {
- pixDest = dest + 4 * (rectx * y + x);
- addAlphaOverFloat(pixDest, pixSrc);
- }
+void FRS_composite_result(Render* re, SceneRenderLayer* srl, Render* freestyle_render)
+{
+ RenderLayer *rl;
+ float *src, *dest, *pixSrc, *pixDest;
+ int x, y, rectx, recty;
+
+ if (freestyle_render == NULL || freestyle_render->result == NULL)
+ return;
+
+ rl = render_get_active_layer( freestyle_render, freestyle_render->result );
+ if (!rl || rl->rectf == NULL) {
+ cout << "Cannot find Freestyle result image" << endl;
+ return;
+ }
+ src = rl->rectf;
+ //cout << "src: " << rl->rectx << " x " << rl->recty << endl;
+
+ rl = RE_GetRenderLayer(re->result, srl->name);
+ if (!rl || rl->rectf == NULL) {
+ cout << "No layer to composite to" << endl;
+ return;
+ }
+ dest = rl->rectf;
+ //cout << "dest: " << rl->rectx << " x " << rl->recty << endl;
+
+ rectx = re->rectx;
+ recty = re->recty;
+ for (y = 0; y < recty; y++) {
+ for (x = 0; x < rectx; x++) {
+ pixSrc = src + 4 * (rectx * y + x);
+ if (pixSrc[3] > 0.0) {
+ pixDest = dest + 4 * (rectx * y + x);
+ addAlphaOverFloat(pixDest, pixSrc);
}
- }
- }
-
- static int displayed_layer_count( SceneRenderLayer* srl ) {
- int count = 0;
-
- switch (srl->freestyleConfig.mode) {
- case FREESTYLE_CONTROL_SCRIPT_MODE:
- for (FreestyleModuleConfig* module = (FreestyleModuleConfig *)srl->freestyleConfig.modules.first; module; module = module->next) {
- if( module->is_displayed )
- count++;
- }
- break;
- case FREESTYLE_CONTROL_EDITOR_MODE:
- for (FreestyleLineSet *lineset = (FreestyleLineSet *)srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
- if (lineset->flags & FREESTYLE_LINESET_ENABLED)
- count++;
- }
- break;
}
- return count;
}
+}
- int FRS_is_freestyle_enabled(SceneRenderLayer* srl) {
- return (!(srl->layflag & SCE_LAY_DISABLE) &&
- srl->layflag & SCE_LAY_FRS &&
- displayed_layer_count(srl) > 0);
+static int displayed_layer_count(SceneRenderLayer *srl)
+{
+ int count = 0;
+
+ switch (srl->freestyleConfig.mode) {
+ case FREESTYLE_CONTROL_SCRIPT_MODE:
+ for (FreestyleModuleConfig *module = (FreestyleModuleConfig*)srl->freestyleConfig.modules.first;
+ module;
+ module = module->next)
+ {
+ if (module->is_displayed)
+ count++;
+ }
+ break;
+ case FREESTYLE_CONTROL_EDITOR_MODE:
+ for (FreestyleLineSet *lineset = (FreestyleLineSet*)srl->freestyleConfig.linesets.first;
+ lineset;
+ lineset = lineset->next)
+ {
+ if (lineset->flags & FREESTYLE_LINESET_ENABLED)
+ count++;
+ }
+ break;
}
-
- void FRS_init_stroke_rendering(Render* re) {
+ return count;
+}
+
+int FRS_is_freestyle_enabled(SceneRenderLayer *srl)
+{
+ return (!(srl->layflag & SCE_LAY_DISABLE) && srl->layflag & SCE_LAY_FRS && displayed_layer_count(srl) > 0);
+}
- cout << "\n#===============================================================" << endl;
- cout << "# Freestyle" << endl;
- cout << "#===============================================================" << endl;
-
- init_view(re);
- init_camera(re);
+void FRS_init_stroke_rendering(Render *re)
+{
+ cout << endl;
+ cout << "#===============================================================" << endl;
+ cout << "# Freestyle" << endl;
+ cout << "#===============================================================" << endl;
- controller->ResetRenderCount();
- }
-
- Render* FRS_do_stroke_rendering(Render* re, SceneRenderLayer *srl) {
-
- Render* freestyle_render = NULL;
-
- RenderMonitor monitor(re);
- controller->setRenderMonitor(&monitor);
-
- cout << "\n----------------------------------------------------------" << endl;
- cout << "| " << (re->scene->id.name+2) << "|" << srl->name << endl;
- cout << "----------------------------------------------------------" << endl;
-
- // prepare Freestyle:
- // - load mesh
- // - add style modules
- // - set parameters
- // - compute view map
- prepare(re, srl);
-
- if( re->test_break(re->tbh) ) {
- controller->CloseFile();
- cout << "Break" << endl;
- return NULL;
- }
-
- // render and composite Freestyle result
- if( controller->_ViewMap ) {
-
- // render strokes
- re->i.infostr= "Freestyle: Stroke rendering";
- re->stats_draw(re->sdh, &re->i);
- re->i.infostr= NULL;
- freestyle_scene = re->scene;
- controller->DrawStrokes();
- freestyle_render = controller->RenderStrokes(re);
- controller->CloseFile();
- freestyle_scene = NULL;
-
- // composite result
- FRS_composite_result(re, srl, freestyle_render);
- RE_FreeRenderResult(freestyle_render->result);
- freestyle_render->result = NULL;
- }
+ init_view(re);
+ init_camera(re);
+
+ controller->ResetRenderCount();
+}
- return freestyle_render;
+Render *FRS_do_stroke_rendering(Render *re, SceneRenderLayer *srl)
+{
+ Render *freestyle_render = NULL;
+
+ RenderMonitor monitor(re);
+ controller->setRenderMonitor(&monitor);
+
+ cout << endl;
+ cout << "----------------------------------------------------------" << endl;
+ cout << "| " << (re->scene->id.name + 2) << "|" << srl->name << endl;
+ cout << "----------------------------------------------------------" << endl;
+
+ // prepare Freestyle:
+ // - load mesh
+ // - add style modules
+ // - set parameters
+ // - compute view map
+ prepare(re, srl);
+
+ if (re->test_break(re->tbh)) {
+ controller->CloseFile();
+ cout << "Break" << endl;
+ return NULL;
}
- void FRS_finish_stroke_rendering(Render* re) {
- // clear canvas
- controller->Clear();
+ // render and composite Freestyle result
+ if (controller->_ViewMap) {
+ // render strokes
+ re->i.infostr = "Freestyle: Stroke rendering";
+ re->stats_draw(re->sdh, &re->i);
+ re->i.infostr = NULL;
+ freestyle_scene = re->scene;
+ controller->DrawStrokes();
+ freestyle_render = controller->RenderStrokes(re);
+ controller->CloseFile();
+ freestyle_scene = NULL;
+
+ // composite result
+ FRS_composite_result(re, srl, freestyle_render);
+ RE_FreeRenderResult(freestyle_render->result);
+ freestyle_render->result = NULL;
}
- //=======================================================
- // Freestyle Panel Configuration
- //=======================================================
+ return freestyle_render;
+}
+
+void FRS_finish_stroke_rendering(Render *re) {
+ // clear canvas
+ controller->Clear();
+}
- void FRS_add_freestyle_config( SceneRenderLayer* srl )
- {
- FreestyleConfig* config = &srl->freestyleConfig;
-
- config->mode = FREESTYLE_CONTROL_SCRIPT_MODE;
+//=======================================================
+// Freestyle Panel Configuration
+//=======================================================
- config->modules.first = config->modules.last = NULL;
- config->flags = 0;
- config->sphere_radius = DEFAULT_SPHERE_RADIUS;
- config->dkr_epsilon = DEFAULT_DKR_EPSILON;
- config->crease_angle = 134.43f;
+void FRS_add_freestyle_config(SceneRenderLayer *srl)
+{
+ FreestyleConfig *config = &srl->freestyleConfig;
- config->linesets.first = config->linesets.last = NULL;
- }
-
- void FRS_free_freestyle_config( SceneRenderLayer* srl )
- {
- FreestyleLineSet *lineset;
-
- for(lineset=(FreestyleLineSet *)srl->freestyleConfig.linesets.first; lineset; lineset=lineset->next) {
- if (lineset->group) {
- lineset->group->id.us--;
- lineset->group = NULL;
- }
- lineset->linestyle->id.us--;
- lineset->linestyle = NULL;
+ config->mode = FREESTYLE_CONTROL_SCRIPT_MODE;
+
+ config->modules.first = config->modules.last = NULL;
+ config->flags = 0;
+ config->sphere_radius = DEFAULT_SPHERE_RADIUS;
+ config->dkr_epsilon = DEFAULT_DKR_EPSILON;
+ config->crease_angle = DEG2RADF(120.0f);
+
+ config->linesets.first = config->linesets.last = NULL;
+}
+
+void FRS_free_freestyle_config(SceneRenderLayer *srl)
+{
+ FreestyleLineSet *lineset;
+
+ for (lineset = (FreestyleLineSet*)srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
+ if (lineset->group) {
+ lineset->group->id.us--;
+ lineset->group = NULL;
}
- BLI_freelistN( &srl->freestyleConfig.linesets );
- BLI_freelistN( &srl->freestyleConfig.modules );
+ lineset->linestyle->id.us--;
+ lineset->linestyle = NULL;
}
+ BLI_freelistN(&srl->freestyleConfig.linesets);
+ BLI_freelistN(&srl->freestyleConfig.modules);
+}
- void FRS_add_module(FreestyleConfig *config)
- {
- FreestyleModuleConfig* module_conf = (FreestyleModuleConfig*) MEM_callocN( sizeof(FreestyleModuleConfig), "style module configuration");
- BLI_addtail(&config->modules, (void*) module_conf);
-
- strcpy( module_conf->module_path, default_module_path.c_str() );
- module_conf->is_displayed = 1;
- }
-
- void FRS_delete_module(FreestyleConfig *config, FreestyleModuleConfig *module_conf)
- {
- BLI_freelinkN(&config->modules, module_conf);
- }
-
- void FRS_move_module_up(FreestyleConfig *config, FreestyleModuleConfig *module_conf)
- {
- BLI_remlink(&config->modules, module_conf);
- BLI_insertlinkbefore(&config->modules, module_conf->prev, module_conf);
- }
-
- void FRS_move_module_down(FreestyleConfig *config, FreestyleModuleConfig *module_conf)
- {
- BLI_remlink(&config->modules, module_conf);
- BLI_insertlinkafter(&config->modules, module_conf->next, module_conf);
- }
+void FRS_add_module(FreestyleConfig *config)
+{
+ FreestyleModuleConfig *module_conf = (FreestyleModuleConfig*)MEM_callocN(sizeof(FreestyleModuleConfig),
+ "style module configuration");
+ BLI_addtail(&config->modules, (void*)module_conf);
- static void unique_lineset_name(FreestyleConfig *config, FreestyleLineSet *lineset)
- {
- BLI_uniquename(&config->linesets, lineset, "FreestyleLineSet", '.', offsetof(FreestyleLineSet, name), sizeof(lineset->name));
- }
+ strcpy(module_conf->module_path, default_module_path.c_str());
+ module_conf->is_displayed = 1;
+}
- FreestyleLineSet *FRS_add_lineset(FreestyleConfig *config)
- {
- int lineset_index = BLI_countlist(&config->linesets);
-
- FreestyleLineSet *lineset = (FreestyleLineSet *) MEM_callocN( sizeof(FreestyleLineSet), "Freestyle line set");
- BLI_addtail(&config->linesets, (void *) lineset);
- FRS_set_active_lineset_index(config, lineset_index);
-
- lineset->linestyle = FRS_new_linestyle("LineStyle", NULL);
- lineset->flags |= FREESTYLE_LINESET_ENABLED;
- lineset->selection = FREESTYLE_SEL_IMAGE_BORDER;
- lineset->qi = FREESTYLE_QI_VISIBLE;
- lineset->qi_start = 0;
- lineset->qi_end = 100;
- lineset->edge_types = FREESTYLE_FE_SILHOUETTE | FREESTYLE_FE_BORDER | FREESTYLE_FE_CREASE;
- lineset->exclude_edge_types = 0;
- lineset->group = NULL;
- if (lineset_index > 0)
- sprintf(lineset->name, "LineSet %i", lineset_index+1);
- else
- strcpy(lineset->name, "LineSet");
- unique_lineset_name(config, lineset);
+void FRS_delete_module(FreestyleConfig *config, FreestyleModuleConfig *module_conf)
+{
+ BLI_freelinkN(&config->modules, module_conf);
+}
- return lineset;
- }
+void FRS_move_module_up(FreestyleConfig *config, FreestyleModuleConfig *module_conf)
+{
+ BLI_remlink(&config->modules, module_conf);
+ BLI_insertlinkbefore(&config->modules, module_conf->prev, module_conf);
+}
- void FRS_copy_active_lineset(FreestyleConfig *config)
- {
- FreestyleLineSet *lineset = FRS_get_active_lineset(config);
-
- if (lineset) {
- lineset_buffer.linestyle = lineset->linestyle;
- lineset_buffer.flags = lineset->flags;
- lineset_buffer.selection = lineset->selection;
- lineset_buffer.qi = lineset->qi;
- lineset_buffer.qi_start = lineset->qi_start;
- lineset_buffer.qi_end = lineset->qi_end;
- lineset_buffer.edge_types = lineset->edge_types;
- lineset_buffer.exclude_edge_types = lineset->exclude_edge_types;
- lineset_buffer.group = lineset->group;
- strcpy(lineset_buffer.name, lineset->name);
- lineset_copied = true;
- }
+void FRS_move_module_down(FreestyleConfig *config, FreestyleModuleConfig *module_conf)
+{
+ BLI_remlink(&config->modules, module_conf);
+ BLI_insertlinkafter(&config->modules, module_conf->next, module_conf);
+}
+
+static void unique_lineset_name(FreestyleConfig *config, FreestyleLineSet *lineset)
+{
+ BLI_uniquename(&config->linesets, lineset, "FreestyleLineSet", '.', offsetof(FreestyleLineSet, name),
+ sizeof(lineset->name));
+}
+
+FreestyleLineSet *FRS_add_lineset(FreestyleConfig *config)
+{
+ int lineset_index = BLI_countlist(&config->linesets);
+
+ FreestyleLineSet *lineset = (FreestyleLineSet*)MEM_callocN(sizeof(FreestyleLineSet), "Freestyle line set");
+ BLI_addtail(&config->linesets, (void*)lineset);
+ FRS_set_active_lineset_index(config, lineset_index);
+
+ lineset->linestyle = FRS_new_linestyle("LineStyle", NULL);
+ lineset->flags |= FREESTYLE_LINESET_ENABLED;
+ lineset->selection = FREESTYLE_SEL_IMAGE_BORDER;
+ lineset->qi = FREESTYLE_QI_VISIBLE;
+ lineset->qi_start = 0;
+ lineset->qi_end = 100;
+ lineset->edge_types = FREESTYLE_FE_SILHOUETTE | FREESTYLE_FE_BORDER | FREESTYLE_FE_CREASE;
+ lineset->exclude_edge_types = 0;
+ lineset->group = NULL;
+ if (lineset_index > 0)
+ sprintf(lineset->name, "LineSet %i", lineset_index + 1);
+ else
+ strcpy(lineset->name, "LineSet");
+ unique_lineset_name(config, lineset);
+
+ return lineset;
+}
+
+void FRS_copy_active_lineset(FreestyleConfig *config)
+{
+ FreestyleLineSet *lineset = FRS_get_active_lineset(config);
+
+ if (lineset) {
+ lineset_buffer.linestyle = lineset->linestyle;
+ lineset_buffer.flags = lineset->flags;
+ lineset_buffer.selection = lineset->selection;
+ lineset_buffer.qi = lineset->qi;
+ lineset_buffer.qi_start = lineset->qi_start;
+ lineset_buffer.qi_end = lineset->qi_end;
+ lineset_buffer.edge_types = lineset->edge_types;
+ lineset_buffer.exclude_edge_types = lineset->exclude_edge_types;
+ lineset_buffer.group = lineset->group;
+ strcpy(lineset_buffer.name, lineset->name);
+ lineset_copied = true;
}
+}
- void FRS_paste_active_lineset(FreestyleConfig *config)
- {
- if (!lineset_copied)
- return;
-
- FreestyleLineSet *lineset = FRS_get_active_lineset(config);
-
- if (lineset) {
- lineset->linestyle->id.us--;
- lineset->linestyle = lineset_buffer.linestyle;
- lineset->linestyle->id.us++;
- lineset->flags = lineset_buffer.flags;
- lineset->selection = lineset_buffer.selection;
- lineset->qi = lineset_buffer.qi;
- lineset->qi_start = lineset_buffer.qi_start;
- lineset->qi_end = lineset_buffer.qi_end;
- lineset->edge_types = lineset_buffer.edge_types;
- lineset->exclude_edge_types = lineset_buffer.exclude_edge_types;
- if (lineset->group) {
- lineset->group->id.us--;
- lineset->group = NULL;
- }
- if (lineset_buffer.group) {
- lineset->group = lineset_buffer.group;
- lineset->group->id.us++;
- }
- strcpy(lineset->name, lineset_buffer.name);
- unique_lineset_name(config, lineset);
- lineset->flags |= FREESTYLE_LINESET_CURRENT;
+void FRS_paste_active_lineset(FreestyleConfig *config)
+{
+ if (!lineset_copied)
+ return;
+
+ FreestyleLineSet *lineset = FRS_get_active_lineset(config);
+
+ if (lineset) {
+ lineset->linestyle->id.us--;
+ lineset->linestyle = lineset_buffer.linestyle;
+ lineset->linestyle->id.us++;
+ lineset->flags = lineset_buffer.flags;
+ lineset->selection = lineset_buffer.selection;
+ lineset->qi = lineset_buffer.qi;
+ lineset->qi_start = lineset_buffer.qi_start;
+ lineset->qi_end = lineset_buffer.qi_end;
+ lineset->edge_types = lineset_buffer.edge_types;
+ lineset->exclude_edge_types = lineset_buffer.exclude_edge_types;
+ if (lineset->group) {
+ lineset->group->id.us--;
+ lineset->group = NULL;
+ }
+ if (lineset_buffer.group) {
+ lineset->group = lineset_buffer.group;
+ lineset->group->id.us++;
}
+ strcpy(lineset->name, lineset_buffer.name);
+ unique_lineset_name(config, lineset);
+ lineset->flags |= FREESTYLE_LINESET_CURRENT;
}
+}
- void FRS_delete_active_lineset(FreestyleConfig *config)
- {
- FreestyleLineSet *lineset = FRS_get_active_lineset(config);
+void FRS_delete_active_lineset(FreestyleConfig *config)
+{
+ FreestyleLineSet *lineset = FRS_get_active_lineset(config);
- if (lineset) {
- if (lineset->group) {
- lineset->group->id.us--;
- lineset->group = NULL;
- }
- lineset->linestyle->id.us--;
- lineset->linestyle = NULL;
- BLI_remlink(&config->linesets, lineset);
- MEM_freeN(lineset);
- FRS_set_active_lineset_index(config, 0);
+ if (lineset) {
+ if (lineset->group) {
+ lineset->group->id.us--;
+ lineset->group = NULL;
}
+ lineset->linestyle->id.us--;
+ lineset->linestyle = NULL;
+ BLI_remlink(&config->linesets, lineset);
+ MEM_freeN(lineset);
+ FRS_set_active_lineset_index(config, 0);
}
+}
- void FRS_move_active_lineset_up(FreestyleConfig *config)
- {
- FreestyleLineSet *lineset = FRS_get_active_lineset(config);
+void FRS_move_active_lineset_up(FreestyleConfig *config)
+{
+ FreestyleLineSet *lineset = FRS_get_active_lineset(config);
- if (lineset) {
- BLI_remlink(&config->linesets, lineset);
- BLI_insertlinkbefore(&config->linesets, lineset->prev, lineset);
- }
+ if (lineset) {
+ BLI_remlink(&config->linesets, lineset);
+ BLI_insertlinkbefore(&config->linesets, lineset->prev, lineset);
}
+}
- void FRS_move_active_lineset_down(FreestyleConfig *config)
- {
- FreestyleLineSet *lineset = FRS_get_active_lineset(config);
+void FRS_move_active_lineset_down(FreestyleConfig *config)
+{
+ FreestyleLineSet *lineset = FRS_get_active_lineset(config);
- if (lineset) {
- BLI_remlink(&config->linesets, lineset);
- BLI_insertlinkafter(&config->linesets, lineset->next, lineset);
- }
+ if (lineset) {
+ BLI_remlink(&config->linesets, lineset);
+ BLI_insertlinkafter(&config->linesets, lineset->next, lineset);
}
+}
- FreestyleLineSet *FRS_get_active_lineset(FreestyleConfig *config)
- {
- FreestyleLineSet *lineset;
+FreestyleLineSet *FRS_get_active_lineset(FreestyleConfig *config)
+{
+ FreestyleLineSet *lineset;
- for(lineset=(FreestyleLineSet *)config->linesets.first; lineset; lineset=lineset->next)
- if(lineset->flags & FREESTYLE_LINESET_CURRENT)
- return lineset;
- return NULL;
+ for (lineset = (FreestyleLineSet*)config->linesets.first; lineset; lineset = lineset->next) {
+ if (lineset->flags & FREESTYLE_LINESET_CURRENT)
+ return lineset;
}
+ return NULL;
+}
- short FRS_get_active_lineset_index(FreestyleConfig *config)
- {
- FreestyleLineSet *lineset;
- short i;
+short FRS_get_active_lineset_index(FreestyleConfig *config)
+{
+ FreestyleLineSet *lineset;
+ short i;
- for(lineset=(FreestyleLineSet *)config->linesets.first, i=0; lineset; lineset=lineset->next, i++)
- if(lineset->flags & FREESTYLE_LINESET_CURRENT)
- return i;
- return 0;
+ for (lineset = (FreestyleLineSet*)config->linesets.first, i = 0; lineset; lineset = lineset->next, i++) {
+ if (lineset->flags & FREESTYLE_LINESET_CURRENT)
+ return i;
}
+ return 0;
+}
- void FRS_set_active_lineset_index(FreestyleConfig *config, short index)
- {
- FreestyleLineSet *lineset;
- short i;
+void FRS_set_active_lineset_index(FreestyleConfig *config, short index)
+{
+ FreestyleLineSet *lineset;
+ short i;
- for(lineset=(FreestyleLineSet *)config->linesets.first, i=0; lineset; lineset=lineset->next, i++) {
- if(i == index)
- lineset->flags |= FREESTYLE_LINESET_CURRENT;
- else
- lineset->flags &= ~FREESTYLE_LINESET_CURRENT;
- }
+ for (lineset = (FreestyleLineSet*)config->linesets.first, i = 0; lineset; lineset = lineset->next, i++) {
+ if (i == index)
+ lineset->flags |= FREESTYLE_LINESET_CURRENT;
+ else
+ lineset->flags &= ~FREESTYLE_LINESET_CURRENT;
}
+}
- void FRS_unlink_target_object(FreestyleConfig *config, Object *ob)
- {
- FreestyleLineSet *lineset;
+void FRS_unlink_target_object(FreestyleConfig *config, Object *ob)
+{
+ FreestyleLineSet *lineset;
- for(lineset=(FreestyleLineSet *)config->linesets.first; lineset; lineset=lineset->next) {
- FRS_unlink_linestyle_target_object(lineset->linestyle, ob);
- }
+ for (lineset = (FreestyleLineSet*)config->linesets.first; lineset; lineset = lineset->next) {
+ FRS_unlink_linestyle_target_object(lineset->linestyle, ob);
}
+}
#ifdef __cplusplus
-}
+} // extern "C"
#endif