22 #if defined(_DEBUG) && defined(_WINDOWS)
23 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
30 : lower_bound(0, 0, 0),
43 void Model_Renderer::create_vertex_buffer(Vertex_Buffer *
const &user_p,
const Model &model,
Lib3dsMeshInstanceNode *
const &node,
Lib3dsMesh *
const &mesh) {
49 user_p->do_normal_alignment(model.will_do_normal_alignment());
52 ~l3dsv() {
free(normals);}
54 } ptr = {(float(*)[3])
malloc(
sizeof(
float) * 9 * mesh->
nfaces)};
55 float (*normal)[3] = ptr.normals;
64 const bool flip_order = scl_track.i * scl_track.j * scl_track.k < 0.0f;
68 for(
unsigned int i = 0;
i < mesh->
nfaces; ++
i) {
73 material = model.thun_get_file()->materials[face->
material];
75 throw Model_Render_Failure();
79 bool textured =
false;
86 mat.ambient.a = opacity;
87 mat.diffuse.a = opacity;
96 mat.emissive = Color(opacity, 0.0
f, 0.0
f, 0.0
f).interpolate_to(material->
self_illum, mat.diffuse);
109 Vector3f na(normal[0][0], normal[0][1], normal[0][2]);
110 Vector3f nb(normal[1][0], normal[1][1], normal[1][2]);
111 Vector3f nc(normal[2][0], normal[2][1], normal[2][2]);
123 Point2f ta(0.5
f - tex_scale.x * (tex_offset.x - mesh->
texcos[face->
index[0]][0]), 0.5f - tex_scale.y * (tex_offset.y + mesh->
texcos[face->
index[0]][1]));
124 const Point2f tb(0.5
f - tex_scale.x * (tex_offset.x - mesh->
texcos[face->
index[1]][0]), 0.5f - tex_scale.y * (tex_offset.y + mesh->
texcos[face->
index[1]][1]));
125 Point2f
tc(0.5
f - tex_scale.x * (tex_offset.x - mesh->
texcos[face->
index[2]][0]), 0.5f - tex_scale.y * (tex_offset.y + mesh->
texcos[face->
index[2]][1]));
130 Triangle<Vertex3f_Texture> triangle(Vertex3f_Texture(pa, na, ta),
131 Vertex3f_Texture(pb, nb, tb),
132 Vertex3f_Texture(pc, nc,
tc));
133 triangle.fax_Material(&mat);
135 user_p->fax_Triangle(&triangle);
138 const Uint32 argb = mat.diffuse.get_argb();
140 Triangle<Vertex3f_Color> triangle(Vertex3f_Color(pa, na, argb),
141 Vertex3f_Color(pb, nb, argb),
142 Vertex3f_Color(pc, nc, argb));
143 triangle.fax_Material(&mat);
145 user_p->fax_Triangle(&triangle);
153 class Model_Unrenderer :
public Model_Visitor {
162 Vertex_Buffer *user_p =
reinterpret_cast<Vertex_Buffer *
>(mesh->
user_ptr);
170 #pragma warning( push )
171 #pragma warning( disable : 4355 )
174 : m_filename(filename),
177 m_align_normals(align_normals_),
179 m_scale(1.0
f, 1.0
f, 1.0
f),
180 m_rotate(0.0
f, 0.0
f, 1.0
f),
181 m_translate(0.0
f, 0.0
f, 0.0
f),
190 : m_filename(rhs.m_filename),
192 m_keyframe(rhs.m_keyframe),
193 m_align_normals(rhs.m_align_normals),
195 m_scale(rhs.m_scale),
196 m_rotate(rhs.m_rotate),
197 m_translate(rhs.m_translate),
198 m_rotate_angle(rhs.m_rotate_angle)
205 #pragma warning( pop )
222 lhs =
new Model(rhs);
230 std::swap(m_unrenderer, lhs->m_unrenderer);
233 std::swap(m_translate, lhs->m_translate);
234 std::swap(m_rotate_angle, lhs->m_rotate_angle);
256 return float(m_file->
frames);
262 m_keyframe = keyframe;
269 for(node=m_file->
nodes; node; node=node->
next)
284 for(node = m_file->
nodes; node; node = node->
next)
308 strcmp(node->
name,
"$$$DUMMY"))
315 mv(*
this, reinterpret_cast<Lib3dsMeshInstanceNode * const>(node), node_mesh);
323 m_unrenderer =
new Model_Unrenderer();
346 create_vertex_buffer(
new Vertex_Buffer(), model, node, mesh);
371 float (&point)[3] = *vertex;
An Abstraction of a 3D Model.
The Video Rendering Singleton.
Point3f get_position() const
Get the position of the Model.
virtual void scale_scene(const Vector3f &factor)=0
Scale the scene.
static Quaternion Axis_Angle(const Vector3f &v, const float &theta)
Create a Quaternion from an Axis/Angle pair.
Lib3dsTextureMap texture1_map
void visit_meshes(Model_Visitor &mv, Lib3dsNode *node=0, Lib3dsMesh *const &mesh=0) const
Visit all meshes.
const char * c_str() const
Vector3f multiply_by(const Vector3f &rhs) const
Multiply corresponding members.
LIB3DSAPI int lib3ds_file_mesh_by_name(Lib3dsFile *file, const char *name)
virtual void operator()(const Model &, Lib3dsNode *const &)
virtual void transform_scene(const Matrix4f &transformation)=0
Transform the scene.
LIB3DSAPI void lib3ds_file_eval(Lib3dsFile *file, float t)
LIB3DSAPI void lib3ds_file_free(Lib3dsFile *file)
float get_keyframes() const
Get the number of keyframes; may be higher than you expect.
A 3D Point represented with floats.
uint32_t Uint32
An unsigned 32-bit integer type.
void set_keyframe(const float &keyframe)
Set the current (key)frame; interpolation is automatic.
A Featureful 3-Space Vector Class.
Model(const String &filename, const bool align_normals_=false)
The only way to create a Model.
virtual void pop_world_stack()=0
Pop a model view matrix off the stack.
virtual void rotate_scene(const Vector3f &about, const float &radians)=0
Rotate the scene.
void visit_nodes(Model_Visitor &mv, Lib3dsNode *node=0) const
Visit all nodes.
A Vertex_Buffer that accepts Triangle and Quadrilaterals.
virtual void push_world_stack()=0
Push a model view matrix onto the stack.
virtual void operator()(const Model &model, Lib3dsMeshInstanceNode *const &node, Lib3dsMesh *const &mesh)
virtual void translate_scene(const Vector3f &direction)=0
Translate the scene.
struct Lib3dsNode * childs
LIB3DSAPI void lib3ds_mesh_calculate_vertex_normals(Lib3dsMesh *mesh, float(*normals)[3])
void swap(Zeni::String &lhs, Zeni::String &rhs)
void render()
Render the Vertex_Buffer.
LIB3DSAPI Lib3dsFile * lib3ds_file_open(const char *filename)
Point3f upper_bound
The bounding box of model, first frame only if animated.
Video & get_Video()
Get access to the singleton.
Point3f interpolate_to(const float &rhs_part, const Point3f &rhs) const
Model & operator=(const Model &rhs)