Geometry.d.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. import { Vector3 } from './../math/Vector3';
  2. import { Color } from './../math/Color';
  3. import { Face3, Event } from './Face3';
  4. import { Vector2 } from './../math/Vector2';
  5. import { Vector4 } from './../math/Vector4';
  6. import { Box3 } from './../math/Box3';
  7. import { Sphere } from './../math/Sphere';
  8. import { Matrix4 } from './../math/Matrix4';
  9. import { BufferGeometry } from './BufferGeometry';
  10. import { Matrix } from './../math/Matrix3';
  11. import { Mesh } from './../objects/Mesh';
  12. import { Bone } from './../objects/Bone';
  13. import { AnimationClip } from './../animation/AnimationClip';
  14. import { EventDispatcher } from './EventDispatcher';
  15. /**
  16. * @deprecated Use {@link Face3} instead.
  17. */
  18. export interface MorphTarget {
  19. name: string;
  20. vertices: Vector3[];
  21. }
  22. export interface MorphColor {
  23. name: string;
  24. colors: Color[];
  25. }
  26. export interface MorphNormals {
  27. name: string;
  28. normals: Vector3[];
  29. }
  30. export let GeometryIdCount: number;
  31. /**
  32. * Base class for geometries
  33. *
  34. * # Example
  35. * var geometry = new THREE.Geometry();
  36. * geometry.vertices.push( new THREE.Vector3( -10, 10, 0 ) );
  37. * geometry.vertices.push( new THREE.Vector3( -10, -10, 0 ) );
  38. * geometry.vertices.push( new THREE.Vector3( 10, -10, 0 ) );
  39. * geometry.faces.push( new THREE.Face3( 0, 1, 2 ) );
  40. * geometry.computeBoundingSphere();
  41. *
  42. * @see https://github.com/mrdoob/three.js/blob/master/src/core/Geometry.js
  43. */
  44. export class Geometry extends EventDispatcher {
  45. constructor();
  46. /**
  47. * Unique number of this geometry instance
  48. */
  49. id: number;
  50. uuid: string;
  51. /**
  52. * Name for this geometry. Default is an empty string.
  53. */
  54. name: string;
  55. type: string;
  56. /**
  57. * The array of vertices hold every position of points of the model.
  58. * To signal an update in this array, Geometry.verticesNeedUpdate needs to be set to true.
  59. */
  60. vertices: Vector3[];
  61. /**
  62. * Array of vertex colors, matching number and order of vertices.
  63. * Used in ParticleSystem, Line and Ribbon.
  64. * Meshes use per-face-use-of-vertex colors embedded directly in faces.
  65. * To signal an update in this array, Geometry.colorsNeedUpdate needs to be set to true.
  66. */
  67. colors: Color[];
  68. /**
  69. * Array of triangles or/and quads.
  70. * The array of faces describe how each vertex in the model is connected with each other.
  71. * To signal an update in this array, Geometry.elementsNeedUpdate needs to be set to true.
  72. */
  73. faces: Face3[];
  74. /**
  75. * Array of face UV layers.
  76. * Each UV layer is an array of UV matching order and number of vertices in faces.
  77. * To signal an update in this array, Geometry.uvsNeedUpdate needs to be set to true.
  78. */
  79. faceVertexUvs: Vector2[][][];
  80. /**
  81. * Array of morph targets. Each morph target is a Javascript object:
  82. *
  83. * { name: "targetName", vertices: [ new THREE.Vector3(), ... ] }
  84. *
  85. * Morph vertices match number and order of primary vertices.
  86. */
  87. morphTargets: MorphTarget[];
  88. /**
  89. * Array of morph normals. Morph normals have similar structure as morph targets, each normal set is a Javascript object:
  90. *
  91. * morphNormal = { name: "NormalName", normals: [ new THREE.Vector3(), ... ] }
  92. */
  93. morphNormals: MorphNormals[];
  94. /**
  95. * Array of skinning weights, matching number and order of vertices.
  96. */
  97. skinWeights: Vector4[];
  98. /**
  99. * Array of skinning indices, matching number and order of vertices.
  100. */
  101. skinIndices: Vector4[];
  102. /**
  103. *
  104. */
  105. lineDistances: number[];
  106. /**
  107. * Bounding box.
  108. */
  109. boundingBox: Box3;
  110. /**
  111. * Bounding sphere.
  112. */
  113. boundingSphere: Sphere;
  114. /**
  115. * Set to true if the vertices array has been updated.
  116. */
  117. verticesNeedUpdate: boolean;
  118. /**
  119. * Set to true if the faces array has been updated.
  120. */
  121. elementsNeedUpdate: boolean;
  122. /**
  123. * Set to true if the uvs array has been updated.
  124. */
  125. uvsNeedUpdate: boolean;
  126. /**
  127. * Set to true if the normals array has been updated.
  128. */
  129. normalsNeedUpdate: boolean;
  130. /**
  131. * Set to true if the colors array has been updated.
  132. */
  133. colorsNeedUpdate: boolean;
  134. /**
  135. * Set to true if the linedistances array has been updated.
  136. */
  137. lineDistancesNeedUpdate: boolean;
  138. /**
  139. *
  140. */
  141. groupsNeedUpdate: boolean;
  142. /**
  143. * Bakes matrix transform directly into vertex coordinates.
  144. */
  145. applyMatrix(matrix: Matrix4): Geometry;
  146. rotateX(angle: number): Geometry;
  147. rotateY(angle: number): Geometry;
  148. rotateZ(angle: number): Geometry;
  149. translate(x: number, y: number, z: number): Geometry;
  150. scale(x: number, y: number, z: number): Geometry;
  151. lookAt(vector: Vector3): void;
  152. fromBufferGeometry(geometry: BufferGeometry): Geometry;
  153. center(): Geometry;
  154. normalize(): Geometry;
  155. /**
  156. * Computes face normals.
  157. */
  158. computeFaceNormals(): void;
  159. /**
  160. * Computes vertex normals by averaging face normals.
  161. * Face normals must be existing / computed beforehand.
  162. */
  163. computeVertexNormals(areaWeighted?: boolean): void;
  164. /**
  165. * Compute vertex normals, but duplicating face normals.
  166. */
  167. computeFlatVertexNormals(): void;
  168. /**
  169. * Computes morph normals.
  170. */
  171. computeMorphNormals(): void;
  172. /**
  173. * Computes bounding box of the geometry, updating {@link Geometry.boundingBox} attribute.
  174. */
  175. computeBoundingBox(): void;
  176. /**
  177. * Computes bounding sphere of the geometry, updating Geometry.boundingSphere attribute.
  178. * Neither bounding boxes or bounding spheres are computed by default. They need to be explicitly computed, otherwise they are null.
  179. */
  180. computeBoundingSphere(): void;
  181. merge(
  182. geometry: Geometry,
  183. matrix?: Matrix,
  184. materialIndexOffset?: number
  185. ): void;
  186. mergeMesh(mesh: Mesh): void;
  187. /**
  188. * Checks for duplicate vertices using hashmap.
  189. * Duplicated vertices are removed and faces' vertices are updated.
  190. */
  191. mergeVertices(): number;
  192. setFromPoints(points: Array<Vector2> | Array<Vector3>): this;
  193. sortFacesByMaterialIndex(): void;
  194. toJSON(): any;
  195. /**
  196. * Creates a new clone of the Geometry.
  197. */
  198. clone(): this;
  199. copy(source: Geometry): this;
  200. /**
  201. * Removes The object from memory.
  202. * Don't forget to call this method when you remove an geometry because it can cuase meomory leaks.
  203. */
  204. dispose(): void;
  205. // These properties do not exist in a normal Geometry class, but if you use the instance that was passed by JSONLoader, it will be added.
  206. bones: Bone[];
  207. animation: AnimationClip;
  208. animations: AnimationClip[];
  209. // EventDispatcher mixins
  210. addEventListener(type: string, listener: (event: Event) => void): void;
  211. hasEventListener(type: string, listener: (event: Event) => void): boolean;
  212. removeEventListener(type: string, listener: (event: Event) => void): void;
  213. dispatchEvent(event: { type: string; [attachment: string]: any }): void;
  214. }