Object3D.d.ts 8.1 KB
Newer Older
L
lu wang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import { Vector3 } from './../math/Vector3';
import { Euler } from './../math/Euler';
import { Quaternion } from './../math/Quaternion';
import { Matrix4 } from './../math/Matrix4';
import { Matrix3 } from './../math/Matrix3';
import { Layers } from './Layers';
import { WebGLRenderer } from './../renderers/WebGLRenderer';
import { Scene } from './../scenes/Scene';
import { Camera } from './../cameras/Camera';
import { Geometry } from './Geometry';
import { Material } from './../materials/Material';
import { Group } from './../objects/Group';
import { Raycaster } from './Raycaster';
import { EventDispatcher } from './EventDispatcher';
import { BufferGeometry } from './BufferGeometry';
import { Intersection } from './Raycaster';

export let Object3DIdCount: number;

/**
 * Base class for scene graph objects
 */
23
export class Object3D<Renderer = WebGLRenderer> extends EventDispatcher {
M
Mr.doob 已提交
24 25

	constructor();
L
lu wang 已提交
26

M
Mr.doob 已提交
27
	/**
M
Mugen87 已提交
28 29
	 * Unique number of this object instance.
	 */
M
Mr.doob 已提交
30
	id: number;
L
lu wang 已提交
31

M
Mr.doob 已提交
32
	/**
M
Mugen87 已提交
33 34
	 *
	 */
M
Mr.doob 已提交
35
	uuid: string;
L
lu wang 已提交
36

M
Mr.doob 已提交
37
	/**
M
Mugen87 已提交
38 39
	 * Optional name of the object (doesn't need to be unique).
	 */
M
Mr.doob 已提交
40
	name: string;
L
lu wang 已提交
41

M
Mr.doob 已提交
42
	type: string;
L
lu wang 已提交
43

M
Mr.doob 已提交
44
	/**
M
Mugen87 已提交
45 46
	 * Object's parent in the scene graph.
	 */
M
Mr.doob 已提交
47
	parent: Object3D | null;
L
lu wang 已提交
48

M
Mr.doob 已提交
49
	/**
M
Mugen87 已提交
50 51
	 * Array with object's children.
	 */
M
Mr.doob 已提交
52
	children: Object3D[];
L
lu wang 已提交
53

M
Mr.doob 已提交
54
	/**
M
Mugen87 已提交
55 56
	 * Up direction.
	 */
M
Mr.doob 已提交
57
	up: Vector3;
L
lu wang 已提交
58

M
Mr.doob 已提交
59
	/**
M
Mugen87 已提交
60 61
	 * Object's local position.
	 */
62
	readonly position: Vector3;
L
lu wang 已提交
63

M
Mr.doob 已提交
64
	/**
M
Mugen87 已提交
65 66
	 * Object's local rotation (Euler angles), in radians.
	 */
67
	readonly rotation: Euler;
L
lu wang 已提交
68

M
Mr.doob 已提交
69
	/**
M
Mugen87 已提交
70 71
	 * Global rotation.
	 */
72
	readonly quaternion: Quaternion;
L
lu wang 已提交
73

M
Mr.doob 已提交
74
	/**
M
Mugen87 已提交
75 76
	 * Object's local scale.
	 */
77
	readonly scale: Vector3;
L
lu wang 已提交
78

79
	readonly modelViewMatrix: Matrix4;
L
lu wang 已提交
80

81
	readonly normalMatrix: Matrix3;
L
lu wang 已提交
82

M
Mr.doob 已提交
83
	/**
M
Mugen87 已提交
84 85
	 * Local transform.
	 */
M
Mr.doob 已提交
86
	matrix: Matrix4;
L
lu wang 已提交
87

M
Mr.doob 已提交
88
	/**
M
Mugen87 已提交
89 90
	 * The global transform of the object. If the Object3d has no parent, then it's identical to the local transform.
	 */
M
Mr.doob 已提交
91
	matrixWorld: Matrix4;
L
lu wang 已提交
92

M
Mr.doob 已提交
93
	/**
M
Mugen87 已提交
94 95
	 * When this is set, it calculates the matrix of position, (rotation or quaternion) and scale every frame and also recalculates the matrixWorld property.
	 */
M
Mr.doob 已提交
96
	matrixAutoUpdate: boolean;
L
lu wang 已提交
97

M
Mr.doob 已提交
98
	/**
M
Mugen87 已提交
99 100
	 * When this is set, it calculates the matrixWorld in that frame and resets this property to false.
	 */
M
Mr.doob 已提交
101
	matrixWorldNeedsUpdate: boolean;
L
lu wang 已提交
102

M
Mr.doob 已提交
103 104
	layers: Layers;
	/**
M
Mugen87 已提交
105 106
	 * Object gets rendered if true.
	 */
M
Mr.doob 已提交
107
	visible: boolean;
L
lu wang 已提交
108

M
Mr.doob 已提交
109
	/**
M
Mugen87 已提交
110 111
	 * Gets rendered into shadow map.
	 */
M
Mr.doob 已提交
112
	castShadow: boolean;
L
lu wang 已提交
113

M
Mr.doob 已提交
114
	/**
M
Mugen87 已提交
115 116
	 * Material gets baked in shadow receiving.
	 */
M
Mr.doob 已提交
117
	receiveShadow: boolean;
L
lu wang 已提交
118

M
Mr.doob 已提交
119
	/**
M
Mugen87 已提交
120 121
	 * When this is set, it checks every frame if the object is in the frustum of the camera. Otherwise the object gets drawn every frame even if it isn't visible.
	 */
M
Mr.doob 已提交
122
	frustumCulled: boolean;
L
lu wang 已提交
123

M
Mr.doob 已提交
124
	/**
M
Mugen87 已提交
125 126
	 * Overrides the default rendering order of scene graph objects, from lowest to highest renderOrder. Opaque and transparent objects remain sorted independently though. When this property is set for an instance of Group, all descendants objects will be sorted and rendered together.
	 */
M
Mr.doob 已提交
127
	renderOrder: number;
L
lu wang 已提交
128

M
Mr.doob 已提交
129
	/**
M
Mugen87 已提交
130 131
	 * An object that can be used to store custom data about the Object3d. It should not hold references to functions as these will not be cloned.
	 */
M
Mr.doob 已提交
132
	userData: { [key: string]: any };
L
lu wang 已提交
133

M
Mr.doob 已提交
134
	/**
M
Mugen87 已提交
135 136 137 138 139
	 * Custom depth material to be used when rendering to the depth map. Can only be used in context of meshes.
	 * When shadow-casting with a DirectionalLight or SpotLight, if you are (a) modifying vertex positions in
	 * the vertex shader, (b) using a displacement map, (c) using an alpha map with alphaTest, or (d) using a
	 * transparent texture with alphaTest, you must specify a customDepthMaterial for proper shadows.
	 */
M
Mr.doob 已提交
140
	customDepthMaterial: Material;
141

M
Mr.doob 已提交
142
	/**
M
Mugen87 已提交
143 144
	 * Same as customDepthMaterial, but used with PointLight.
	 */
M
Mr.doob 已提交
145
	customDistanceMaterial: Material;
146

M
Mr.doob 已提交
147
	/**
M
Mugen87 已提交
148 149 150
	 * Used to check whether this or derived classes are Object3Ds. Default is true.
	 * You should not change this, as it is used internally for optimisation.
	 */
Y
Yomotsu 已提交
151
	readonly isObject3D: true;
L
lu wang 已提交
152

M
Mr.doob 已提交
153
	/**
M
Mugen87 已提交
154 155
	 * Calls before rendering object
	 */
M
Mr.doob 已提交
156
	onBeforeRender: (
157
		renderer: Renderer,
M
Mr.doob 已提交
158 159 160 161 162 163
		scene: Scene,
		camera: Camera,
		geometry: Geometry | BufferGeometry,
		material: Material,
		group: Group
	) => void;
L
lu wang 已提交
164

M
Mr.doob 已提交
165
	/**
M
Mugen87 已提交
166 167
	 * Calls after rendering object
	 */
M
Mr.doob 已提交
168
	onAfterRender: (
169
		renderer: Renderer,
M
Mr.doob 已提交
170 171 172 173 174 175
		scene: Scene,
		camera: Camera,
		geometry: Geometry | BufferGeometry,
		material: Material,
		group: Group
	) => void;
L
lu wang 已提交
176

M
Mr.doob 已提交
177 178
	static DefaultUp: Vector3;
	static DefaultMatrixAutoUpdate: boolean;
L
lu wang 已提交
179

M
Mr.doob 已提交
180
	/**
M
Mugen87 已提交
181 182
	 * This updates the position, rotation and scale with the matrix.
	 */
183
	applyMatrix4( matrix: Matrix4 ): void;
L
lu wang 已提交
184

M
Mr.doob 已提交
185
	applyQuaternion( quaternion: Quaternion ): this;
L
lu wang 已提交
186

M
Mr.doob 已提交
187
	/**
M
Mugen87 已提交
188 189
	 *
	 */
M
Mr.doob 已提交
190
	setRotationFromAxisAngle( axis: Vector3, angle: number ): void;
L
lu wang 已提交
191

M
Mr.doob 已提交
192
	/**
M
Mugen87 已提交
193 194
	 *
	 */
M
Mr.doob 已提交
195
	setRotationFromEuler( euler: Euler ): void;
L
lu wang 已提交
196

M
Mr.doob 已提交
197
	/**
M
Mugen87 已提交
198 199
	 *
	 */
M
Mr.doob 已提交
200
	setRotationFromMatrix( m: Matrix4 ): void;
L
lu wang 已提交
201

M
Mr.doob 已提交
202
	/**
M
Mugen87 已提交
203 204
	 *
	 */
M
Mr.doob 已提交
205
	setRotationFromQuaternion( q: Quaternion ): void;
L
lu wang 已提交
206

M
Mr.doob 已提交
207
	/**
M
Mugen87 已提交
208 209 210 211
	 * Rotate an object along an axis in object space. The axis is assumed to be normalized.
	 * @param axis	A normalized vector in object space.
	 * @param angle	The angle in radians.
	 */
M
Mr.doob 已提交
212
	rotateOnAxis( axis: Vector3, angle: number ): this;
L
lu wang 已提交
213

M
Mr.doob 已提交
214
	/**
M
Mugen87 已提交
215 216 217 218
	 * Rotate an object along an axis in world space. The axis is assumed to be normalized. Method Assumes no rotated parent.
	 * @param axis	A normalized vector in object space.
	 * @param angle	The angle in radians.
	 */
M
Mr.doob 已提交
219
	rotateOnWorldAxis( axis: Vector3, angle: number ): this;
L
lu wang 已提交
220

M
Mr.doob 已提交
221
	/**
M
Mugen87 已提交
222 223 224
	 *
	 * @param angle
	 */
M
Mr.doob 已提交
225
	rotateX( angle: number ): this;
L
lu wang 已提交
226

M
Mr.doob 已提交
227
	/**
M
Mugen87 已提交
228 229 230
	 *
	 * @param angle
	 */
M
Mr.doob 已提交
231
	rotateY( angle: number ): this;
L
lu wang 已提交
232

M
Mr.doob 已提交
233
	/**
M
Mugen87 已提交
234 235 236
	 *
	 * @param angle
	 */
M
Mr.doob 已提交
237
	rotateZ( angle: number ): this;
L
lu wang 已提交
238

M
Mr.doob 已提交
239
	/**
M
Mugen87 已提交
240 241 242
	 * @param axis	A normalized vector in object space.
	 * @param distance	The distance to translate.
	 */
M
Mr.doob 已提交
243
	translateOnAxis( axis: Vector3, distance: number ): this;
L
lu wang 已提交
244

M
Mr.doob 已提交
245
	/**
M
Mugen87 已提交
246 247 248
	 * Translates object along x axis by distance.
	 * @param distance Distance.
	 */
M
Mr.doob 已提交
249
	translateX( distance: number ): this;
L
lu wang 已提交
250

M
Mr.doob 已提交
251
	/**
M
Mugen87 已提交
252 253 254
	 * Translates object along y axis by distance.
	 * @param distance Distance.
	 */
M
Mr.doob 已提交
255
	translateY( distance: number ): this;
L
lu wang 已提交
256

M
Mr.doob 已提交
257
	/**
M
Mugen87 已提交
258 259 260
	 * Translates object along z axis by distance.
	 * @param distance Distance.
	 */
M
Mr.doob 已提交
261
	translateZ( distance: number ): this;
L
lu wang 已提交
262

M
Mr.doob 已提交
263
	/**
M
Mugen87 已提交
264 265 266
	 * Updates the vector from local space to world space.
	 * @param vector A local vector.
	 */
M
Mr.doob 已提交
267
	localToWorld( vector: Vector3 ): Vector3;
L
lu wang 已提交
268

M
Mr.doob 已提交
269
	/**
M
Mugen87 已提交
270 271 272
	 * Updates the vector from world space to local space.
	 * @param vector A world vector.
	 */
M
Mr.doob 已提交
273
	worldToLocal( vector: Vector3 ): Vector3;
L
lu wang 已提交
274

M
Mr.doob 已提交
275
	/**
M
Mugen87 已提交
276 277 278
	 * Rotates object to face point in space.
	 * @param vector A world vector to look at.
	 */
M
Mr.doob 已提交
279
	lookAt( vector: Vector3 | number, y?: number, z?: number ): void;
L
lu wang 已提交
280

M
Mr.doob 已提交
281
	/**
M
Mugen87 已提交
282 283
	 * Adds object as child of this object.
	 */
M
Mr.doob 已提交
284
	add( ...object: Object3D[] ): this;
L
lu wang 已提交
285

M
Mr.doob 已提交
286
	/**
M
Mugen87 已提交
287 288
	 * Removes object as child of this object.
	 */
M
Mr.doob 已提交
289
	remove( ...object: Object3D[] ): this;
L
lu wang 已提交
290

M
Mr.doob 已提交
291
	/**
M
Mugen87 已提交
292 293
	 * Adds object as a child of this, while maintaining the object's world transform.
	 */
M
Mr.doob 已提交
294
	attach( object: Object3D ): this;
W
WestLangley 已提交
295

M
Mr.doob 已提交
296
	/**
M
Mugen87 已提交
297 298 299
	 * Searches through the object's children and returns the first with a matching id.
	 * @param id	Unique number of the object instance
	 */
M
Mr.doob 已提交
300
	getObjectById( id: number ): Object3D | undefined;
L
lu wang 已提交
301

M
Mr.doob 已提交
302
	/**
M
Mugen87 已提交
303 304 305
	 * Searches through the object's children and returns the first with a matching name.
	 * @param name	String to match to the children's Object3d.name property.
	 */
M
Mr.doob 已提交
306
	getObjectByName( name: string ): Object3D | undefined;
L
lu wang 已提交
307

M
Mr.doob 已提交
308
	getObjectByProperty( name: string, value: string ): Object3D | undefined;
L
lu wang 已提交
309

M
Mr.doob 已提交
310 311 312 313
	getWorldPosition( target: Vector3 ): Vector3;
	getWorldQuaternion( target: Quaternion ): Quaternion;
	getWorldScale( target: Vector3 ): Vector3;
	getWorldDirection( target: Vector3 ): Vector3;
L
lu wang 已提交
314

M
Mr.doob 已提交
315
	raycast( raycaster: Raycaster, intersects: Intersection[] ): void;
L
lu wang 已提交
316

M
Mr.doob 已提交
317
	traverse( callback: ( object: Object3D ) => any ): void;
L
lu wang 已提交
318

M
Mr.doob 已提交
319
	traverseVisible( callback: ( object: Object3D ) => any ): void;
L
lu wang 已提交
320

M
Mr.doob 已提交
321
	traverseAncestors( callback: ( object: Object3D ) => any ): void;
L
lu wang 已提交
322

M
Mr.doob 已提交
323
	/**
M
Mugen87 已提交
324 325
	 * Updates local transform.
	 */
M
Mr.doob 已提交
326
	updateMatrix(): void;
L
lu wang 已提交
327

M
Mr.doob 已提交
328
	/**
M
Mugen87 已提交
329 330
	 * Updates global transform of the object and its children.
	 */
M
Mr.doob 已提交
331
	updateMatrixWorld( force?: boolean ): void;
L
lu wang 已提交
332

M
Mr.doob 已提交
333
	updateWorldMatrix( updateParents: boolean, updateChildren: boolean ): void;
N
Nathan Bierema 已提交
334

M
Mr.doob 已提交
335 336 337 338 339 340
	toJSON( meta?: {
		geometries: any;
		materials: any;
		textures: any;
		images: any;
	} ): any;
L
lu wang 已提交
341

M
Mr.doob 已提交
342
	clone( recursive?: boolean ): this;
L
lu wang 已提交
343

M
Mr.doob 已提交
344
	/**
M
Mugen87 已提交
345 346 347 348
	 *
	 * @param object
	 * @param recursive
	 */
349
	copy( source: this, recursive?: boolean ): this;
M
Mr.doob 已提交
350

L
lu wang 已提交
351
}