Oolite 1.91.0.7604-240417-a536cbe
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"
39#import "OOWeakReference.h"
41
42@class OOMaterial, Octree;
43
44
45#define OOMESH_PROFILE 0
46#if OOMESH_PROFILE
48#endif
49
50
51enum
52{
54};
55
56
57typedef uint16_t OOMeshSmoothGroup;
59typedef uint32_t OOMeshVertexCount;
60typedef uint32_t OOMeshFaceCount;
61typedef uint8_t OOMeshFaceVertexCount;
62
63
64typedef struct
65{
68 GLuint vertex[3];
69
70 Vector normal;
71 Vector tangent;
72 GLfloat s[3];
73 GLfloat t[3];
75
76
77typedef struct
78{
79 GLint *indexArray;
81 Vector *vertexArray;
82 Vector *normalArray;
83 Vector *tangentArray;
84
85 GLuint count;
87
88
89@interface OOMesh: OODrawable <NSCopying>
90{
91@private
92 uint8_t _normalMode: 2,
100 NSString *baseFile;
104 Vector *_vertices;
105 Vector *_normals;
106 Vector *_tangents;
109 // Redundancy! Needs fixing.
112 NSRange triangle_range[kOOMeshMaxMaterials];
113 NSString *materialKeys[kOOMeshMaxMaterials];
114 OOMaterial *materials[kOOMeshMaxMaterials];
117 GLfloat collisionRadius;
119 BoundingBox boundingBox;
121 Octree *octree;
123 NSMutableDictionary *_retainedObjects;
125 NSDictionary *_materialDict;
126 NSDictionary *_shadersDict;
127 NSString *_cacheKey;
128 NSDictionary *_shaderMacros;
131 Vector _lastPosition;
133 BoundingBox _lastBoundingBox;
135#if OO_MULTITEXTURE
136 NSUInteger _textureUnitCount;
137#endif
138
139#if OOMESH_PROFILE
140 OOProfilingStopwatch *_stopwatch;
141 double _stopwatchLastTime;
142#endif
143}
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
153+ (instancetype) meshWithName:(NSString *)name
154 cacheKey:(NSString *)cacheKey
155 materialDictionary:(NSDictionary *)materialDict
156 shadersDictionary:(NSDictionary *)shadersDict
157 smooth:(BOOL)smooth
158 shaderMacros:(NSDictionary *)macros
159 shaderBindingTarget:(id<OOWeakReferenceSupport>)object
160 scaleFactor:(float)factor
161 cacheWriteable:(BOOL)cacheWriteable;
162
163
164+ (OOMaterial *) placeholderMaterial;
165
166- (NSString *) modelName;
167
168- (void) rebindMaterials;
169
170- (NSDictionary *) materials;
171- (NSDictionary *) shaders;
172
173- (size_t) vertexCount;
174- (size_t) faceCount;
175
176- (Octree *) octree;
177
178// This needs a better name.
179- (BoundingBox) findBoundingBoxRelativeToPosition:(Vector)opv
180 basis:(Vector)ri :(Vector)rj :(Vector)rk
181 selfPosition:(Vector)position
182 selfBasis:(Vector)si :(Vector)sj :(Vector)sk;
183- (BoundingBox) findSubentityBoundingBoxWithPosition:(Vector)position rotMatrix:(OOMatrix)rotMatrix;
184
185- (OOMesh *) meshRescaledBy:(GLfloat)scaleFactor;
186
187@end
188
189
190#import "OOCacheManager.h"
191@interface OOCacheManager (Octree)
193+ (Octree *)octreeForModel:(NSString *)inKey;
194+ (void)setOctree:(Octree *)inOctree forModel:(NSString *)inKey;
195
196@end
@ kOOMeshMaxMaterials
Definition OOMesh.h:53
uint8_t OOMeshFaceVertexCount
Definition OOMesh.h:61
uint16_t OOMeshSmoothGroup
Definition OOMesh.h:57
uint32_t OOMeshFaceCount
Definition OOMesh.h:60
uint32_t OOMeshVertexCount
Definition OOMesh.h:59
uint8_t OOMeshMaterialIndex
Definition OOMesh.h:58
uint8_t OOMeshMaterialCount
Definition OOMesh.h:58
Vector * _vertices
Definition OOMesh.h:105
NSMutableDictionary * _retainedObjects
Definition OOMesh.h:124
NSDictionary * _shaderMacros
Definition OOMesh.h:129
uint8_t brokenInRender
Definition OOMesh.h:94
OOMaterial * materials[kOOMeshMaxMaterials]
Definition OOMesh.h:115
id _shaderBindingTarget
Definition OOMesh.h:130
GLfloat maxDrawDistance
Definition OOMesh.h:119
NSString * materialKeys[kOOMeshMaxMaterials]
Definition OOMesh.h:114
Octree * octree
Definition OOMesh.h:122
GLuint displayList0
Definition OOMesh.h:116
uint8_t listsReady
Definition OOMesh.h:95
OOMeshFace * _faces
Definition OOMesh.h:108
uint8_t _normalMode
Definition OOMesh.h:93
OOMeshMaterialCount materialCount
Definition OOMesh.h:97
NSRange triangle_range[kOOMeshMaxMaterials]
Definition OOMesh.h:113
Vector _lastPosition
Definition OOMesh.h:132
Vector * _tangents
Definition OOMesh.h:107
NSString * _cacheKey
Definition OOMesh.h:128
BoundingBox _lastBoundingBox
Definition OOMesh.h:134
BOOL _cacheWriteable
Definition OOMesh.h:103
NSDictionary * _materialDict
Definition OOMesh.h:126
NSDictionary * _shadersDict
Definition OOMesh.h:127
BoundingBox boundingBox
Definition OOMesh.h:120
NSString * baseFileOctreeCacheRef
Definition OOMesh.h:102
NSString * baseFile
Definition OOMesh.h:101
OOMeshVertexCount vertexCount
Definition OOMesh.h:98
OOMatrix _lastRotMatrix
Definition OOMesh.h:133
Vector * _normals
Definition OOMesh.h:106
OOMeshDisplayLists _displayLists
Definition OOMesh.h:111
GLfloat collisionRadius
Definition OOMesh.h:118
OOMeshFaceCount faceCount
Definition OOMesh.h:99
Vector * tangentArray
Definition OOMesh.h:83
GLint * indexArray
Definition OOMesh.h:79
Vector * vertexArray
Definition OOMesh.h:81
GLfloat * textureUVArray
Definition OOMesh.h:80
Vector * normalArray
Definition OOMesh.h:82
Vector tangent
Definition OOMesh.h:71
Vector normal
Definition OOMesh.h:70
OOMeshSmoothGroup smoothGroup
Definition OOMesh.h:66
OOMeshMaterialIndex materialIndex
Definition OOMesh.h:67