Object3D.d.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. import { Vector3 } from './../math/Vector3';
  2. import { Euler } from './../math/Euler';
  3. import { Quaternion } from './../math/Quaternion';
  4. import { Matrix4 } from './../math/Matrix4';
  5. import { Matrix3 } from './../math/Matrix3';
  6. import { Layers } from './Layers';
  7. import { WebGLRenderer } from './../renderers/WebGLRenderer';
  8. import { Scene } from './../scenes/Scene';
  9. import { Camera } from './../cameras/Camera';
  10. import { Geometry } from './Geometry';
  11. import { Material } from './../materials/Material';
  12. import { Group } from './../objects/Group';
  13. import { Raycaster } from './Raycaster';
  14. import { EventDispatcher } from './EventDispatcher';
  15. import { BufferGeometry } from './BufferGeometry';
  16. import { Intersection } from './Raycaster';
  17. export let Object3DIdCount: number;
  18. /**
  19. * Base class for scene graph objects
  20. */
  21. export class Object3D extends EventDispatcher {
  22. constructor();
  23. /**
  24. * Unique number of this object instance.
  25. */
  26. id: number;
  27. /**
  28. *
  29. */
  30. uuid: string;
  31. /**
  32. * Optional name of the object (doesn't need to be unique).
  33. * @default ''
  34. */
  35. name: string;
  36. /**
  37. * @default 'Object3D'
  38. */
  39. type: string;
  40. /**
  41. * Object's parent in the scene graph.
  42. * @default null
  43. */
  44. parent: Object3D | null;
  45. /**
  46. * Array with object's children.
  47. * @default []
  48. */
  49. children: Object3D[];
  50. /**
  51. * Up direction.
  52. * @default THREE.Object3D.DefaultUp.clone()
  53. */
  54. up: Vector3;
  55. /**
  56. * Object's local position.
  57. * @default new THREE.Vector3()
  58. */
  59. readonly position: Vector3;
  60. /**
  61. * Object's local rotation (Euler angles), in radians.
  62. * @default new THREE.Euler()
  63. */
  64. readonly rotation: Euler;
  65. /**
  66. * Global rotation.
  67. * @default new THREE.Quaternion()
  68. */
  69. readonly quaternion: Quaternion;
  70. /**
  71. * Object's local scale.
  72. * @default new THREE.Vector3()
  73. */
  74. readonly scale: Vector3;
  75. /**
  76. * @default new THREE.Matrix4()
  77. */
  78. readonly modelViewMatrix: Matrix4;
  79. /**
  80. * @default new THREE.Matrix3()
  81. */
  82. readonly normalMatrix: Matrix3;
  83. /**
  84. * Local transform.
  85. * @default new THREE.Matrix4()
  86. */
  87. matrix: Matrix4;
  88. /**
  89. * The global transform of the object. If the Object3d has no parent, then it's identical to the local transform.
  90. * @default new THREE.Matrix4()
  91. */
  92. matrixWorld: Matrix4;
  93. /**
  94. * When this is set, it calculates the matrix of position, (rotation or quaternion) and scale every frame and also recalculates the matrixWorld property.
  95. * @default THREE.Object3D.DefaultMatrixAutoUpdate
  96. */
  97. matrixAutoUpdate: boolean;
  98. /**
  99. * When this is set, it calculates the matrixWorld in that frame and resets this property to false.
  100. * @default false
  101. */
  102. matrixWorldNeedsUpdate: boolean;
  103. /**
  104. * @default new THREE.Layers()
  105. */
  106. layers: Layers;
  107. /**
  108. * Object gets rendered if true.
  109. * @default true
  110. */
  111. visible: boolean;
  112. /**
  113. * Gets rendered into shadow map.
  114. * @default false
  115. */
  116. castShadow: boolean;
  117. /**
  118. * Material gets baked in shadow receiving.
  119. * @default false
  120. */
  121. receiveShadow: boolean;
  122. /**
  123. * 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.
  124. * @default true
  125. */
  126. frustumCulled: boolean;
  127. /**
  128. * 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.
  129. * @default 0
  130. */
  131. renderOrder: number;
  132. /**
  133. * 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.
  134. * @default {}
  135. */
  136. userData: { [key: string]: any };
  137. /**
  138. * Custom depth material to be used when rendering to the depth map. Can only be used in context of meshes.
  139. * When shadow-casting with a DirectionalLight or SpotLight, if you are (a) modifying vertex positions in
  140. * the vertex shader, (b) using a displacement map, (c) using an alpha map with alphaTest, or (d) using a
  141. * transparent texture with alphaTest, you must specify a customDepthMaterial for proper shadows.
  142. */
  143. customDepthMaterial: Material;
  144. /**
  145. * Same as customDepthMaterial, but used with PointLight.
  146. */
  147. customDistanceMaterial: Material;
  148. /**
  149. * Used to check whether this or derived classes are Object3Ds. Default is true.
  150. * You should not change this, as it is used internally for optimisation.
  151. */
  152. readonly isObject3D: true;
  153. /**
  154. * Calls before rendering object
  155. */
  156. onBeforeRender: (
  157. renderer: WebGLRenderer,
  158. scene: Scene,
  159. camera: Camera,
  160. geometry: Geometry | BufferGeometry,
  161. material: Material,
  162. group: Group
  163. ) => void;
  164. /**
  165. * Calls after rendering object
  166. */
  167. onAfterRender: (
  168. renderer: WebGLRenderer,
  169. scene: Scene,
  170. camera: Camera,
  171. geometry: Geometry | BufferGeometry,
  172. material: Material,
  173. group: Group
  174. ) => void;
  175. static DefaultUp: Vector3;
  176. static DefaultMatrixAutoUpdate: boolean;
  177. /**
  178. * This updates the position, rotation and scale with the matrix.
  179. */
  180. applyMatrix4( matrix: Matrix4 ): void;
  181. applyQuaternion( quaternion: Quaternion ): this;
  182. /**
  183. *
  184. */
  185. setRotationFromAxisAngle( axis: Vector3, angle: number ): void;
  186. /**
  187. *
  188. */
  189. setRotationFromEuler( euler: Euler ): void;
  190. /**
  191. *
  192. */
  193. setRotationFromMatrix( m: Matrix4 ): void;
  194. /**
  195. *
  196. */
  197. setRotationFromQuaternion( q: Quaternion ): void;
  198. /**
  199. * Rotate an object along an axis in object space. The axis is assumed to be normalized.
  200. * @param axis A normalized vector in object space.
  201. * @param angle The angle in radians.
  202. */
  203. rotateOnAxis( axis: Vector3, angle: number ): this;
  204. /**
  205. * Rotate an object along an axis in world space. The axis is assumed to be normalized. Method Assumes no rotated parent.
  206. * @param axis A normalized vector in object space.
  207. * @param angle The angle in radians.
  208. */
  209. rotateOnWorldAxis( axis: Vector3, angle: number ): this;
  210. /**
  211. *
  212. * @param angle
  213. */
  214. rotateX( angle: number ): this;
  215. /**
  216. *
  217. * @param angle
  218. */
  219. rotateY( angle: number ): this;
  220. /**
  221. *
  222. * @param angle
  223. */
  224. rotateZ( angle: number ): this;
  225. /**
  226. * @param axis A normalized vector in object space.
  227. * @param distance The distance to translate.
  228. */
  229. translateOnAxis( axis: Vector3, distance: number ): this;
  230. /**
  231. * Translates object along x axis by distance.
  232. * @param distance Distance.
  233. */
  234. translateX( distance: number ): this;
  235. /**
  236. * Translates object along y axis by distance.
  237. * @param distance Distance.
  238. */
  239. translateY( distance: number ): this;
  240. /**
  241. * Translates object along z axis by distance.
  242. * @param distance Distance.
  243. */
  244. translateZ( distance: number ): this;
  245. /**
  246. * Updates the vector from local space to world space.
  247. * @param vector A local vector.
  248. */
  249. localToWorld( vector: Vector3 ): Vector3;
  250. /**
  251. * Updates the vector from world space to local space.
  252. * @param vector A world vector.
  253. */
  254. worldToLocal( vector: Vector3 ): Vector3;
  255. /**
  256. * Rotates object to face point in space.
  257. * @param vector A world vector to look at.
  258. */
  259. lookAt( vector: Vector3 | number, y?: number, z?: number ): void;
  260. /**
  261. * Adds object as child of this object.
  262. */
  263. add( ...object: Object3D[] ): this;
  264. /**
  265. * Removes object as child of this object.
  266. */
  267. remove( ...object: Object3D[] ): this;
  268. /**
  269. * Adds object as a child of this, while maintaining the object's world transform.
  270. */
  271. attach( object: Object3D ): this;
  272. /**
  273. * Searches through the object's children and returns the first with a matching id.
  274. * @param id Unique number of the object instance
  275. */
  276. getObjectById( id: number ): Object3D | undefined;
  277. /**
  278. * Searches through the object's children and returns the first with a matching name.
  279. * @param name String to match to the children's Object3d.name property.
  280. */
  281. getObjectByName( name: string ): Object3D | undefined;
  282. getObjectByProperty( name: string, value: string ): Object3D | undefined;
  283. getWorldPosition( target: Vector3 ): Vector3;
  284. getWorldQuaternion( target: Quaternion ): Quaternion;
  285. getWorldScale( target: Vector3 ): Vector3;
  286. getWorldDirection( target: Vector3 ): Vector3;
  287. raycast( raycaster: Raycaster, intersects: Intersection[] ): void;
  288. traverse( callback: ( object: Object3D ) => any ): void;
  289. traverseVisible( callback: ( object: Object3D ) => any ): void;
  290. traverseAncestors( callback: ( object: Object3D ) => any ): void;
  291. /**
  292. * Updates local transform.
  293. */
  294. updateMatrix(): void;
  295. /**
  296. * Updates global transform of the object and its children.
  297. */
  298. updateMatrixWorld( force?: boolean ): void;
  299. updateWorldMatrix( updateParents: boolean, updateChildren: boolean ): void;
  300. toJSON( meta?: {
  301. geometries: any;
  302. materials: any;
  303. textures: any;
  304. images: any;
  305. } ): any;
  306. clone( recursive?: boolean ): this;
  307. /**
  308. *
  309. * @param object
  310. * @param recursive
  311. */
  312. copy( source: this, recursive?: boolean ): this;
  313. }