Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Skin.cpp
Go to the documentation of this file.
1
/* Project nGenEx
2
Destroyer Studios LLC
3
Copyright © 1997-2004. All Rights Reserved.
4
5
SUBSYSTEM: nGenEx.lib
6
FILE: Skin.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Classes for rendering solid meshes of polygons
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
Skin.h
"
17
#include "
Solid.h
"
18
19
void
Print
(
const
char
* fmt, ...);
20
21
// +--------------------------------------------------------------------+
22
23
Skin::Skin
(
const
char
* n)
24
{
25
if
(n && *n) {
26
strncpy_s(
name
, n,
NAMELEN
);
27
name
[
NAMELEN
-1] = 0;
28
}
29
30
else
{
31
ZeroMemory(
name
,
NAMELEN
);
32
}
33
34
ZeroMemory(
path
, 256);
35
}
36
37
// +--------------------------------------------------------------------+
38
39
Skin::~Skin
()
40
{
41
cells
.
destroy
();
42
}
43
44
// +--------------------------------------------------------------------+
45
46
void
47
Skin::SetName
(
const
char
* n)
48
{
49
if
(n && *n) {
50
strncpy_s(
name
, n,
NAMELEN
);
51
name
[
NAMELEN
-1] = 0;
52
}
53
}
54
55
void
56
Skin::SetPath
(
const
char
* n)
57
{
58
if
(n && *n) {
59
strncpy_s(
path
, n, 256);
60
path
[255] = 0;
61
}
62
63
else
{
64
ZeroMemory(
path
, 256);
65
}
66
}
67
68
// +--------------------------------------------------------------------+
69
70
void
71
Skin::AddMaterial
(
const
Material
* mtl)
72
{
73
if
(!mtl)
return
;
74
75
bool
found =
false
;
76
77
ListIter<SkinCell>
iter =
cells
;
78
while
(++iter && !found) {
79
SkinCell
* s = iter.
value
();
80
81
if
(s->skin && !strcmp(s->skin->
name
, mtl->
name
)) {
82
s->skin = mtl;
83
found =
true
;
84
}
85
}
86
87
if
(!found) {
88
SkinCell
* s =
new
(__FILE__,__LINE__)
SkinCell
(mtl);
89
cells
.
append
(s);
90
}
91
}
92
93
// +--------------------------------------------------------------------+
94
95
void
96
Skin::ApplyTo
(
Model
* model)
const
97
{
98
if
(model) {
99
for
(
int
i = 0; i <
cells
.
size
(); i++) {
100
SkinCell
* s =
cells
[i];
101
102
if
(s->skin) {
103
s->orig = model->
ReplaceMaterial
(s->skin);
104
}
105
}
106
}
107
}
108
109
void
110
Skin::Restore
(
Model
* model)
const
111
{
112
if
(model) {
113
for
(
int
i = 0; i <
cells
.
size
(); i++) {
114
SkinCell
* s =
cells
[i];
115
116
if
(s->orig) {
117
model->
ReplaceMaterial
(s->orig);
118
s->orig = 0;
119
}
120
}
121
}
122
}
123
124
// +--------------------------------------------------------------------+
125
// +--------------------------------------------------------------------+
126
// +--------------------------------------------------------------------+
127
128
SkinCell::SkinCell
(
const
Material
* mtl)
129
: skin(mtl), orig(0)
130
{
131
}
132
133
SkinCell::~SkinCell
()
134
{
135
delete
skin;
136
}
137
138
// +--------------------------------------------------------------------+
139
140
int
141
SkinCell::operator ==
(
const
SkinCell
& other)
const
142
{
143
if
(skin == other.skin)
144
return
true
;
145
146
if
(skin && other.skin)
147
return
!strcmp(skin->
name
, other.skin->
name
);
148
149
return
false
;
150
}
151
152
// +--------------------------------------------------------------------+
153
154
const
char
*
155
SkinCell::Name
()
const
156
{
157
if
(skin)
158
return
skin->
name
;
159
160
return
"Invalid Skin Cell"
;
161
}
162
163
// +--------------------------------------------------------------------+
164
165
void
166
SkinCell::SetSkin
(
const
Material
* mtl)
167
{
168
skin = mtl;
169
}
170
171
void
172
SkinCell::SetOrig
(
const
Material
* mtl)
173
{
174
orig = mtl;
175
}
nGenEx
Skin.cpp
Generated on Thu May 31 2012 16:30:58 for Starshatter_Open by
1.8.1