Object3D.html 18.5 KB
Newer Older
1 2 3
<!DOCTYPE html>
<html lang="en">
	<head>
M
Mr.doob 已提交
4
		<meta charset="utf-8" />
M
Mr.doob 已提交
5
		<base href="../../../" />
M
Mr.doob 已提交
6 7
		<script src="page.js"></script>
		<link type="text/css" rel="stylesheet" href="page.css" />
8 9 10 11
	</head>
	<body>
		<h1>[name]</h1>

12
		<p class="desc">
L
Lewy Blue 已提交
13
			This is the base class for most objects in three.js and provides a set of properties and methods
L
looeee 已提交
14 15 16 17
			for manipulating objects in 3D space.<br /><br />

			Note that this can be used for grouping objects via the [page:.add]( object ) method
			which adds the object as a child, however it is better to use [page:Group] for this.
18
		</p>
19 20 21 22


		<h2>Constructor</h2>

C
cjshannon 已提交
23

24
		<h3>[name]()</h3>
25
		<p>
G
Greg Tatum 已提交
26
		The constructor takes no arguments.
27
		</p>
28 29 30 31


		<h2>Properties</h2>

M
Mugen87 已提交
32 33 34
		<h3>[property:AnimationClip animations]</h3>
		<p>Array with object's animation clips.</p>

L
looeee 已提交
35
		<h3>[property:Boolean castShadow]</h3>
36
		<p>Whether the object gets rendered into shadow map. Default is *false*.</p>
37

L
looeee 已提交
38
		<h3>[property:Object3D children]</h3>
39
		<p>Array with object's children. See [page:Group] for info on manually grouping objects.</p>
40

41 42 43 44 45 46 47 48 49 50
		<h3>[property:Material customDepthMaterial]</h3>
		<p>
		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 [page:DirectionalLight] or [page: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. Default is *undefined*.
		</p>

		<h3>[property:Material customDistanceMaterial]</h3>
		<p>
51
		Same as [page:.customDepthMaterial customDepthMaterial], but used with [page:PointLight]. Default is *undefined*.
52 53
		</p>

L
looeee 已提交
54
		<h3>[property:Boolean frustumCulled]</h3>
55
		<p>
56
		When this is set, it checks every frame if the object is in the frustum of the camera before rendering the object. If set to `false` the object gets rendered every frame even if it is not in the frustum of the camera. Default is `true`.
57
		</p>
M
Mr.doob 已提交
58

L
looeee 已提交
59
		<h3>[property:Integer id]</h3>
60
		<p>readonly – Unique number for this object instance.</p>
M
Mr.doob 已提交
61

L
looeee 已提交
62
		<h3>[property:Layers layers]</h3>
63
		<p>
L
looeee 已提交
64
		The layer membership of the object. The object is only visible if it has at least one
65 66
		layer in common with the [page:Camera] in use. This property can also be used to filter out
		unwanted objects in ray-intersection tests when using [page:Raycaster].
67
		</p>
68

L
looeee 已提交
69
		<h3>[property:Matrix4 matrix]</h3>
70
		<p>The local transform matrix.</p>
71

L
looeee 已提交
72
		<h3>[property:Boolean matrixAutoUpdate]</h3>
73
		<p>
L
looeee 已提交
74
		When this is set, it calculates the matrix of position, (rotation or quaternion) and
75
		scale every frame and also recalculates the matrixWorld property. Default is [page:Object3D.DefaultMatrixAutoUpdate] (true).
76
		</p>
77

L
looeee 已提交
78
		<h3>[property:Matrix4 matrixWorld]</h3>
79
		<p>
J
Jing Ma 已提交
80
		The global transform of the object. If the Object3D has no parent, then it's identical to
L
looeee 已提交
81
		the local transform [page:.matrix].
82
		</p>
83

L
looeee 已提交
84
		<h3>[property:Boolean matrixWorldNeedsUpdate]</h3>
85
		<p>
L
looeee 已提交
86 87
		When this is set, it calculates the matrixWorld in that frame and resets this property
		 to false. Default is *false*.
88
		</p>
89

L
looeee 已提交
90
		<h3>[property:Matrix4 modelViewMatrix]</h3>
91
		<p>This is passed to the shader and used to calculate the position of the object.</p>
92

L
looeee 已提交
93
		<h3>[property:String name]</h3>
94
		<p>Optional name of the object (doesn't need to be unique). Default is an empty string.</p>
L
looeee 已提交
95 96

		<h3>[property:Matrix3 normalMatrix]</h3>
97
		<p>
98 99 100 101 102
		This is passed to the shader and used to calculate lighting for the object. It is the transpose of the inverse of the upper left 3x3 sub-matrix of this object's modelViewMatrix.<br /><br />

		The reason for this special matrix is that simply using the modelViewMatrix could result in a non-unit length of normals (on scaling) or in a non-perpendicular direction (on non-uniform scaling).<br /><br />

		On the other hand the translation part of the modelViewMatrix is not relevant for the calculation of normals. Thus a Matrix3 is sufficient.
103
		</p>
L
looeee 已提交
104

105
		<h3>[property:Function onAfterRender]</h3>
106
		<p>
107
		An optional callback that is executed immediately after a 3D object is rendered.
L
looeee 已提交
108 109
		This function is called with the following parameters: renderer, scene, camera, geometry,
		material, group.
110
		</p>
111 112 113 114 115
		<p>
		Please notice that this callback is only executed for *renderable* 3D objects. Meaning 3D objects which define their visual
		appearance with geometries and materials like instances of [page:Mesh], [page:Line], [page:Points] or [page:Sprite].
		Instances of [page:Object3D], [page:Group] or [page:Bone] are not renderable and thus this callback is not executed for such objects.
		</p>
L
looeee 已提交
116

117
		<h3>[property:Function onBeforeRender]</h3>
118
		<p>
119
		An optional callback that is executed immediately before a 3D object is rendered.
L
looeee 已提交
120 121
		This function is called with the following parameters: renderer, scene, camera, geometry,
		material, group.
122
		</p>
123 124 125 126 127
		<p>
		Please notice that this callback is only executed for *renderable* 3D objects. Meaning 3D objects which define their visual
		appearance with geometries and materials like instances of [page:Mesh], [page:Line], [page:Points] or [page:Sprite].
		Instances of [page:Object3D], [page:Group] or [page:Bone] are not renderable and thus this callback is not executed for such objects.
		</p>
128

L
looeee 已提交
129
		<h3>[property:Object3D parent]</h3>
130 131
		<p>Object's parent in the [link:https://en.wikipedia.org/wiki/Scene_graph scene graph]. An object can have at most
		one parent.</p>
L
looeee 已提交
132 133

		<h3>[property:Vector3 position]</h3>
134
		<p>A [page:Vector3] representing the object's local position. Default is (0, 0, 0).</p>
L
looeee 已提交
135 136

		<h3>[property:Quaternion quaternion]</h3>
137
		<p>Object's local rotation as a [page:Quaternion Quaternion].</p>
L
looeee 已提交
138

139
		<h3>[property:Boolean receiveShadow]</h3>
140
		<p>Whether the material receives shadows. Default is *false*.</p>
141

L
looeee 已提交
142
		<h3>[property:Number renderOrder]</h3>
143
		<p>
L
looeee 已提交
144
		This value allows the default rendering order of [link:https://en.wikipedia.org/wiki/Scene_graph scene graph]
145 146
		objects to be overridden although opaque and transparent objects remain sorted independently. When this property
		is set for an instance of [page:Group Group], all descendants objects will be sorted and rendered together.
L
looeee 已提交
147
		Sorting is from lowest to highest renderOrder. Default value is *0*.
148
		</p>
149

L
looeee 已提交
150
		<h3>[property:Euler rotation]</h3>
151
		<p>
L
looeee 已提交
152
		Object's local rotation (see [link:https://en.wikipedia.org/wiki/Euler_angles Euler angles]), in radians.
153
		</p>
154

L
looeee 已提交
155
		<h3>[property:Vector3 scale]</h3>
156 157 158
		<p>
		The object's local scale. Default is [page:Vector3]( 1, 1, 1 ).
		</p>
159

L
looeee 已提交
160
		<h3>[property:Vector3 up]</h3>
161
		<p>
L
Lewy Blue 已提交
162 163
		This is used by the [page:.lookAt lookAt] method, for example, to determine the orientation of the result.<br />
		Default is [page:Object3D.DefaultUp] - that is, ( 0, 1, 0 ).
164
		</p>
L
looeee 已提交
165

166
		<h3>[property:Object userData]</h3>
167
		<p>
J
Jing Ma 已提交
168
		An object that can be used to store custom data about the Object3D. It should not hold
L
looeee 已提交
169
		references to functions as these will not be cloned.
170
		</p>
C
cjshannon 已提交
171

L
looeee 已提交
172
		<h3>[property:String uuid]</h3>
173
		<p>
L
looeee 已提交
174 175
		[link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID] of this object instance.
		This gets automatically assigned, so this shouldn't be edited.
176
		</p>
177

L
looeee 已提交
178
		<h3>[property:Boolean visible]</h3>
179
		<p>Object gets rendered if *true*. Default is *true*.</p>
L
looeee 已提交
180 181 182



183

184
		<h2>Static Properties</h2>
185
		<p>
186 187 188 189 190
			Static properties and methods are defined per class rather than per instance of that class.
			This means that changing [page:Object3D.DefaultUp] or [page:Object3D.DefaultMatrixAutoUpdate]
			will change the values of [page:.up up] and [page:.matrixAutoUpdate matrixAutoUpdate] for
			<em>every</em>	instance of Object3D (or derived classes)	created after the change has
			been made (already created Object3Ds will not be affected).
191
		</p>
192 193

		<h3>[property:Vector3 DefaultUp]</h3>
194
		<p>
195 196
			The default [page:.up up] direction for objects, also used as the default position for [page:DirectionalLight],
			[page:HemisphereLight] and [page:Spotlight] (which creates lights shining from the top down).<br />
J
Jing Ma 已提交
197
			Set to ( 0, 1, 0 ) by default.
198
		</p>
199

200
		<h3>[property:Boolean DefaultMatrixAutoUpdate]</h3>
201
		<p>
J
Jing Ma 已提交
202
			The default setting for [page:.matrixAutoUpdate matrixAutoUpdate] for newly created Object3Ds.<br />
C
cjshannon 已提交
203

204
		</p>
A
aardgoose 已提交
205

206

207
		<h2>Methods</h2>
208

G
Greg Tatum 已提交
209
		<h3>[page:EventDispatcher EventDispatcher] methods are available on this class.</h3>
210

211
		<h3>[method:this add]( [param:Object3D object], ... )</h3>
212
		<p>
213
		Adds *object* as child of this object. An arbitrary number of objects may be added. Any current parent on an
214
		object passed in here will be removed, since an object can have at most one parent.<br /><br />
215

L
looeee 已提交
216
		See [page:Group] for info on manually grouping objects.
217
		</p>
218

219
		<h3>[method:null applyMatrix4]( [param:Matrix4 matrix] )</h3>
220
		<p>Applies the matrix transform to the object and updates the object's position, rotation and scale.</p>
W
WestLangley 已提交
221

222
		<h3>[method:this applyQuaternion]( [param:Quaternion quaternion] )</h3>
223
		<p>Applies the rotation represented by the quaternion to the object.</p>
L
looeee 已提交
224

W
WestLangley 已提交
225 226 227
		<h3>[method:this attach]( [param:Object3D object] )</h3>
		<p>Adds *object* as a child of this, while maintaining the object's world transform.</p>

228
		<h3>[method:Object3D clone]( [param:Boolean recursive] )</h3>
229
		<p>
L
looeee 已提交
230 231
		recursive -- if true, descendants of the object are also cloned. Default is true.<br /><br />

J
Jing Ma 已提交
232
		Returns a clone of this object and optionally all descendants.
233
		</p>
L
looeee 已提交
234

235
		<h3>[method:this copy]( [param:Object3D object], [param:Boolean recursive] )</h3>
236
		<p>
L
looeee 已提交
237 238 239
		recursive -- if true, descendants of the object are also copied. Default is true.<br /><br />

		Copy the given object into this object.
240

M
Mr.doob 已提交
241
		Note: event listeners and user-defined callbacks ([page:.onAfterRender] and [page:.onBeforeRender]) are not copied.
242
		</p>
243

244
		<h3>[method:Object3D getObjectById]( [param:Integer id] )</h3>
245
		<p>
L
looeee 已提交
246 247
		id -- Unique number of the object instance<br /><br />

U
unknown 已提交
248
		Searches through an object and its children, starting with the object itself, and returns the first with a matching id.<br />
L
looeee 已提交
249
		Note that ids are assigned in chronological order: 1, 2, 3, ..., incrementing by one for each new object.
250
		</p>
L
looeee 已提交
251

252
		<h3>[method:Object3D getObjectByName]( [param:String name] )</h3>
253
		<p>
J
Jing Ma 已提交
254
		name -- String to match to the children's Object3D.name property. <br /><br />
L
looeee 已提交
255

U
unknown 已提交
256
		Searches through an object and its children, starting with the object itself, and returns the first with a matching name.<br />
257
		Note that for most objects the name is an empty string by default. You will
L
looeee 已提交
258
		have to set it manually to make use of this method.
259
		</p>
260

261
		<h3>[method:Object3D getObjectByProperty]( [param:String name], [param:Float value] )</h3>
262
		<p>
L
looeee 已提交
263 264 265
		name -- the property name to search for. <br />
		value -- value of the given property. <br /><br />

U
unknown 已提交
266
		Searches through an object and its children, starting with the object itself, and returns the first with a property that matches the value given.
267
		</p>
L
looeee 已提交
268

M
Mr.doob 已提交
269
		<h3>[method:Vector3 getWorldPosition]( [param:Vector3 target] )</h3>
270
		<p>
W
WestLangley 已提交
271
		[page:Vector3 target] — the result will be copied into this Vector3. <br /><br />
L
looeee 已提交
272 273

		Returns a vector representing the position of the object in world space.
274
		</p>
275

M
Mr.doob 已提交
276
		<h3>[method:Quaternion getWorldQuaternion]( [param:Quaternion target] )</h3>
277
		<p>
W
WestLangley 已提交
278
		[page:Quaternion target] — the result will be copied into this Quaternion. <br /><br />
L
looeee 已提交
279 280

		Returns a quaternion representing the rotation of the object in world space.
281
		</p>
L
looeee 已提交
282

M
Mr.doob 已提交
283
		<h3>[method:Vector3 getWorldScale]( [param:Vector3 target] )</h3>
284
		<p>
W
WestLangley 已提交
285
		[page:Vector3 target] — the result will be copied into this Vector3. <br /><br />
L
looeee 已提交
286 287

		Returns a vector of the scaling factors applied to the object for each axis in world space.
288
		</p>
L
looeee 已提交
289

M
Mr.doob 已提交
290
		<h3>[method:Vector3 getWorldDirection]( [param:Vector3 target] )</h3>
291
		<p>
W
WestLangley 已提交
292
		[page:Vector3 target] — the result will be copied into this Vector3. <br /><br />
L
looeee 已提交
293 294

		Returns a vector representing the direction of object's positive z-axis in world space.
295
		</p>
296

L
looeee 已提交
297

298
		<h3>[method:Vector3 localToWorld]( [param:Vector3 vector] )</h3>
299
		<p>
W
WestLangley 已提交
300
		vector - A vector representing a position in this object's local space.<br /><br />
301

W
WestLangley 已提交
302
		Converts the vector from this object's local space to world space.
303
		</p>
304

L
linbingquan 已提交
305
		<h3>[method:null lookAt]( [param:Vector3 vector] )<br />
306
		[method:null lookAt]( [param:Float x], [param:Float y], [param:Float z] )</h3>
307
		<p>
L
looeee 已提交
308
		vector - A vector representing a position in world space.<br /><br />
W
WestLangley 已提交
309 310 311 312
		Optionally, the [page:.x x], [page:.y y] and [page:.z z] components of the world space position.<br /><br />

		Rotates the object to face a point in world space.<br /><br />

W
WestLangley 已提交
313
		This method does not support objects having non-uniformly-scaled parent(s).
314
		</p>
L
looeee 已提交
315

316
		<h3>[method:Array raycast]( [param:Raycaster raycaster], [param:Array intersects] )</h3>
317
		<p>
L
looeee 已提交
318 319 320
		Abstract (empty) method to get intersections between a casted ray and this object.
		Subclasses such as [page:Mesh], [page:Line], and [page:Points] implement this method in order
		to use raycasting.
321
		</p>
322

323
		<h3>[method:this remove]( [param:Object3D object], ... )</h3>
324
		<p>
325
		Removes *object* as child of this object. An arbitrary number of objects may be removed.
326
		</p>
327

M
Mr.doob 已提交
328
		<h3>[method:this clear]()</h3>
M
Mugen87 已提交
329 330 331 332
		<p>
		Removes all child objects.
		</p>

333
		<h3>[method:this rotateOnAxis]( [param:Vector3 axis], [param:Float angle] )</h3>
334
		<p>
335
		axis -- A normalized vector in object space.<br />
L
looeee 已提交
336
		angle -- The angle in radians.<br /><br />
337

338
		Rotate the object on an axis in object space. The axis is assumed to be normalized.
339
		</p>
340

341
		<h3>[method:this rotateOnWorldAxis]( [param:Vector3 axis], [param:Float angle] )</h3>
342
		<p>
343
		axis -- A normalized vector in world space.<br />
344 345
		angle -- The angle in radians.<br /><br />

346 347 348
		Rotate the object on an axis in world space. The axis is assumed to be normalized.<br /><br />

		This method does not support objects having rotated parent(s).
349
		</p>
350

351 352 353 354 355 356 357 358 359 360 361
		<h3>[method:this rotateAroundWorldAxis]( [param:Vector3 point], [param:Vector3 axis], [param:Float angle] )</h3>
		<p>
		point -- The point to rotate around.<br />
		axis -- A normalized vector in world space.<br />
		angle -- The angle in radians.<br /><br />

		Rotate the object around an axis in world space. (The axis passes through point.) The axis is assumed to be normalized.<br /><br/ >

		This method does not support objects having rotated parent(s).
		</p>

362
		<h3>[method:this rotateX]( [param:Float rad] )</h3>
363
		<p>
L
looeee 已提交
364
		rad - the angle to rotate in radians.<br /><br />
365

L
looeee 已提交
366
		Rotates the object around x axis in local space.
367
		</p>
368

369
		<h3>[method:this rotateY]( [param:Float rad] )</h3>
370
		<p>
L
looeee 已提交
371
		rad - the angle to rotate in radians.<br /><br />
372

L
looeee 已提交
373
		Rotates the object around y axis in local space.
374
		</p>
375

376
		<h3>[method:this rotateZ]( [param:Float rad] )</h3>
377
		<p>
L
looeee 已提交
378
		rad - the angle to rotate in radians.<br /><br />
C
cjshannon 已提交
379

L
looeee 已提交
380
		Rotates the object around z axis in local space.
381
		</p>
382

383
		<h3>[method:null setRotationFromAxisAngle]( [param:Vector3 axis], [param:Float angle] )</h3>
384
		<p>
L
looeee 已提交
385 386
			axis -- A normalized vector in object space. <br />
			angle -- angle in radians<br /><br />
387

L
looeee 已提交
388 389
			Calls [page:Quaternion.setFromAxisAngle setFromAxisAngle]( [page:Float axis], [page:Float angle] )
			on the [page:.quaternion].
390
		</p>
391

392
		<h3>[method:null setRotationFromEuler]( [param:Euler euler] )</h3>
393
		<p>
L
looeee 已提交
394
			euler -- Euler angle specifying rotation amount.<br />
395

L
looeee 已提交
396 397
			Calls [page:Quaternion.setRotationFromEuler setRotationFromEuler]( [page:Euler euler])
			on the [page:.quaternion].
398
		</p>
L
looeee 已提交
399

400
		<h3>[method:null setRotationFromMatrix]( [param:Matrix4 m] )</h3>
401
		<p>
L
looeee 已提交
402 403 404 405 406 407
			m -- rotate the quaternion by the rotation component of the matrix.<br />

			Calls [page:Quaternion.setFromRotationMatrix setFromRotationMatrix]( [page:Matrix4 m])
			on the [page:.quaternion].<br /><br />

			Note that this assumes that the upper 3x3 of m is a pure rotation matrix (i.e, unscaled).
408
		</p>
409

410
		<h3>[method:null setRotationFromQuaternion]( [param:Quaternion q] )</h3>
411
		<p>
L
looeee 已提交
412 413 414
			q -- normalized Quaternion.<br /><br />

			Copy the given quaternion into [page:.quaternion].
415
		</p>
L
looeee 已提交
416

G
gonnavis 已提交
417
		<h3>[method:Object toJSON]( [param:Object meta] )</h3>
418
		<p>
419 420
		meta -- object containing metadata such as materials, textures or images for the object.<br />
		Convert the object to three.js [link:https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 JSON Object/Scene format].
421
		</p>
422

423
		<h3>[method:this translateOnAxis]( [param:Vector3 axis], [param:Float distance] )</h3>
424
		<p>
G
Greg Tatum 已提交
425
		axis -- A normalized vector in object space.<br />
L
looeee 已提交
426 427 428
		distance -- The distance to translate.<br /><br />

		Translate an object by distance along an axis in object space. The axis is assumed to be normalized.
429
		</p>
L
looeee 已提交
430

431
		<h3>[method:this translateX]( [param:Float distance] )</h3>
H
haolly 已提交
432
		<p>Translates object along x axis in object space by *distance* units.</p>
L
looeee 已提交
433

434
		<h3>[method:this translateY]( [param:Float distance] )</h3>
H
haolly 已提交
435
		<p>Translates object along y axis in object space by *distance* units.</p>
L
looeee 已提交
436

437
		<h3>[method:this translateZ]( [param:Float distance] )</h3>
H
haolly 已提交
438
		<p>Translates object along z axis in object space by *distance* units.</p>
L
looeee 已提交
439

440
		<h3>[method:null traverse]( [param:Function callback] )</h3>
441
		<p>
L
looeee 已提交
442 443
		callback - A function with as first argument an object3D object.<br /><br />

M
Mr.doob 已提交
444 445
		Executes the callback on this object and all descendants.<br/>
		Note: Modifying the scene graph inside the callback is discouraged.
446
		</p>
447

448
		<h3>[method:null traverseVisible]( [param:Function callback] )</h3>
449
		<p>
L
looeee 已提交
450 451 452
		callback - A function with as first argument an object3D object.<br /><br />

		Like traverse, but the callback will only be executed for visible objects.
M
Mr.doob 已提交
453 454
		Descendants of invisible objects are not traversed.<br/>
		Note: Modifying the scene graph inside the callback is discouraged.
455
		</p>
L
looeee 已提交
456

457
		<h3>[method:null traverseAncestors]( [param:Function callback] )</h3>
458
		<p>
L
looeee 已提交
459 460
		callback - A function with as first argument an object3D object.<br /><br />

M
Mr.doob 已提交
461 462
		Executes the callback on all ancestors.<br/>
		Note: Modifying the scene graph inside the callback is discouraged.
463
		</p>
C
cjshannon 已提交
464

L
looeee 已提交
465
		<h3>[method:null updateMatrix]()</h3>
466
		<p>Updates the local transform.</p>
L
looeee 已提交
467

468
		<h3>[method:null updateMatrixWorld]( [param:Boolean force] )</h3>
G
Guilherme Avila 已提交
469
		<p>Updates the global transform of the object and its descendants.</p>
L
looeee 已提交
470

471 472
		<h3>[method:null updateWorldMatrix]( [param:Boolean updateParents], [param:Boolean updateChildren] )</h3>
		<p>
473 474
		updateParents - recursively updates global transform of ancestors.<br />
		updateChildren - recursively updates global transform of descendants.<br /><br />
475

476
		Updates the global transform of the object.
477
		</p>
L
looeee 已提交
478

479
		<h3>[method:Vector3 worldToLocal]( [param:Vector3 vector] )</h3>
480
		<p>
W
WestLangley 已提交
481
		vector - A vector representing a position in world space.<br /><br />
L
looeee 已提交
482

W
WestLangley 已提交
483
		Converts the vector from world space to this object's local space.
484
		</p>
485

486 487
		<h2>Source</h2>

M
Mugen87 已提交
488 489 490
		<p>
			[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
		</p>
491 492
	</body>
</html>