00001 #ifndef GSGL_SG_MODEL_H 00002 #define GSGL_SG_MODEL_H 00003 00004 // 00005 // $Id: model.hpp 2 2008-03-01 20:58:50Z kulibali $ 00006 // 00007 // Copyright (c) 2008, The Periapsis Project. All rights reserved. 00008 // 00009 // Redistribution and use in source and binary forms, with or without 00010 // modification, are permitted provided that the following conditions are 00011 // met: 00012 // 00013 // * Redistributions of source code must retain the above copyright notice, 00014 // this list of conditions and the following disclaimer. 00015 // 00016 // * Redistributions in binary form must reproduce the above copyright 00017 // notice, this list of conditions and the following disclaimer in the 00018 // documentation and/or other materials provided with the distribution. 00019 // 00020 // * Neither the name of the The Periapsis Project nor the names of its 00021 // contributors may be used to endorse or promote products derived from 00022 // this software without specific prior written permission. 00023 // 00024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00025 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00026 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00027 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00028 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00030 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 // 00036 00037 #include "scenegraph/scenegraph.hpp" 00038 #include "scenegraph/node.hpp" 00039 00040 #include "platform/color.hpp" 00041 #include "platform/texture.hpp" 00042 #include "platform/shader.hpp" 00043 #include "platform/vbuffer.hpp" 00044 00045 namespace gsgl 00046 { 00047 00048 namespace scenegraph 00049 { 00050 00051 class material_impl; 00052 00053 00054 /// A material is a named material. 00055 class SCENEGRAPH_API material 00056 { 00057 material_impl *impl; 00058 00059 public: 00060 material(const gsgl::string & material_file, const gsgl::string & material_name); 00061 ~material(); 00062 00063 gsgl::string & get_name(); 00064 platform::color & get_ambient(); 00065 platform::color & get_diffuse(); 00066 platform::color & get_specular(); 00067 float & get_shininess(); 00068 bool & get_flat(); 00069 00070 platform::texture *get_texture(); 00071 platform::shader_base *get_shader(); 00072 00073 bool is_opaque(); 00074 00075 void bind(gsgl::flags_t render_flags = 0); 00076 00077 static gsgl::data_object *create_global_material_cache(); 00078 }; // class material 00079 00080 00081 ////////////////////////////////////////// 00082 00083 class submesh_node; 00084 class mesh; 00085 00086 /// A model_part is a possibly animated part of a model. 00087 /// It contains child nodes for drawing the visual parts, and meshes for collision and inertia calculation. 00088 class model_part 00089 : public scenegraph::node 00090 { 00091 submesh_node *opaque, *translucent; 00092 mesh *inertial, *collision; 00093 00094 data::list<platform::vertex_buffer *> inertial_triangles; 00095 data::list<platform::vertex_buffer *> collision_triangles; 00096 00097 public: 00098 model_part(const gsgl::data::config_record & obj_config); 00099 virtual ~model_part(); 00100 00101 data::list<platform::vertex_buffer *> & get_inertial_triangles(); 00102 data::list<platform::vertex_buffer *> & get_collision_triangles(); 00103 }; // class model_part 00104 00105 00106 /// A model is a collection of model_parts. 00107 class SCENEGRAPH_API model 00108 : public scenegraph::node 00109 { 00110 data::simple_array<model_part *> model_parts; 00111 00112 data::list<platform::vertex_buffer *> inertial_triangles; 00113 data::list<platform::vertex_buffer *> collision_triangles; 00114 00115 public: 00116 model(const gsgl::data::config_record & obj_config); 00117 virtual ~model(); 00118 00119 data::list<platform::vertex_buffer *> & get_inertial_triangles(); 00120 data::list<platform::vertex_buffer *> & get_collision_triangles(); 00121 00122 static gsgl::data_object *create_global_model_cache(); 00123 }; // class model 00124 00125 00126 } // namespace scenegraph 00127 00128 } // namespace gsgl 00129 00130 #endif