1 /*
2  * NodeTriangleFanSet.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 "MeshBasedNode.h"
25 #include "ProtoMacros.h"
26 #include "Proto.h"
27 #include "DuneApp.h"
28 #include "MyMesh.h"
29 #include "Vec3f.h"
30 #include "NodeCoordinate.h"
31 #include "Colored.h"
32 #include "SFMFTypes.h"
33 #include "ComposedGeometryMacros.h"
34 
35 class ProtoTriangleFanSet : public GeometryProto {
36 public:
37                     ProtoTriangleFanSet(Scene *scene);
38     virtual Node   *create(Scene *scene);
39 
getType()40     virtual int     getType() const { return X3D_TRIANGLE_FAN_SET; }
41 
isMesh(void)42     virtual bool    isMesh(void) { return true; }
43 
isX3dInternalProto(void)44     virtual bool    isX3dInternalProto(void) { return true; }
45 
46     FieldIndex color;
47     FieldIndex coord;
48     FieldIndex fanCount;
49     FieldIndex normal;
50     FieldIndex texCoord;
51     FieldIndex ccw;
52     FieldIndex colorPerVertex;
53     FieldIndex normalPerVertex;
54     FieldIndex solid;
55     ComposedGeometryProtoMacro()
56 };
57 
58 class NodeTriangleFanSet : public MeshBasedNode, Colored {
59 public:
60                     NodeTriangleFanSet(Scene *scene, Proto *proto);
61 
62 protected:
63     virtual        ~NodeTriangleFanSet();
64 
65 public:
66 
getComponentName(void)67     virtual const char* getComponentName(void) const
68                            { return "Rendering"; }
getComponentLevel(void)69     virtual int         getComponentLevel(void) const { return 3; }
getX3dVersion(void)70     virtual int     getX3dVersion(void) const { return 0; }
copy()71     virtual Node   *copy() const { return new NodeTriangleFanSet(*this); }
72 
73     virtual void    setField(int index, FieldValue *value, int cf = -1);
74 
75     virtual void    draw();
76 
77     virtual void    flip(int index);
78     virtual void    swap(int fromTo);
79 
getNormalField()80     virtual int     getNormalField() { return normal_Field(); }
getTexCoordField()81     virtual int     getTexCoordField() { return texCoord_Field(); }
82 
83     virtual void    setNormalFromMesh(Node *nnormal);
84     virtual void    setTexCoordFromMesh(Node *ntexCoord);
85 
hasTwoSides(void)86     virtual bool    hasTwoSides(void) { return true; }
isDoubleSided(void)87     virtual bool    isDoubleSided(void) { return !solid()->getValue(); }
toggleDoubleSided(void)88     virtual void    toggleDoubleSided(void)
89                        { solid(new SFBool(!solid()->getValue())); }
getSolidField()90     virtual int     getSolidField() { return solid_Field(); }
flipSide(void)91     virtual void    flipSide(void) { ccw(new SFBool(!ccw()->getValue())); }
92 
maySetDefault(void)93     virtual bool    maySetDefault(void) { return false; }
94 
canConvertToTriangleSet(void)95     virtual bool    canConvertToTriangleSet(void) { return hasParent(); }
96 
getColorNode()97     virtual NodeColor *getColorNode()
98                     { return (NodeColor *)color()->getValue(); }
getColorRGBANode()99     virtual NodeColorRGBA *getColorRGBANode()
100                     { return (NodeColorRGBA *)color()->getValue(); }
getCoordinateNode(void)101     virtual NodeCoordinate *getCoordinateNode(void)
102                     { return (NodeCoordinate *)coord()->getValue(); }
getColored()103     virtual Colored *getColored() { return this; }
104 
colorPerVertexField()105     virtual int     colorPerVertexField() const
106                        { return colorPerVertex_Field(); }
colorIndexField()107     virtual int     colorIndexField() const
108                        { return -1; }
109 
110     MFVec3f        *getCoordinates();
111     MFVec2f        *getTextureCoordinates();
112 
113     Node           *toIndexedLineSet(void);
114 
115     fieldMacros(SFNode,  color,           ProtoTriangleFanSet)
116     fieldMacros(SFNode,  coord,           ProtoTriangleFanSet)
117     fieldMacros(MFInt32, fanCount,        ProtoTriangleFanSet)
118     fieldMacros(SFNode,  normal,          ProtoTriangleFanSet)
119     fieldMacros(SFNode,  texCoord,        ProtoTriangleFanSet)
120     fieldMacros(SFBool,  ccw,             ProtoTriangleFanSet)
121     fieldMacros(SFBool,  colorPerVertex,  ProtoTriangleFanSet)
122     fieldMacros(SFBool,  normalPerVertex, ProtoTriangleFanSet)
123     fieldMacros(SFBool,  solid,           ProtoTriangleFanSet)
124     ComposedGeometryFieldMacros(ProtoTriangleFanSet)
125 protected:
126     void            createMesh(bool cleanDoubleVertices = true,
127                                bool triangulate = true);
128 
129 protected:
130     MFInt32        *m_coordIndex;
131     bool            m_colorPerVertexWarning;
132 };
133 
134