Object3D.html 15.2 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 8
		<script src="list.js"></script>
		<script src="page.js"></script>
		<link type="text/css" rel="stylesheet" href="page.css" />
9 10 11 12
	</head>
	<body>
		<h1>[name]</h1>

13
		<p class="desc">
L
Lewy Blue 已提交
14
			This is the base class for most objects in three.js and provides a set of properties and methods
L
looeee 已提交
15 16 17 18
			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.
19
		</p>
20 21 22 23


		<h2>Constructor</h2>

C
cjshannon 已提交
24

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


		<h2>Properties</h2>

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

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

L
looeee 已提交
39
		<h3>[property:Boolean frustumCulled]</h3>
40
		<p>
L
looeee 已提交
41
		When this is set, it checks every frame if the object is in the frustum of the camera before rendering the object.
42
		Otherwise the object gets rendered every frame even if it isn't visible. Default is *true*.
43
		</p>
M
Mr.doob 已提交
44

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

G
Gerdon Abbink 已提交
48
		<h3>[property:Boolean isObject3D]</h3>
49
		<p>
L
looeee 已提交
50
			Used to check whether this or derived classes are Object3Ds. Default is *true*.<br /><br />
51

J
Jing Ma 已提交
52
			You should not change this, as it is used internally for optimisation.
53
		</p>
54

L
looeee 已提交
55
		<h3>[property:Layers layers]</h3>
56
		<p>
L
looeee 已提交
57 58
		The layer membership of the object. The object is only visible if it has at least one
		layer in common with the [page:Camera] in use.
59
		</p>
60

L
looeee 已提交
61
		<h3>[property:Matrix4 matrix]</h3>
62
		<p>The local transform matrix.</p>
63

L
looeee 已提交
64
		<h3>[property:Boolean matrixAutoUpdate]</h3>
65
		<p>
L
looeee 已提交
66
		When this is set, it calculates the matrix of position, (rotation or quaternion) and
67
		scale every frame and also recalculates the matrixWorld property. Default is [page:Object3D.DefaultMatrixAutoUpdate] (true).
68
		</p>
69

L
looeee 已提交
70
		<h3>[property:Matrix4 matrixWorld]</h3>
71
		<p>
J
Jing Ma 已提交
72
		The global transform of the object. If the Object3D has no parent, then it's identical to
L
looeee 已提交
73
		the local transform [page:.matrix].
74
		</p>
75

L
looeee 已提交
76
		<h3>[property:Boolean matrixWorldNeedsUpdate]</h3>
77
		<p>
L
looeee 已提交
78 79
		When this is set, it calculates the matrixWorld in that frame and resets this property
		 to false. Default is *false*.
80
		</p>
81

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

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

		<h3>[property:Matrix3 normalMatrix]</h3>
89
		<p>
90 91 92 93 94
		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.
95
		</p>
L
looeee 已提交
96 97

		<h3>[property:function onAfterRender]</h3>
98
		<p>
L
looeee 已提交
99 100 101
		An optional callback that is executed immediately after the Object3D is rendered.
		This function is called with the following parameters: renderer, scene, camera, geometry,
		material, group.
102
		</p>
L
looeee 已提交
103 104

		<h3>[property:function onBeforeRender]</h3>
105
		<p>
L
looeee 已提交
106 107 108
		An optional callback that is executed immediately before the Object3D is rendered.
		This function is called with the following parameters: renderer, scene, camera, geometry,
		material, group.
109
		</p>
110

L
looeee 已提交
111
		<h3>[property:Object3D parent]</h3>
112 113
		<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 已提交
114 115

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

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

121
		<h3>[property:Boolean receiveShadow]</h3>
122
		<p>Whether the material receives shadows. Default is *false*.</p>
123

L
looeee 已提交
124
		<h3>[property:Number renderOrder]</h3>
125
		<p>
L
looeee 已提交
126 127 128
		This value allows the default rendering order of [link:https://en.wikipedia.org/wiki/Scene_graph scene graph]
		objects to be overridden although opaque and transparent objects remain sorted independently.
		Sorting is from lowest to highest renderOrder. Default value is *0*.
129
		</p>
130

L
looeee 已提交
131
		<h3>[property:Euler rotation]</h3>
132
		<p>
L
looeee 已提交
133
		Object's local rotation (see [link:https://en.wikipedia.org/wiki/Euler_angles Euler angles]), in radians.
134
		</p>
135

L
looeee 已提交
136
		<h3>[property:Vector3 scale]</h3>
137 138 139
		<p>
		The object's local scale. Default is [page:Vector3]( 1, 1, 1 ).
		</p>
140

L
looeee 已提交
141
		<h3>[property:Vector3 up]</h3>
142
		<p>
L
Lewy Blue 已提交
143 144
		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 ).
145
		</p>
L
looeee 已提交
146

147
		<h3>[property:object userData]</h3>
148
		<p>
J
Jing Ma 已提交
149
		An object that can be used to store custom data about the Object3D. It should not hold
L
looeee 已提交
150
		references to functions as these will not be cloned.
151
		</p>
C
cjshannon 已提交
152

L
looeee 已提交
153
		<h3>[property:String uuid]</h3>
154
		<p>
L
looeee 已提交
155 156
		[link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID] of this object instance.
		This gets automatically assigned, so this shouldn't be edited.
157
		</p>
158

L
looeee 已提交
159
		<h3>[property:Boolean visible]</h3>
160
		<p>Object gets rendered if *true*. Default is *true*.</p>
L
looeee 已提交
161 162 163



164

165
		<h2>Static Properties</h2>
166
		<p>
167 168 169 170 171
			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).
172
		</p>
173 174

		<h3>[property:Vector3 DefaultUp]</h3>
175
		<p>
176 177
			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 已提交
178
			Set to ( 0, 1, 0 ) by default.
179
		</p>
180 181

		<h3>[property:Vector3 DefaultMatrixAutoUpdate]</h3>
182
		<p>
J
Jing Ma 已提交
183
			The default setting for [page:.matrixAutoUpdate matrixAutoUpdate] for newly created Object3Ds.<br />
C
cjshannon 已提交
184

185
		</p>
A
aardgoose 已提交
186

187

188
		<h2>Methods</h2>
189

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

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

L
looeee 已提交
197
		See [page:Group] for info on manually grouping objects.
198
		</p>
199

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

203
		<h3>[method:Object3D applyQuaternion]( [param:Quaternion quaternion] )</h3>
204
		<p>Applies the rotation represented by the quaternion to the object.</p>
L
looeee 已提交
205

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

J
Jing Ma 已提交
210
		Returns a clone of this object and optionally all descendants.
211
		</p>
L
looeee 已提交
212

213
		<h3>[method:this copy]( [param:Object3D object], [param:Boolean recursive] )</h3>
214
		<p>
L
looeee 已提交
215 216 217
		recursive -- if true, descendants of the object are also copied. Default is true.<br /><br />

		Copy the given object into this object.
218
		</p>
219

220
		<h3>[method:Object3D getObjectById]( [param:Integer id] )</h3>
221
		<p>
L
looeee 已提交
222 223 224 225
		id -- Unique number of the object instance<br /><br />

		Searches through the object's children and returns the first with a matching id.<br />
		Note that ids are assigned in chronological order: 1, 2, 3, ..., incrementing by one for each new object.
226
		</p>
L
looeee 已提交
227

228
		<h3>[method:Object3D getObjectByName]( [param:String name] )</h3>
229
		<p>
J
Jing Ma 已提交
230
		name -- String to match to the children's Object3D.name property. <br /><br />
L
looeee 已提交
231 232

		Searches through the object's children and returns the first with a matching name.<br />
233
		Note that for most objects the name is an empty string by default. You will
L
looeee 已提交
234
		have to set it manually to make use of this method.
235
		</p>
236

237
		<h3>[method:Object3D getObjectByProperty]( [param:String name], [param:Float value] )</h3>
238
		<p>
L
looeee 已提交
239 240 241
		name -- the property name to search for. <br />
		value -- value of the given property. <br /><br />

J
Jing Ma 已提交
242
		Searches through the object's children and returns the first with a property that matches the value given.
243
		</p>
L
looeee 已提交
244

M
Mr.doob 已提交
245
		<h3>[method:Vector3 getWorldPosition]( [param:Vector3 target] )</h3>
246
		<p>
W
WestLangley 已提交
247
		[page:Vector3 target] — the result will be copied into this Vector3. <br /><br />
L
looeee 已提交
248 249

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

M
Mr.doob 已提交
252
		<h3>[method:Quaternion getWorldQuaternion]( [param:Quaternion target] )</h3>
253
		<p>
W
WestLangley 已提交
254
		[page:Quaternion target] — the result will be copied into this Quaternion. <br /><br />
L
looeee 已提交
255 256

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

M
Mr.doob 已提交
259
		<h3>[method:Vector3 getWorldScale]( [param:Vector3 target] )</h3>
260
		<p>
W
WestLangley 已提交
261
		[page:Vector3 target] — the result will be copied into this Vector3. <br /><br />
L
looeee 已提交
262 263

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

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

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

L
looeee 已提交
273

274
		<h3>[method:Vector3 localToWorld]( [param:Vector3 vector] )</h3>
275
		<p>
T
Tentone 已提交
276
		vector - A vector representing a position in local (object) space.<br /><br />
277

L
looeee 已提交
278
		Converts the vector from local space to world space.
279
		</p>
280

281 282
		<h3>[method:null lookAt]( [param:Vector3 vector] )</br>
		[method:null lookAt]( [param:Float x], [param:Float y], [param:Float z] )</h3>
283
		<p>
L
looeee 已提交
284
		vector - A vector representing a position in world space.<br /><br />
W
WestLangley 已提交
285 286 287 288
		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 已提交
289
		This method does not support objects having non-uniformly-scaled parent(s).
290
		</p>
L
looeee 已提交
291

292
		<h3>[method:Array raycast]( [param:Raycaster raycaster], [param:Array intersects] )</h3>
293
		<p>
L
looeee 已提交
294 295 296
		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.
297
		</p>
298

299
		<h3>[method:null remove]( [param:Object3D object], ... )</h3>
300
		<p>
301
		Removes *object* as child of this object. An arbitrary number of objects may be removed.
302
		</p>
303

304
		<h3>[method:this rotateOnAxis]( [param:Vector3 axis], [param:Float angle] )</h3>
305
		<p>
L
looeee 已提交
306 307
		axis -- A normalized vector in object space. <br />
		angle -- The angle in radians.<br /><br />
308

L
looeee 已提交
309
		Rotate an object along an axis in object space. The axis is assumed to be normalized.
310
		</p>
311

312
		<h3>[method:this rotateOnWorldAxis]( [param:Vector3 axis], [param:Float angle] )</h3>
313
		<p>
314 315 316 317 318
		axis -- A normalized vector in world space. <br />
		angle -- The angle in radians.<br /><br />

		Rotate an object along an axis in world space. The axis is assumed to be normalized.
		Method Assumes no rotated parent.
319
		</p>
320

321
		<h3>[method:this rotateX]( [param:Float rad] )</h3>
322
		<p>
L
looeee 已提交
323
		rad - the angle to rotate in radians.<br /><br />
324

L
looeee 已提交
325
		Rotates the object around x axis in local space.
326
		</p>
327

328
		<h3>[method:this rotateY]( [param:Float rad] )</h3>
329
		<p>
L
looeee 已提交
330
		rad - the angle to rotate in radians.<br /><br />
331

L
looeee 已提交
332
		Rotates the object around y axis in local space.
333
		</p>
334

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

L
looeee 已提交
339
		Rotates the object around z axis in local space.
340
		</p>
341

342
		<h3>[method:null setRotationFromAxisAngle]( [param:Vector3 axis], [param:Float angle] )</h3>
343
		<p>
L
looeee 已提交
344 345
			axis -- A normalized vector in object space. <br />
			angle -- angle in radians<br /><br />
346

L
looeee 已提交
347 348
			Calls [page:Quaternion.setFromAxisAngle setFromAxisAngle]( [page:Float axis], [page:Float angle] )
			on the [page:.quaternion].
349
		</p>
350

351
		<h3>[method:null setRotationFromEuler]( [param:Euler euler] )</h3>
352
		<p>
L
looeee 已提交
353
			euler -- Euler angle specifying rotation amount.<br />
354

L
looeee 已提交
355 356
			Calls [page:Quaternion.setRotationFromEuler setRotationFromEuler]( [page:Euler euler])
			on the [page:.quaternion].
357
		</p>
L
looeee 已提交
358

359
		<h3>[method:null setRotationFromMatrix]( [param:Matrix4 m] )</h3>
360
		<p>
L
looeee 已提交
361 362 363 364 365 366
			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).
367
		</p>
368

369
		<h3>[method:null setRotationFromQuaternion]( [param:Quaternion q] )</h3>
370
		<p>
L
looeee 已提交
371 372 373
			q -- normalized Quaternion.<br /><br />

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

376
		<h3>[method:null toJSON]( [param:Quaternion q] )</h3>
377
		<p>
L
looeee 已提交
378
			Convert the object to JSON format.
379
		</p>
380

381
		<h3>[method:this translateOnAxis]( [param:Vector3 axis], [param:Float distance] )</h3>
382
		<p>
G
Greg Tatum 已提交
383
		axis -- A normalized vector in object space.<br />
L
looeee 已提交
384 385 386
		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.
387
		</p>
L
looeee 已提交
388

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

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

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

398
		<h3>[method:null traverse]( [param:Function callback] )</h3>
399
		<p>
L
looeee 已提交
400 401 402
		callback - A function with as first argument an object3D object.<br /><br />

		Executes the callback on this object and all descendants.
403
		</p>
404

405
		<h3>[method:null traverseVisible]( [param:Function callback] )</h3>
406
		<p>
L
looeee 已提交
407 408 409 410
		callback - A function with as first argument an object3D object.<br /><br />

		Like traverse, but the callback will only be executed for visible objects.
		Descendants of invisible objects are not traversed.
411
		</p>
L
looeee 已提交
412

413
		<h3>[method:null traverseAncestors]( [param:Function callback] )</h3>
414
		<p>
L
looeee 已提交
415 416 417
		callback - A function with as first argument an object3D object.<br /><br />

		Executes the callback on all ancestors.
418
		</p>
C
cjshannon 已提交
419

L
looeee 已提交
420
		<h3>[method:null updateMatrix]()</h3>
421
		<p>Update the local transform.</p>
L
looeee 已提交
422

423
		<h3>[method:null updateMatrixWorld]( [param:Boolean force] )</h3>
424
		<p>Update the global transform of the object and its children.</p>
L
looeee 已提交
425 426


427
		<h3>[method:Vector3 worldToLocal]( [param:Vector3 vector] )</h3>
428
		<p>
L
looeee 已提交
429 430 431
		vector - A world vector.<br /><br />

		Updates the vector from world space to local space.
432
		</p>
433

434 435 436 437 438
		<h2>Source</h2>

		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
	</body>
</html>