Oolite
Loading...
Searching...
No Matches
OOMesh.h
Go to the documentation of this file.
1/*
2
3OOMesh.h
4
5Standard OODrawable for static meshes from DAT files. OOMeshes are immutable
6(and can therefore be shared). Avoid the temptation to add externally-visible
7mutator methods as it will break such sharing. (Sharing will be implemented
8when ship types are turned into objects instead of dictionaries; this is
9currently slated for post-1.70. -- Ahruman)
10
11Hmm. On further consideration, sharing will be problematic because of material
12bindings. Two possible solutions: separate mesh data into shared object with
13each mesh instance having its own set of materials but shared data, or
14retarget bindings each frame. -- Ahruman
15
16
17Oolite
18Copyright (C) 2004-2013 Giles C Williams and contributors
19
20This program is free software; you can redistribute it and/or
21modify it under the terms of the GNU General Public License
22as published by the Free Software Foundation; either version 2
23of the License, or (at your option) any later version.
24
25This program is distributed in the hope that it will be useful,
26but WITHOUT ANY WARRANTY; without even the implied warranty of
27MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28GNU General Public License for more details.
29
30You should have received a copy of the GNU General Public License
31along with this program; if not, write to the Free Software
32Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
33MA 02110-1301, USA.
34
35*/
36
37#import "OODrawable.h"
38#import "OOOpenGL.h"
40#import "OOWeakReference.h"
41
42@class OOMaterial, Octree;
43
44#define OOMESH_PROFILE 0
45#if OOMESH_PROFILE
47#endif
48
49enum {
51};
52
53typedef uint16_t OOMeshSmoothGroup;
55typedef uint32_t OOMeshVertexCount;
56typedef uint32_t OOMeshFaceCount;
57typedef uint8_t OOMeshFaceVertexCount;
58
70
81
82@interface OOMesh : OODrawable <NSCopying> {
83@private
84 uint8_t _normalMode : 2,
87
91
92 NSString* baseFile;
95
100
101 // Redundancy! Needs fixing.
103
104 NSRange triangle_range[kOOMeshMaxMaterials];
105 NSString* materialKeys[kOOMeshMaxMaterials];
106 OOMaterial* materials[kOOMeshMaxMaterials];
108
109 GLfloat collisionRadius;
110 GLfloat maxDrawDistance;
112
113 Octree* octree;
114
115 NSMutableDictionary* _retainedObjects;
116
117 NSDictionary* _materialDict;
118 NSDictionary* _shadersDict;
119 NSString* _cacheKey;
120 NSDictionary* _shaderMacros;
122
126
127#if OO_MULTITEXTURE
128 NSUInteger _textureUnitCount;
129#endif
130
131#if OOMESH_PROFILE
132 OOProfilingStopwatch* _stopwatch;
133 double _stopwatchLastTime;
134#endif
135}
136
137+ (instancetype)meshWithName:(NSString*)name
138 cacheKey:(NSString*)cacheKey
139 materialDictionary:(NSDictionary*)materialDict
140 shadersDictionary:(NSDictionary*)shadersDict
141 smooth:(BOOL)smooth
142 shaderMacros:(NSDictionary*)macros
143 shaderBindingTarget:(id<OOWeakReferenceSupport>)object;
144
145+ (instancetype)meshWithName:(NSString*)name
146 cacheKey:(NSString*)cacheKey
147 materialDictionary:(NSDictionary*)materialDict
148 shadersDictionary:(NSDictionary*)shadersDict
149 smooth:(BOOL)smooth
150 shaderMacros:(NSDictionary*)macros
151 shaderBindingTarget:(id<OOWeakReferenceSupport>)object
152 scaleFactor:(float)factor
153 cacheWriteable:(BOOL)cacheWriteable;
154
155+ (OOMaterial*)placeholderMaterial;
156
157- (NSString*)modelName;
158
159- (void)rebindMaterials;
160
161- (NSDictionary*)materials;
162- (NSDictionary*)shaders;
163
164- (size_t)vertexCount;
165- (size_t)faceCount;
166
168
169// This needs a better name.
170- (BoundingBox)findBoundingBoxRelativeToPosition:(Vector)opv
171 ri:(Vector)ri
172 rj:(Vector)rj
173 rk:(Vector)rk
174 selfPosition:(Vector)position
175 si:(Vector)si
176 sj:(Vector)sj
177 sk:(Vector)sk;
178- (BoundingBox)findSubentityBoundingBoxWithPosition:(Vector)position rotMatrix:(OOMatrix)rotMatrix;
179
180- (OOMesh*)meshRescaledBy:(GLfloat)scaleFactor;
181
182@end
183
184#import "OOCacheManager.h"
185@interface OOCacheManager (Octree)
186
187+ (Octree*)octreeForModel:(NSString*)inKey;
188+ (void)setOctree:(Octree*)inOctree forModel:(NSString*)inKey;
189
190@end
uint8_t OOMeshFaceVertexCount
Definition OOMesh.h:57
@ kOOMeshMaxMaterials
Definition OOMesh.h:50
uint16_t OOMeshSmoothGroup
Definition OOMesh.h:53
uint32_t OOMeshFaceCount
Definition OOMesh.h:56
uint32_t OOMeshVertexCount
Definition OOMesh.h:55
uint8_t OOMeshMaterialIndex
Definition OOMesh.h:54
uint8_t OOMeshMaterialCount
Definition OOMesh.h:54
Vector * _vertices
Definition OOMesh.h:96
NSDictionary * shaders()
Definition OOMesh.m:570
NSMutableDictionary * _retainedObjects
Definition OOMesh.h:115
NSDictionary * _shaderMacros
Definition OOMesh.h:120
uint8_t brokenInRender
Definition OOMesh.h:85
OOMaterial * materials[kOOMeshMaxMaterials]
Definition OOMesh.m:565
id _shaderBindingTarget
Definition OOMesh.h:121
GLfloat maxDrawDistance
Definition OOMesh.m:585
NSString * materialKeys[kOOMeshMaxMaterials]
Definition OOMesh.h:105
Octree * octree
Definition OOMesh.m:631
GLuint displayList0
Definition OOMesh.h:107
uint8_t listsReady
Definition OOMesh.h:86
OOMeshFace * _faces
Definition OOMesh.h:99
uint8_t _normalMode
Definition OOMesh.h:84
OOMeshMaterialCount materialCount
Definition OOMesh.h:88
NSRange triangle_range[kOOMeshMaxMaterials]
Definition OOMesh.h:104
Vector _lastPosition
Definition OOMesh.h:123
Vector * _tangents
Definition OOMesh.h:98
NSString * _cacheKey
Definition OOMesh.h:119
BoundingBox _lastBoundingBox
Definition OOMesh.h:125
BOOL _cacheWriteable
Definition OOMesh.h:94
NSDictionary * _materialDict
Definition OOMesh.h:117
NSDictionary * _shadersDict
Definition OOMesh.h:118
BoundingBox boundingBox
Definition OOMesh.h:111
NSString * baseFileOctreeCacheRef
Definition OOMesh.h:93
NSString * baseFile
Definition OOMesh.h:92
OOMeshVertexCount vertexCount
Definition OOMesh.m:358
OOMatrix _lastRotMatrix
Definition OOMesh.h:124
Vector * _normals
Definition OOMesh.h:97
OOMeshDisplayLists _displayLists
Definition OOMesh.h:102
GLfloat collisionRadius
Definition OOMesh.m:580
OOMeshFaceCount faceCount
Definition OOMesh.m:363
Vector * tangentArray
Definition OOMesh.h:77
GLint * indexArray
Definition OOMesh.h:73
Vector * vertexArray
Definition OOMesh.h:75
GLfloat * textureUVArray
Definition OOMesh.h:74
Vector * normalArray
Definition OOMesh.h:76
Vector tangent
Definition OOMesh.h:66
GLuint vertex[3]
Definition OOMesh.h:63
Vector normal
Definition OOMesh.h:65
OOMeshSmoothGroup smoothGroup
Definition OOMesh.h:61
GLfloat t[3]
Definition OOMesh.h:68
OOMeshMaterialIndex materialIndex
Definition OOMesh.h:62
GLfloat s[3]
Definition OOMesh.h:67