1 | #ifndef MXBLOCKMODEL_INCLUDED // -*- C++ -*-
|
---|
2 | #define MXBLOCKMODEL_INCLUDED
|
---|
3 | #if !defined(__GNUC__)
|
---|
4 | # pragma once
|
---|
5 | #endif
|
---|
6 |
|
---|
7 | /************************************************************************
|
---|
8 |
|
---|
9 | MxBlockModel
|
---|
10 |
|
---|
11 | Copyright (C) 1998 Michael Garland. See "COPYING.txt" for details.
|
---|
12 |
|
---|
13 | $Id: MxBlockModel.h,v 1.1 2002/09/24 16:53:54 wimmer Exp $
|
---|
14 |
|
---|
15 | ************************************************************************/
|
---|
16 |
|
---|
17 | #include "MxDynBlock.h"
|
---|
18 | #include "MxGeoPrims.h"
|
---|
19 | #include "MxRaster.h"
|
---|
20 |
|
---|
21 | #define MX_UNBOUND 0x0
|
---|
22 | #define MX_PERFACE 0x1
|
---|
23 | #define MX_PERVERTEX 0x2
|
---|
24 | #define MX_MAX_BINDING 0x2
|
---|
25 |
|
---|
26 | #define MX_NORMAL_MASK 0x3
|
---|
27 | #define MX_COLOR_MASK (0x3<<2)
|
---|
28 | #define MX_TEXTURE_MASK (0x3<<4)
|
---|
29 | #define MX_ALL_MASK (MX_NORMAL_MASK|MX_COLOR_MASK|MX_TEXTURE_MASK)
|
---|
30 |
|
---|
31 | class MxBlockModel
|
---|
32 | {
|
---|
33 | private:
|
---|
34 | unsigned char cbinding, nbinding, tbinding;
|
---|
35 |
|
---|
36 | unsigned int flags;
|
---|
37 |
|
---|
38 | // Required blocks
|
---|
39 | MxDynBlock<MxVertex> vertices;
|
---|
40 | MxDynBlock<MxFace> faces;
|
---|
41 |
|
---|
42 | // Optional blocks
|
---|
43 | MxDynBlock<MxNormal> *normals;
|
---|
44 | MxDynBlock<MxColor> *colors;
|
---|
45 | MxDynBlock<MxTexCoord> *tcoords;
|
---|
46 | // prop_block *properties; // Indirect block for arbitrary properties
|
---|
47 |
|
---|
48 | // Optional texture map
|
---|
49 | MxRaster *tex;
|
---|
50 | char *tex_name;
|
---|
51 |
|
---|
52 | protected:
|
---|
53 | virtual MxVertexID alloc_vertex(float, float, float);
|
---|
54 | virtual void init_vertex(MxVertexID) { }
|
---|
55 | virtual void free_vertex(MxVertexID) { }
|
---|
56 | virtual MxFaceID alloc_face(MxVertexID, MxVertexID, MxVertexID);
|
---|
57 | virtual void init_face(MxFaceID) { }
|
---|
58 | virtual void free_face(MxFaceID) { }
|
---|
59 |
|
---|
60 | public:
|
---|
61 | uint binding_mask;
|
---|
62 |
|
---|
63 | public:
|
---|
64 | MxBlockModel(int nvert, int nface) : vertices(nvert), faces(nface)
|
---|
65 | {
|
---|
66 | colors = NULL; normals = NULL; tcoords = NULL;
|
---|
67 | cbinding = nbinding = tbinding = MX_UNBOUND;
|
---|
68 | binding_mask = MX_ALL_MASK;
|
---|
69 | tex = NULL;
|
---|
70 | tex_name = NULL;
|
---|
71 | }
|
---|
72 | virtual ~MxBlockModel()
|
---|
73 | {
|
---|
74 | if( normals ) delete normals;
|
---|
75 | if( colors ) delete colors;
|
---|
76 | if( tcoords ) delete tcoords;
|
---|
77 | if( tex ) delete tex;
|
---|
78 | if( tex_name ) delete tex_name;
|
---|
79 | }
|
---|
80 |
|
---|
81 | unsigned int vert_count() const { return vertices.length(); }
|
---|
82 | unsigned int face_count() const { return faces.length(); }
|
---|
83 | unsigned int color_count() const { return (colors?colors->length():0); }
|
---|
84 | unsigned int normal_count() const { return (normals?normals->length():0); }
|
---|
85 | uint texcoord_count() const { return (tcoords?tcoords->length():0); }
|
---|
86 |
|
---|
87 | MxVertexID add_vertex(float, float, float);
|
---|
88 | MxFaceID add_face(uint, uint, uint, bool will_link=true);
|
---|
89 | unsigned int add_color(float, float, float);
|
---|
90 | unsigned int add_normal(float, float, float);
|
---|
91 | unsigned int add_texcoord(float, float);
|
---|
92 |
|
---|
93 | MxVertexID add_vertex(float *v) { return add_vertex(v[0], v[1], v[2]); }
|
---|
94 | MxFaceID add_face(unsigned int *f) { return add_face(f[0], f[1], f[2]); }
|
---|
95 |
|
---|
96 | void remove_vertex(MxVertexID v);
|
---|
97 | void remove_face(MxFaceID f);
|
---|
98 |
|
---|
99 | MxVertex& vertex(unsigned int i) { return vertices(i); }
|
---|
100 | MxFace& face(unsigned int i) { return faces(i); }
|
---|
101 | MxVertex& corner(MxFaceID f, short i) { return vertex(face(f)[i]); }
|
---|
102 | MxColor& color(unsigned int i) { assert(colors); return (*colors)(i); }
|
---|
103 | MxNormal& normal(unsigned int i) { assert(normals); return (*normals)(i); }
|
---|
104 | MxTexCoord& texcoord(uint i) { assert(tcoords); return (*tcoords)(i); }
|
---|
105 |
|
---|
106 | int color_binding() { return (cbinding&(binding_mask>>2)); }
|
---|
107 | int normal_binding() { return (nbinding&binding_mask); }
|
---|
108 | int texcoord_binding() { return (tbinding&(binding_mask>>4)); }
|
---|
109 | void color_binding(unsigned char b);
|
---|
110 | void normal_binding(unsigned char b);
|
---|
111 | void texcoord_binding(unsigned char b);
|
---|
112 |
|
---|
113 | const char *binding_name(int);
|
---|
114 | int parse_binding(const char *);
|
---|
115 |
|
---|
116 | MxRaster *texmap() const { return tex; }
|
---|
117 | const char *texmap_name() const { return tex_name; }
|
---|
118 | uint add_texmap(MxRaster *, const char *name);
|
---|
119 |
|
---|
120 | void compute_face_normal(MxFaceID, double *, bool will_unitize=true);
|
---|
121 | void compute_face_normal(MxFaceID, float *, bool will_unitize=true);
|
---|
122 | double compute_face_area(MxFaceID);
|
---|
123 | double compute_face_perimeter(MxFaceID, bool *edge_flags=NULL);
|
---|
124 |
|
---|
125 | double compute_corner_angle(MxFaceID, uint);
|
---|
126 | };
|
---|
127 |
|
---|
128 |
|
---|
129 | // MXBLOCKMODEL_INCLUDED
|
---|
130 | #endif
|
---|