35 _converter(converter),
39 _rgb.set(1.0, 1.0, 1.0);
40 _checked_material =
false;
41 _checked_texture =
false;
46 int num_chunks = _surface->get_num_chunks();
47 for (
int i = 0; i < num_chunks; i++) {
48 const IffChunk *chunk = _surface->get_chunk(i);
50 if (chunk->
is_of_type(LwoSurfaceColor::get_class_type())) {
55 }
else if (chunk->
is_of_type(LwoSurfaceParameter::get_class_type())) {
59 if (type ==
IffId(
"DIFF")) {
61 _diffuse = param->_value;
63 }
else if (type ==
IffId(
"LUMI")) {
64 _flags |= F_luminosity;
65 _luminosity = param->_value;
67 }
else if (type ==
IffId(
"SPEC")) {
69 _specular = param->_value;
71 }
else if (type ==
IffId(
"REFL")) {
72 _flags |= F_reflection;
73 _reflection = param->_value;
75 }
else if (type ==
IffId(
"TRAN")) {
76 _flags |= F_transparency;
77 _transparency = param->_value;
79 }
else if (type ==
IffId(
"GLOS")) {
81 _gloss = param->_value;
83 }
else if (type ==
IffId(
"TRNL")) {
84 _flags |= F_translucency;
85 _translucency = param->_value;
88 }
else if (chunk->
is_of_type(LwoSurfaceSmoothingAngle::get_class_type())) {
90 _flags |= F_smooth_angle;
91 _smooth_angle = sa->_angle;
93 }
else if (chunk->
is_of_type(LwoSurfaceSidedness::get_class_type())) {
96 _backface = (sn->_sidedness == LwoSurfaceSidedness::S_front_and_back);
98 }
else if (chunk->
is_of_type(LwoSurfaceBlock::get_class_type())) {
106 if (block->_block_type ==
IffId(
"IMAP") &&
107 block->_channel_id ==
IffId(
"COLR") &&
110 if (_block ==
nullptr) {
113 }
else if (block->_ordinal < _block->_ordinal) {
129 _color.set(1.0, 1.0, 1.0, 1.0);
131 if ((_flags & F_rgb) != 0) {
137 if ((_flags & F_transparency) != 0) {
138 _color[3] = 1.0 - _transparency;
141 _diffuse_color = _color;
149 if (_block !=
nullptr) {
163 PN_stdfloat &smooth_angle) {
164 if (!_surface->_source.empty()) {
167 if (parent !=
nullptr && parent !=
this) {
175 egg_prim->set_color(_diffuse_color);
185 generate_uvs(egg_vertices);
188 if ((_flags & F_backface) != 0) {
192 if ((_flags & F_smooth_angle) != 0) {
193 smooth_angle = std::max(smooth_angle, _smooth_angle);
206 if (_checked_texture) {
207 return (_egg_texture !=
nullptr);
209 _checked_texture =
true;
210 _egg_texture =
nullptr;
213 if (_block ==
nullptr) {
218 int clip_index = _block->_clip_index;
219 if (clip_index < 0) {
225 if (clip ==
nullptr) {
226 nout <<
"No clip image with index " << clip_index <<
"\n";
237 _egg_texture =
new EggTexture(
"clip" + format_string(clip_index), pathname);
240 switch (_block->_projection_mode) {
241 case LwoSurfaceBlockProjection::M_planar:
242 _map_uvs = &CLwoSurface::map_planar;
245 case LwoSurfaceBlockProjection::M_cylindrical:
246 _map_uvs = &CLwoSurface::map_cylindrical;
249 case LwoSurfaceBlockProjection::M_spherical:
250 _map_uvs = &CLwoSurface::map_spherical;
253 case LwoSurfaceBlockProjection::M_cubic:
254 _map_uvs = &CLwoSurface::map_cubic;
257 case LwoSurfaceBlockProjection::M_front:
262 case LwoSurfaceBlockProjection::M_uv:
283 if (_checked_material) {
284 return (_egg_material !=
nullptr);
286 _checked_material =
true;
287 _egg_material =
nullptr;
289 if (!_converter->_make_materials) {
296 if ((_flags & F_diffuse) != 0) {
297 _diffuse_color.set(_color[0] * _diffuse,
298 _color[1] * _diffuse,
299 _color[2] * _diffuse,
309 if ((_flags & F_luminosity) != 0) {
310 LColor luminosity(_color[0] * _luminosity,
311 _color[1] * _luminosity,
312 _color[2] * _luminosity,
314 _egg_material->set_emit(luminosity);
317 if ((_flags & F_specular) != 0) {
318 LColor specular(_color[0] * _specular,
319 _color[1] * _specular,
320 _color[2] * _specular,
322 _egg_material->set_spec(specular);
325 if ((_flags & F_gloss) != 0) {
326 _egg_material->set_shininess(_gloss * 128.0);
338 generate_uvs(vector_PT_EggVertex &egg_vertices) {
339 if (_map_uvs ==
nullptr) {
346 LPoint3d centroid(0.0, 0.0, 0.0);
348 vector_PT_EggVertex::const_iterator vi;
349 for (vi = egg_vertices.begin(); vi != egg_vertices.end(); ++vi) {
354 centroid /= (double)egg_vertices.size();
355 centroid = centroid * _block->_inv_transform;
358 for (vi = egg_vertices.begin(); vi != egg_vertices.end(); ++vi) {
360 LPoint3d pos = egg_vertex->
get_pos3() * _block->_inv_transform;
361 LPoint2d uv = (this->*_map_uvs)(pos, centroid);
369 LPoint2d CLwoSurface::
370 map_planar(
const LPoint3d &pos,
const LPoint3d &)
const {
373 double u = (pos[0] + 0.5);
374 double v = (pos[2] + 0.5);
376 return LPoint2d(u, v);
383 LPoint2d CLwoSurface::
384 map_spherical(
const LPoint3d &pos,
const LPoint3d ¢roid)
const {
389 LVector2d xz_orig(pos[0], pos[2]);
390 LVector2d xz = xz_orig;
391 double u_offset = 0.0;
393 if (xz == LVector2d::zero()) {
400 xz.set(centroid[0], centroid[2]);
402 }
else if (xz[1] >= 0.0 && ((xz[0] < 0.0) != (centroid[0] < 0.))) {
409 u_offset = (xz[0] < 0.0) ? 1.0 : -1.0;
414 (atan2(xz[0], -xz[1]) / (2.0 * MathNumbers::pi) + 0.5 + u_offset) * _block->_w_repeat;
418 LVector2d yz(pos[1], xz_orig.length());
420 (atan2(yz[0], yz[1]) / MathNumbers::pi + 0.5) * _block->_h_repeat;
422 return LPoint2d(u, v);
429 LPoint2d CLwoSurface::
430 map_cylindrical(
const LPoint3d &pos,
const LPoint3d ¢roid)
const {
434 LVector2d xz(pos[0], pos[2]);
435 double u_offset = 0.0;
437 if (xz == LVector2d::zero()) {
442 xz.set(centroid[0], centroid[2]);
444 }
else if (xz[1] >= 0.0 && ((xz[0] < 0.0) != (centroid[0] < 0.))) {
446 u_offset = (xz[0] < 0.0) ? 1.0 : -1.0;
450 (atan2(xz[0], -xz[1]) / (2.0 * MathNumbers::pi) + 0.5 + u_offset) * _block->_w_repeat;
454 double v = (pos[1] + 0.5);
456 return LPoint2d(u, v);
462 LPoint2d CLwoSurface::
463 map_cubic(
const LPoint3d &pos,
const LPoint3d ¢roid)
const {
468 double x = fabs(centroid[0]);
469 double y = fabs(centroid[1]);
470 double z = fabs(centroid[2]);
496 return LPoint2d(u, v);