* Implemented the basic stroke rendering functionality for the new
Parameter Editor mode. This is a WIP commit. Only the base line color, base alpha transparency, and base line thickness are respected. More additions are anticipated to account for other parameters. * Added FRS_finish_stroke_rendering() to clean Freestyle-related temporary resources after stroke rendering. * Some functions in FRS_freestyle.cpp are now declared as static functions, so as not to mess up the program-wide name space. * Made the StyleModule class inheritable, and defined new subclass BlenderStyleModule that takes a Text object instead of a file name.
This commit is contained in:
42
release/scripts/freestyle/style_modules/parameter_editor.py
Normal file
42
release/scripts/freestyle/style_modules/parameter_editor.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# ##### 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.
|
||||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
import Freestyle
|
||||
|
||||
from freestyle_init import *
|
||||
from logical_operators import *
|
||||
from ChainingIterators import *
|
||||
from shaders import *
|
||||
|
||||
def process(layer_name, lineset_name):
|
||||
scene = Freestyle.getCurrentScene()
|
||||
layer = scene.render.layers[layer_name]
|
||||
lineset = layer.freestyle_settings.linesets[lineset_name]
|
||||
linestyle = lineset.linestyle
|
||||
|
||||
color = linestyle.color
|
||||
|
||||
upred = QuantitativeInvisibilityUP1D(0)
|
||||
Operators.select(upred)
|
||||
Operators.bidirectionalChain(ChainSilhouetteIterator(), NotUP1D(upred))
|
||||
shaders_list = [
|
||||
SamplingShader(5.0),
|
||||
ConstantThicknessShader(linestyle.thickness),
|
||||
ConstantColorShader(color.r, color.g, color.b, linestyle.alpha)
|
||||
]
|
||||
Operators.create(TrueUP1D(), shaders_list)
|
||||
@@ -52,6 +52,7 @@ extern "C" {
|
||||
int FRS_is_freestyle_enabled(struct SceneRenderLayer* srl);
|
||||
void FRS_init_stroke_rendering(struct Render* re);
|
||||
struct Render* FRS_do_stroke_rendering(struct Render* re, struct SceneRenderLayer* srl);
|
||||
void FRS_finish_stroke_rendering(struct Render* re);
|
||||
void FRS_composite_result(struct Render* re, struct SceneRenderLayer* srl, struct Render* freestyle_render);
|
||||
void FRS_exit();
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
|
||||
#include "../blender_interface/BlenderFileLoader.h"
|
||||
#include "../blender_interface/BlenderStrokeRenderer.h"
|
||||
#include "../blender_interface/BlenderStyleModule.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -717,6 +718,12 @@ void Controller::InsertStyleModule(unsigned index, const char *iFileName)
|
||||
|
||||
}
|
||||
|
||||
void Controller::InsertStyleModule(unsigned index, const char *iName, struct Text *iText)
|
||||
{
|
||||
StyleModule* sm = new BlenderStyleModule(iText, iName, _inter);
|
||||
_Canvas->InsertStyleModule(index, sm);
|
||||
}
|
||||
|
||||
void Controller::AddStyleModule(const char *iFileName)
|
||||
{
|
||||
//_pStyleWindow->Add(iFileName);
|
||||
|
||||
@@ -89,6 +89,7 @@ public:
|
||||
Render* RenderStrokes(Render *re);
|
||||
void SwapStyleModules(unsigned i1, unsigned i2);
|
||||
void InsertStyleModule(unsigned index, const char *iFileName);
|
||||
void InsertStyleModule(unsigned index, const char *iName, struct Text *iText);
|
||||
void AddStyleModule(const char *iFileName);
|
||||
void RemoveStyleModule(unsigned index);
|
||||
void ReloadStyleModule(unsigned index, const char * iFileName);
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef BLENDERSTYLEMODULE_H
|
||||
#define BLENDERSTYLEMODULE_H
|
||||
|
||||
#include "../stroke/StyleModule.h"
|
||||
#include "../system/PythonInterpreter.h"
|
||||
|
||||
extern "C" {
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_text.h"
|
||||
}
|
||||
|
||||
class BlenderStyleModule : public StyleModule
|
||||
{
|
||||
public:
|
||||
|
||||
BlenderStyleModule(struct Text *text, const string &name,
|
||||
Interpreter *inter) : StyleModule(name, inter) {
|
||||
_text = text;
|
||||
}
|
||||
|
||||
virtual ~BlenderStyleModule() {
|
||||
unlink_text(G.main, _text);
|
||||
free_libblock(&G.main->text, _text);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual int interpret() {
|
||||
PythonInterpreter* py_inter = dynamic_cast<PythonInterpreter*>(_inter);
|
||||
assert(py_inter != 0);
|
||||
return py_inter->interpretText(_text, getFileName());
|
||||
}
|
||||
|
||||
private:
|
||||
struct Text *_text;
|
||||
};
|
||||
|
||||
#endif // BLENDERSTYLEMODULE_H
|
||||
@@ -15,12 +15,14 @@ extern "C" {
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_camera_types.h"
|
||||
#include "DNA_text_types.h"
|
||||
#include "DNA_freestyle_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"
|
||||
@@ -61,6 +63,7 @@ extern "C" {
|
||||
controller = new Controller();
|
||||
view = new AppView;
|
||||
controller->setView(view);
|
||||
controller->Clear();
|
||||
freestyle_scene = NULL;
|
||||
|
||||
default_module_path = pathconfig->getProjectDir() + Config::DIR_SEP + "style_modules" + Config::DIR_SEP + "contour.py";
|
||||
@@ -83,7 +86,7 @@ extern "C" {
|
||||
// Rendering
|
||||
//=======================================================
|
||||
|
||||
void init_view(Render* re){
|
||||
static void init_view(Render* re){
|
||||
float ycor = ((float)re->r.yasp) / ((float)re->r.xasp);
|
||||
int width = re->r.xsch;
|
||||
int height = (int)(((float)re->r.ysch) * ycor);
|
||||
@@ -107,7 +110,7 @@ extern "C" {
|
||||
cout << "Border : (" << xmin << ", " << ymin << ") - (" << xmax << ", " << ymax << ")" << endl;
|
||||
}
|
||||
|
||||
void init_camera(Render* re){
|
||||
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.
|
||||
@@ -128,11 +131,18 @@ extern "C" {
|
||||
//print_m4("proj", freestyle_proj);
|
||||
}
|
||||
|
||||
static Text *create_lineset_handler(char *layer_name, char *lineset_name)
|
||||
{
|
||||
Text *text = add_empty_text(lineset_name);
|
||||
write_text(text, "import parameter_editor; parameter_editor.process('");
|
||||
write_text(text, layer_name);
|
||||
write_text(text, "', '");
|
||||
write_text(text, lineset_name);
|
||||
write_text(text, "')\n");
|
||||
return text;
|
||||
}
|
||||
|
||||
void prepare(Render* re, SceneRenderLayer* srl ) {
|
||||
|
||||
// clear canvas
|
||||
controller->Clear();
|
||||
static void prepare(Render* re, SceneRenderLayer* srl ) {
|
||||
|
||||
// load mesh
|
||||
re->i.infostr= "Freestyle: Mesh loading";
|
||||
@@ -147,10 +157,11 @@ extern "C" {
|
||||
FreestyleConfig* config = &srl->freestyleConfig;
|
||||
|
||||
cout << "\n=== Rendering options ===" << endl;
|
||||
cout << "Modules :"<< 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;
|
||||
@@ -160,6 +171,20 @@ extern "C" {
|
||||
}
|
||||
}
|
||||
cout << endl;
|
||||
break;
|
||||
case FREESTYLE_CONTROL_EDITOR_MODE:
|
||||
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);
|
||||
layer_count++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// set parameters
|
||||
controller->setCreaseAngle( config->crease_angle );
|
||||
@@ -234,13 +259,23 @@ extern "C" {
|
||||
}
|
||||
}
|
||||
|
||||
int displayed_layer_count( SceneRenderLayer* srl ) {
|
||||
static int displayed_layer_count( SceneRenderLayer* srl ) {
|
||||
int count = 0;
|
||||
|
||||
for( FreestyleModuleConfig* module_conf = (FreestyleModuleConfig *)srl->freestyleConfig.modules.first; module_conf; module_conf = module_conf->next ) {
|
||||
if( module_conf->is_displayed )
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -271,7 +306,6 @@ extern "C" {
|
||||
cout << "----------------------------------------------------------" << endl;
|
||||
|
||||
// prepare Freestyle:
|
||||
// - clear canvas
|
||||
// - load mesh
|
||||
// - add style modules
|
||||
// - set parameters
|
||||
@@ -305,6 +339,11 @@ extern "C" {
|
||||
return freestyle_render;
|
||||
}
|
||||
|
||||
void FRS_finish_stroke_rendering(Render* re) {
|
||||
// clear canvas
|
||||
controller->Clear();
|
||||
}
|
||||
|
||||
//=======================================================
|
||||
// Freestyle Panel Configuration
|
||||
//=======================================================
|
||||
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
_inter = inter;
|
||||
}
|
||||
|
||||
~StyleModule() {}
|
||||
virtual ~StyleModule() {}
|
||||
|
||||
StrokeLayer* execute() {
|
||||
if (!_inter) {
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
|
||||
Operators::reset();
|
||||
|
||||
if( _inter->interpretFile(_file_name) ) {
|
||||
if( interpret() ) {
|
||||
cerr << "Error: interpretation failed" << endl;
|
||||
return NULL;
|
||||
}
|
||||
@@ -89,6 +89,14 @@ public:
|
||||
return sl;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual int interpret() {
|
||||
return _inter->interpretFile(_file_name);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// accessors
|
||||
|
||||
const string getFileName() const {
|
||||
@@ -151,6 +159,9 @@ private:
|
||||
bool _drawable;
|
||||
bool _modified;
|
||||
bool _displayed;
|
||||
|
||||
protected:
|
||||
|
||||
Interpreter* _inter;
|
||||
};
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
//soc
|
||||
extern "C" {
|
||||
#include "MEM_guardedalloc.h"
|
||||
#include "DNA_text_types.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_global.h"
|
||||
@@ -101,6 +102,27 @@ class LIB_SYSTEM_EXPORT PythonInterpreter : public Interpreter
|
||||
return 0;
|
||||
}
|
||||
|
||||
int interpretText(struct Text *text, const string& name) {
|
||||
|
||||
initPath();
|
||||
|
||||
ReportList* reports = CTX_wm_reports(_context);
|
||||
|
||||
BKE_reports_clear(reports);
|
||||
|
||||
if (!BPY_run_python_script(_context, NULL, text, reports)) {
|
||||
cout << "\nError executing Python script from PythonInterpreter::interpretText" << endl;
|
||||
cout << "Name: " << name << endl;
|
||||
cout << "Errors: " << endl;
|
||||
BKE_reports_print(reports, RPT_ERROR);
|
||||
return 1;
|
||||
}
|
||||
|
||||
BKE_reports_clear(reports);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct Options
|
||||
{
|
||||
static void setPythonPath(const string& path) {
|
||||
|
||||
@@ -2261,6 +2261,8 @@ static void add_freestyle(Render *re)
|
||||
link->data = (void *)FRS_do_stroke_rendering(re, srl);
|
||||
}
|
||||
}
|
||||
|
||||
FRS_finish_stroke_rendering(re);
|
||||
}
|
||||
|
||||
/* merges the results of Freestyle stroke rendering into a given render result */
|
||||
|
||||
Reference in New Issue
Block a user