Skip to content

Commit 3111041

Browse files
committed
add new modules : RollToHorizontal, TextureBaseColor and InterpolateTextureBaseColors
1 parent c627d0c commit 3111041

File tree

2 files changed

+102
-6
lines changed

2 files changed

+102
-6
lines changed

src/cpp/moduleclass.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ typedef pgl_hash_map_string<size_t> ParameterNameDict;
9393
MACRO(iRollL) \
9494
MACRO(iRollR) \
9595
MACRO(TurnAround) \
96-
MACRO(RollToVert) \
96+
MACRO(RollToVert) \
97+
MACRO(RollToHorizontal) \
9798
MACRO(Sphere) \
9899
MACRO(Box) \
99100
MACRO(Quad) \
@@ -126,7 +127,9 @@ typedef pgl_hash_map_string<size_t> ParameterNameDict;
126127
MACRO(TextureVScale) \
127128
MACRO(TextureTranslation) \
128129
MACRO(TextureRotation) \
129-
MACRO(TextureTransformation) \
130+
MACRO(TextureTransformation) \
131+
MACRO(TextureBaseColor) \
132+
MACRO(InterpolateTextureBaseColors) \
130133
MACRO(GetIterator) \
131134
MACRO(GetModule) \
132135
MACRO(New) \

src/cpp/predefinedmodules.cpp

+97-4
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,43 @@ DeclareModuleEnd
477477
#endif
478478
#endif
479479

480-
DeclareSimpleModule(rollToVert, "Roll to Vertical : Roll the turtle around the H axis so that H and U lie in a common vertical plane with U closest to up",eRotation)
480+
DeclareModuleBegin(rollToVert, "Roll to Vertical : Roll the turtle around the H axis so that H and U lie in a common vertical plane with U closest to up",eRotation)
481+
{
482+
#if PGL_VERSION >= 0x021500
483+
switch(m.size()){
484+
case 0: t.rollToVert(); break;
485+
default: t.rollToVert(m._getReal(0)); break;
486+
}
487+
#else
488+
t.rollToVert();
489+
#ifdef _MSC_VER
490+
#pragma message("RollToVert module with parameter will be disabled. Upgrade PlantGL.")
491+
#else
492+
#warning RollToVert module with parameter will be disabled. Upgrade PlantGL.
493+
#endif
494+
495+
#endif
496+
}
497+
DeclareModuleEnd
498+
499+
DeclareModuleBegin(rollToHorizontal, "Roll to Horizontal : Roll the turtle so that H lie in the horizontal plane",eRotation)
500+
{
501+
#if PGL_VERSION >= 0x021500
502+
switch(m.size()){
503+
case 0: t.rollToHorizontal(); break;
504+
default: t.rollToHorizontal(m._getReal(0)); break;
505+
}
506+
#else
507+
508+
#ifdef _MSC_VER
509+
#pragma message("RollToHorizontal module will be disabled. Upgrade PlantGL.")
510+
#else
511+
#warning RollToHorizontal module will be disabled. Upgrade PlantGL.
512+
#endif
513+
#endif
514+
}
515+
DeclareModuleEnd
516+
481517
DeclareModuleReal1(sphere,"Draw a sphere. Params : 'radius' (optional, should be positive, default = line width).",ePrimitive)
482518
DeclareModuleReal1(circle,"Draw a circle. Params : 'radius' (optional, should be positive, default = line width).",ePrimitive)
483519

@@ -561,8 +597,8 @@ DeclareModuleEnd
561597

562598
DeclareModuleBegin(setColor,"Set the current material. Params : 'index' (positive int) or 'r,g,b[,a]' or 'material'.",eColor)
563599
{
564-
if(m.empty()) t.setColor(t.getColor());
565-
else {
600+
if(m.empty()) t.setColor(t.getColor());
601+
else {
566602
int nbatt = m.size();
567603
if (nbatt == 1) {
568604
boost::python::extract<PGL::AppearancePtr> appextractor(m.getAt(0));
@@ -578,6 +614,7 @@ DeclareModuleBegin(setColor,"Set the current material. Params : 'index' (positiv
578614
}
579615
DeclareModuleEnd
580616

617+
581618
DeclareModuleBegin(interpolateColors,"Set the current material. Params : 'index1', 'index2', 'alpha' .",eColor)
582619
{
583620
#if PGL_VERSION >= 0x021300
@@ -604,6 +641,59 @@ DeclareModuleBegin(interpolateColors,"Set the current material. Params : 'index1
604641
}
605642
DeclareModuleEnd
606643

644+
645+
DeclareModuleBegin(textureBaseColor,"Set the base color of the texture. Params : 'index' (positive int) or 'r,g,b[,a]' or 'material'.",eTexture)
646+
{
647+
#if PGL_VERSION >= 0x021500
648+
if(!m.empty()) {
649+
int nbatt = m.size();
650+
if (nbatt == 1) {
651+
boost::python::extract<PGL::MaterialPtr> appextractor(m.getAt(0));
652+
if (appextractor.check()) t.setTextureBaseColor(Color4(appextractor()->getDiffuseColor(), appextractor()->getTransparency()));
653+
else t.setTextureBaseColor(m._getInt(0));
654+
}
655+
else if (nbatt >= 3) {
656+
Color4 c(m._get<uchar_t>(0),m._get<uchar_t>(1),m._get<uchar_t>(2),0);
657+
if (nbatt >= 4) c.getAlpha() = m._get<uchar_t>(3) / 255.f;
658+
t.setTextureBaseColor(c);
659+
}
660+
}
661+
#else
662+
#ifdef _MSC_VER
663+
#pragma message("TextureBaseColor module will be disabled. Upgrade PlantGL.")
664+
#else
665+
#warning TextureBaseColor module will be disabled. Upgrade PlantGL.
666+
#endif
667+
#endif
668+
}
669+
DeclareModuleEnd
670+
671+
DeclareModuleBegin(interpolateTextureBaseColors,"Set the base color of the texture from interpolation of 2 predefined material. Params : 'index1', 'index2', 'alpha' .",eTexture)
672+
{
673+
#if PGL_VERSION >= 0x021500
674+
size_t nbargs = m.size();
675+
switch (nbargs) {
676+
case 0:
677+
case 1:
678+
{
679+
LsysWarning("Argument missing for module "+m.name());
680+
break;
681+
}
682+
case 2:
683+
t.interpolateTextureBaseColors(m._getInt(0),m._getInt(1)); break;
684+
default:
685+
t.interpolateTextureBaseColors(m._getInt(0),m._getInt(1),m._getReal(2)); break;
686+
}
687+
#else
688+
#ifdef _MSC_VER
689+
#pragma message("InterpolateTextureBaseColors module will be disabled. Upgrade PlantGL.")
690+
#else
691+
#warning InterpolateColors module will be disabled. Upgrade PlantGL.
692+
#endif
693+
#endif
694+
}
695+
696+
DeclareModuleEnd
607697
DeclareModuleBegin(divScale,"Divides the current turtle scale by a scale factor, Params : 'scale_factor' (optional, default = 1.0).",eScale)
608698
{
609699
if (m.empty())t.divScale();
@@ -1064,7 +1154,8 @@ void ModuleClass::createPredefinedClasses() {
10641154
iRollL = new DeclaredModule(iRollL)("iRollL");
10651155
iRollR = new DeclaredModule(iRollR)("iRollR");
10661156
TurnAround = new DeclaredModule(turnAround)("|","TurnAround");
1067-
RollToVert = new DeclaredModule(rollToVert)("@v","RollToVert");
1157+
RollToVert = new DeclaredModule(rollToVert)("@v","RollToVert");
1158+
RollToHorizontal = new DeclaredModule(rollToHorizontal)("@h","RollToHorizontal");
10681159
Sphere = new DeclaredModule(sphere)("@O","Sphere");
10691160
Box = new DeclaredModule(box)("@B","Box");
10701161
Quad = new DeclaredModule(quad)("@b","Quad");
@@ -1077,6 +1168,8 @@ void ModuleClass::createPredefinedClasses() {
10771168
DecColor = new DeclaredModule(decColor)(",","DecColor");
10781169
SetColor = new DeclaredModule(setColor)("SetColor");
10791170
InterpolateColors = new DeclaredModule(interpolateColors)("InterpolateColors");
1171+
TextureBaseColor = new DeclaredModule(textureBaseColor)("TextureBaseColor");
1172+
InterpolateTextureBaseColors = new DeclaredModule(interpolateTextureBaseColors)("InterpolateTextureBaseColors");
10801173
DivScale = new DeclaredModule(divScale)("@Dd","DivScale");
10811174
MultScale = new DeclaredModule(multScale)("@Di","MultScale");
10821175
SetScale = new DeclaredModule(scale)("@D","SetScale");

0 commit comments

Comments
 (0)