1 /*
2  * NodeSuperRevolver.h
3  *
4  * Copyright (C) 1999 Stephen F. White, 2008 J. "MUFTI" Scheurich
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program (see the file "COPYING" for details); if
18  * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19  * Cambridge, MA 02139, USA.
20  */
21 
22 #pragma once
23 
24 #include "ProtoMacros.h"
25 #include "Proto.h"
26 #include "NodeNurbsCurve.h"
27 #include "MeshMorphingNode.h"
28 #include "SFMFTypes.h"
29 
30 class SuperRevolverData
31 {
32 public:
33     float a;
34     float b;
35     float m;
36     float n1;
37     float n2;
38     float n3;
39     float border;
40     float bottomBorder;
41     float *controlPoint;
42     float *weight;
43     float *knot;
44 };
45 
46 
47 class ProtoSuperRevolver : public Proto {
48 public:
49                     ProtoSuperRevolver(Scene *scene);
50     virtual Node   *create(Scene *scene);
51 
getType()52     virtual int     getType() const { return DUNE_SUPER_REVOLVER; }
getNodeClass()53     virtual int     getNodeClass() const
54                        { return PARAMETRIC_GEOMETRY_NODE | GEOMETRY_NODE; }
55 
isScriptedExternProto(void)56     virtual bool    isScriptedExternProto(void) { return true; }
57 
isMesh(void)58     virtual bool    isMesh(void) { return true; }
59 
60     FieldIndex      a;
61     FieldIndex      b;
62     FieldIndex      m;
63     FieldIndex      n1;
64     FieldIndex      n2;
65     FieldIndex      n3;
66     FieldIndex      border;
67     FieldIndex      bottomBorder;
68     FieldIndex      superTessellation;
69     FieldIndex      nurbsTessellation;
70     FieldIndex      controlPoint;
71     FieldIndex      weight;
72     FieldIndex      knot;
73     FieldIndex      order;
74     FieldIndex      creaseAngle;
75     FieldIndex      ccw;
76     FieldIndex      solid;
77     FieldIndex      pieceOfCake;
78 };
79 
80 class NodeSuperRevolver : public MeshMorphingNode {
81 public:
82                     NodeSuperRevolver(Scene *scene, Proto *proto);
83                     ~NodeSuperRevolver();
84 
getProfile(void)85     virtual int     getProfile(void) const { return PROFILE_IMMERSIVE; }
getX3dVersion(void)86     virtual int     getX3dVersion(void) const { return -1; }
copy()87     virtual Node   *copy() const { return new NodeSuperRevolver(*this); }
88 
draw()89     virtual void    draw() { meshDraw(); }
90     virtual void    drawHandles(void);
91     virtual void    drawAHandles();
92 
93     virtual Vec3f   getHandle(int handle, int *constraint, int *field);
94     virtual void    setHandle(int handle, const Vec3f &v);
95 
96     virtual void    setField(int index, FieldValue *value, int cf = -1);
97 
98     virtual void    flip(int index);
99     virtual void    swap(int fromTo);
canMoveTo(int direction)100     virtual bool    canMoveTo(int direction) { return true; }
101 
getSolidField()102     virtual int     getSolidField() { return solid_Field(); }
flipSide(void)103     virtual void    flipSide(void) { ccw(new SFBool(!ccw()->getValue())); }
104 
maySetDefault(void)105     virtual bool    maySetDefault(void) { return false; }
106 
avoidProtoOnPureVrml(void)107     virtual bool    avoidProtoOnPureVrml(void) { return true; }
108     virtual int     writeProto(int filedes);
109 
110     Node           *degreeElevate(int newDegree);
111 
112     virtual Node   *toNurbsCurve(void);
113     virtual Node   *toNurbs(int uTess,  int vTess, int uDegree, int vDegree);
114 
115     fieldMacros(SFFloat, a,                 ProtoSuperRevolver)
116     fieldMacros(SFFloat, b,                 ProtoSuperRevolver)
117     fieldMacros(SFFloat, m,                 ProtoSuperRevolver)
118     fieldMacros(SFFloat, n1,                ProtoSuperRevolver)
119     fieldMacros(SFFloat, n2,                ProtoSuperRevolver)
120     fieldMacros(SFFloat, n3,                ProtoSuperRevolver)
121     fieldMacros(SFFloat, border,            ProtoSuperRevolver)
122     fieldMacros(SFFloat, bottomBorder,      ProtoSuperRevolver)
123     fieldMacros(SFInt32, superTessellation, ProtoSuperRevolver)
124     fieldMacros(SFInt32, nurbsTessellation, ProtoSuperRevolver)
125     fieldMacros(MFVec2f, controlPoint,      ProtoSuperRevolver)
126     fieldMacros(MFFloat, weight,            ProtoSuperRevolver)
127     fieldMacros(MFFloat, knot,              ProtoSuperRevolver)
128     fieldMacros(SFInt32, order,             ProtoSuperRevolver)
129     fieldMacros(SFFloat, creaseAngle,       ProtoSuperRevolver)
130     fieldMacros(SFBool,  ccw,               ProtoSuperRevolver)
131     fieldMacros(SFBool,  solid,             ProtoSuperRevolver)
132     fieldMacros(SFBool,  pieceOfCake,       ProtoSuperRevolver)
133 protected:
134     void            createMesh(bool cleanDoubleVertices = true,
135                                bool triangulate = true);
136     void            createMesh(SuperRevolverData &data);
137     void           *initializeData(void);
138     void            loadDataFromInterpolators(void *data, Interpolator *inter,
139                                               int field, float key);
140     void            createMeshFromData(void* data, bool optimize);
141     void            finalizeData(void* data);
142     void            copyData(SuperRevolverData *data);
143 
144 protected:
145     NodeNurbsCurve    *m_nurbsCurve;
146     MyArray<float>     m_chain;
147     SuperRevolverData  m_tempStoreData;
148 };
149 
150