1 /*
2  * NodeBox.h
3  *
4  * Copyright (C) 1999 Stephen F. White
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 "Vec3f.h"
28 #include "SFMFTypes.h"
29 
30 class ProtoBox : public Proto {
31 public:
32                     ProtoBox(Scene *scene);
33     virtual Node   *create(Scene *scene);
34 
getType()35     virtual int     getType() const { return VRML_BOX; }
getNodeClass()36     virtual int     getNodeClass() const
37                        { return PRIMITIVE_GEOMETRY_OR_MASS_DENSITY_MODEL_NODE |
38                                 GEOMETRY_NODE; }
39 
isMesh(void)40     virtual bool    isMesh(void) { return true; }
41 
42     FieldIndex size;
43     FieldIndex solid;
44     FieldIndex texCoord;
45     x3domGeometryCommonFieldIndex()
46     FieldIndex ccw;
47     FieldIndex hasHelperColors;
48 };
49 
50 class NodeBox : public MeshBasedNode {
51 public:
52                     NodeBox(Scene *scene, Proto *proto);
53 
getProfile(void)54     virtual int     getProfile(void) const { return PROFILE_INTERCHANGE; }
getX3dVersion(void)55     virtual int     getX3dVersion(void) const { return 0; }
copy()56     virtual Node   *copy() const { return new NodeBox(*this); }
isInvalidChildNode(void)57     virtual bool    isInvalidChildNode(void) { return true; }
draw()58     virtual void    draw() { meshDraw(); }
59     virtual void    drawHandles(void);
60     virtual Vec3f   getHandle(int handle, int *constraint, int *field);
61     virtual void    setHandle(int handle, const Vec3f &v);
62     virtual bool    validHandle(int handle);
63 
64     virtual Node   *toNurbs(int nuAreaPoints, int uDegree,
65                             int nvAreaPoints, int vDegree);
66     virtual Node   *toNurbs(int nuAreaPoints, int uDegree,
67                             int nvAreaPoints, int vDegree, int nzAreaPoints);
68 
flip(int index)69     virtual void    flip(int index) {}
70     virtual void    swap(int fromTo);
71 
countPrimitives(void)72     virtual int     countPrimitives(void) {return 1;}
countPolygons(void)73     virtual int     countPolygons(void) { return 0; }
74 
isFlat(void)75     virtual bool    isFlat(void) { return true; }
76 
shouldConvertToIndexedFaceSet(void)77     virtual bool    shouldConvertToIndexedFaceSet(void) { return false; }
78 
79     fieldMacros(SFVec3f, size,            ProtoBox)
80     fieldMacros(SFBool,  solid,           ProtoBox)
81     fieldMacros(SFNode,  texCoord,        ProtoBox)
82     x3domGeometryCommonFieldMacros(ProtoBox)
83     fieldMacros(SFBool,  ccw,             ProtoBox)
84     fieldMacros(SFBool,  hasHelperColors, ProtoBox)
85 
86 
87 protected:
88     void            createMesh(bool cleanDoubleVertices = true,
89                                bool triangulate = true);
90     void            makeKnotvectors(int uOrder, int uDimension,
91                                     int vOrder, int vDimension);
92     Node           *makeNurbsSurfaces(int surfaces);
93     void            makeNurbsRectangle(float xSize, float ySize,
94                                        float zPosition, int nuAreapoints,
95                                        int uDegree);
96 
97 protected:
m_uKnotSize()98     int             m_uKnotSize() {return m_uKnots.size();}
m_vKnotSize()99     int             m_vKnotSize() {return m_vKnots.size();}
100     int             m_uOrder;
101     int             m_vOrder;
102     int             m_uDimension;
103     int             m_vDimension;
104     int             m_nuAreaPoints;
105     int             m_nvAreaPoints;
106     MyArray<float>  m_uKnots;
107     MyArray<float>  m_vKnots;
108     MyArray<Vec3f>  m_rectangle;
109 };
110