![]() |
Blender V2.61 - r43446
|
00001 /* 00002 * Copyright 2011, Blender Foundation. 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #ifndef __MESH_H__ 00020 #define __MESH_H__ 00021 00022 #include "attribute.h" 00023 #include "shader.h" 00024 00025 #include "util_boundbox.h" 00026 #include "util_list.h" 00027 #include "util_map.h" 00028 #include "util_param.h" 00029 #include "util_transform.h" 00030 #include "util_types.h" 00031 #include "util_vector.h" 00032 00033 CCL_NAMESPACE_BEGIN 00034 00035 class BVH; 00036 class Device; 00037 class DeviceScene; 00038 class Mesh; 00039 class Progress; 00040 class Scene; 00041 class SceneParams; 00042 class AttributeRequest; 00043 00044 /* Mesh */ 00045 00046 class Mesh { 00047 public: 00048 /* Mesh Triangle */ 00049 struct Triangle { 00050 int v[3]; 00051 }; 00052 00053 /* Displacement */ 00054 enum DisplacementMethod { 00055 DISPLACE_BUMP, 00056 DISPLACE_TRUE, 00057 DISPLACE_BOTH 00058 }; 00059 00060 ustring name; 00061 00062 /* Mesh Data */ 00063 vector<float3> verts; 00064 vector<Triangle> triangles; 00065 vector<uint> shader; 00066 vector<bool> smooth; 00067 00068 vector<uint> used_shaders; 00069 AttributeSet attributes; 00070 00071 BoundBox bounds; 00072 bool transform_applied; 00073 bool transform_negative_scaled; 00074 DisplacementMethod displacement_method; 00075 00076 /* Update Flags */ 00077 bool need_update; 00078 bool need_update_rebuild; 00079 00080 /* BVH */ 00081 BVH *bvh; 00082 size_t tri_offset; 00083 size_t vert_offset; 00084 00085 /* Functions */ 00086 Mesh(); 00087 ~Mesh(); 00088 00089 void reserve(int numverts, int numfaces); 00090 void clear(); 00091 void add_triangle(int v0, int v1, int v2, int shader, bool smooth); 00092 00093 void compute_bounds(); 00094 void add_face_normals(); 00095 void add_vertex_normals(); 00096 00097 void pack_normals(Scene *scene, float4 *normal, float4 *vnormal); 00098 void pack_verts(float4 *tri_verts, float4 *tri_vindex, size_t vert_offset); 00099 void compute_bvh(SceneParams *params, Progress& progress); 00100 00101 void tag_update(Scene *scene, bool rebuild); 00102 }; 00103 00104 /* Mesh Manager */ 00105 00106 class MeshManager { 00107 public: 00108 BVH *bvh; 00109 00110 bool need_update; 00111 00112 MeshManager(); 00113 ~MeshManager(); 00114 00115 bool displace(Device *device, Scene *scene, Mesh *mesh, Progress& progress); 00116 00117 /* attributes */ 00118 void update_osl_attributes(Device *device, Scene *scene, vector<AttributeRequestSet>& mesh_attributes); 00119 void update_svm_attributes(Device *device, DeviceScene *dscene, Scene *scene, vector<AttributeRequestSet>& mesh_attributes); 00120 00121 void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); 00122 void device_update_object(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); 00123 void device_update_mesh(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); 00124 void device_update_attributes(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); 00125 void device_update_bvh(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); 00126 void device_free(Device *device, DeviceScene *dscene); 00127 00128 void tag_update(Scene *scene); 00129 }; 00130 00131 CCL_NAMESPACE_END 00132 00133 #endif /* __MESH_H__ */ 00134