-
Notifications
You must be signed in to change notification settings - Fork 3
/
models.pas
201 lines (182 loc) · 4.43 KB
/
models.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//------------------------------------------------------------------------------
//
// Voxelizer
// Copyright (C) 2021 by Jim Valavanis
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
// DESCRIPTION:
// Base model class
//
//------------------------------------------------------------------------------
// Site : https://sourceforge.net/projects/voxelizer/
//------------------------------------------------------------------------------
unit models;
interface
type
fvec5_t = record
x, y, z, u, v: single;
end;
fvec5_p = ^fvec5_t;
fvec5_a = array[0..$FFFF] of fvec5_t;
fvec5_pa = ^fvec5_a;
ivec3_t = record
x, y, z: integer;
end;
ivec3_p = ^ivec3_t;
ivec3_a = array[0..$FFFF] of ivec3_t;
ivec3_pa = ^ivec3_a;
type
model_t = class
public
mVertCount: integer;
mFaceCount: integer;
mVert: array of fvec5_t;
mFace: array of ivec3_t;
mFrame: Integer;
constructor Create; virtual;
destructor Destroy; override;
procedure init;
function AddVert(const x, y, z, u, v: single): integer;
function maxcoord: single;
function maxdiameter: single;
end;
implementation
constructor model_t.Create;
begin
SetLength(mVert, 0);
SetLength(mFace, 0);
mVertCount := 0;
mFaceCount := 0;
mFrame := 0;
end;
destructor model_t.Destroy;
begin
SetLength(mVert, 0);
SetLength(mFace, 0);
end;
const
EPSILON = 0.000001;
function model_t.AddVert(const x, y, z, u, v: single): integer;
var
i: integer;
begin
for i := 0 to mVertCount - 1 do
if abs(x - mVert[i].x) < EPSILON then
if abs(y - mVert[i].y) < EPSILON then
if abs(z - mVert[i].z) < EPSILON then
begin
Result := i;
Exit;
end;
Result := mVertCount;
inc(mVertCount);
SetLength(mVert, mVertCount);
mVert[Result].x := x;
mVert[Result].y := y;
mVert[Result].z := z;
mVert[Result].u := u;
mVert[Result].v := v;
end;
procedure model_t.init;
begin
SetLength(mVert, 0);
SetLength(mFace, 0);
mVertCount := 0;
mFaceCount := 0;
mFrame := 0;
end;
function model_t.maxcoord: single;
var
minx, maxx, miny, maxy, minz, maxz: single;
i: integer;
begin
minx := 100000.0;
maxx := -100000.0;
miny := 100000.0;
maxy := -100000.0;
minz := 100000.0;
maxz := -100000.0;
for i := 0 to mVertCount - 1 do
begin
if mVert[i].x < minx then
minx := mVert[i].x;
if mVert[i].x > maxx then
maxx := mVert[i].x;
if mVert[i].y < miny then
miny := mVert[i].y;
if mVert[i].y > maxy then
maxy := mVert[i].y;
if mVert[i].z < minz then
minz := mVert[i].z;
if mVert[i].z > maxz then
maxz := mVert[i].z;
end;
minx := abs(minx);
maxx := abs(maxx);
miny := abs(miny);
maxy := abs(maxy);
minz := abs(minz);
maxz := abs(maxz);
Result := minx;
if maxx > Result then
Result := maxx;
if miny > Result then
Result := miny;
if maxy > Result then
Result := maxy;
if minz > Result then
Result := minz;
if maxz > Result then
Result := maxz;
end;
function model_t.maxdiameter: single;
var
minx, maxx, miny, maxy, minz, maxz: single;
dx, dy, dz: single;
i: integer;
begin
minx := 100000.0;
maxx := -100000.0;
miny := 100000.0;
maxy := -100000.0;
minz := 100000.0;
maxz := -100000.0;
for i := 0 to mVertCount - 1 do
begin
if mVert[i].x < minx then
minx := mVert[i].x;
if mVert[i].x > maxx then
maxx := mVert[i].x;
if mVert[i].y < miny then
miny := mVert[i].y;
if mVert[i].y > maxy then
maxy := mVert[i].y;
if mVert[i].z < minz then
minz := mVert[i].z;
if mVert[i].z > maxz then
maxz := mVert[i].z;
end;
dx := maxx - minx;
dy := maxy - miny;
dz := maxz - minz;
Result := dx;
if dy > Result then
Result := dy;
if dz > Result then
Result := dz;
end;
end.