Geometry.d.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. import {
  2. Vector3,
  3. Color,
  4. Vector2,
  5. Vector4,
  6. Box3,
  7. Sphere,
  8. Matrix4,
  9. BufferGeometry,
  10. Matrix,
  11. Mesh,
  12. Bone,
  13. AnimationClip,
  14. EventDispatcher,
  15. Object3D
  16. } from '../../../src/Three';
  17. /**
  18. * @deprecated Use Face3 instead.
  19. */
  20. export interface MorphTarget {
  21. name: string;
  22. vertices: Vector3[];
  23. }
  24. export interface MorphColor {
  25. name: string;
  26. colors: Color[];
  27. }
  28. export interface MorphNormals {
  29. name: string;
  30. normals: Vector3[];
  31. }
  32. /**
  33. * Base class for geometries
  34. */
  35. export class Geometry extends EventDispatcher {
  36. constructor();
  37. /**
  38. * Unique number of this geometry instance
  39. */
  40. id: number;
  41. uuid: string;
  42. readonly isGeometry: true;
  43. /**
  44. * Name for this geometry. Default is an empty string.
  45. * @default ''
  46. */
  47. name: string;
  48. /**
  49. * @default 'Geometry'
  50. */
  51. type: string;
  52. /**
  53. * The array of vertices hold every position of points of the model.
  54. * To signal an update in this array, Geometry.verticesNeedUpdate needs to be set to true.
  55. * @default []
  56. */
  57. vertices: Vector3[];
  58. /**
  59. * Array of vertex colors, matching number and order of vertices.
  60. * Used in ParticleSystem, Line and Ribbon.
  61. * Meshes use per-face-use-of-vertex colors embedded directly in faces.
  62. * To signal an update in this array, Geometry.colorsNeedUpdate needs to be set to true.
  63. * @default []
  64. */
  65. colors: Color[];
  66. /**
  67. * Array of triangles or/and quads.
  68. * The array of faces describe how each vertex in the model is connected with each other.
  69. * To signal an update in this array, Geometry.elementsNeedUpdate needs to be set to true.
  70. * @default []
  71. */
  72. faces: Face3[];
  73. /**
  74. * Array of face UV layers.
  75. * Each UV layer is an array of UV matching order and number of vertices in faces.
  76. * To signal an update in this array, Geometry.uvsNeedUpdate needs to be set to true.
  77. * @default [[]]
  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. * @default []
  87. */
  88. morphTargets: MorphTarget[];
  89. /**
  90. * Array of morph normals. Morph normals have similar structure as morph targets, each normal set is a Javascript object:
  91. *
  92. * morphNormal = { name: "NormalName", normals: [ new THREE.Vector3(), ... ] }
  93. * @default []
  94. */
  95. morphNormals: MorphNormals[];
  96. /**
  97. * Array of skinning weights, matching number and order of vertices.
  98. * @default []
  99. */
  100. skinWeights: Vector4[];
  101. /**
  102. * Array of skinning indices, matching number and order of vertices.
  103. * @default []
  104. */
  105. skinIndices: Vector4[];
  106. /**
  107. * @default []
  108. */
  109. lineDistances: number[];
  110. /**
  111. * Bounding box.
  112. * @default null
  113. */
  114. boundingBox: Box3 | null;
  115. /**
  116. * Bounding sphere.
  117. * @default null
  118. */
  119. boundingSphere: Sphere | null;
  120. /**
  121. * Set to true if the vertices array has been updated.
  122. * @default false
  123. */
  124. verticesNeedUpdate: boolean;
  125. /**
  126. * Set to true if the faces array has been updated.
  127. * @default false
  128. */
  129. elementsNeedUpdate: boolean;
  130. /**
  131. * Set to true if the uvs array has been updated.
  132. * @default false
  133. */
  134. uvsNeedUpdate: boolean;
  135. /**
  136. * Set to true if the normals array has been updated.
  137. * @default false
  138. */
  139. normalsNeedUpdate: boolean;
  140. /**
  141. * Set to true if the colors array has been updated.
  142. * @default false
  143. */
  144. colorsNeedUpdate: boolean;
  145. /**
  146. * Set to true if the linedistances array has been updated.
  147. * @default false
  148. */
  149. lineDistancesNeedUpdate: boolean;
  150. /**
  151. *
  152. * @default false
  153. */
  154. groupsNeedUpdate: boolean;
  155. /**
  156. * Bakes matrix transform directly into vertex coordinates.
  157. */
  158. applyMatrix4( matrix: Matrix4 ): Geometry;
  159. rotateX( angle: number ): Geometry;
  160. rotateY( angle: number ): Geometry;
  161. rotateZ( angle: number ): Geometry;
  162. translate( x: number, y: number, z: number ): Geometry;
  163. scale( x: number, y: number, z: number ): Geometry;
  164. lookAt( vector: Vector3 ): void;
  165. fromBufferGeometry( geometry: BufferGeometry ): Geometry;
  166. center(): Geometry;
  167. normalize(): Geometry;
  168. /**
  169. * Computes face normals.
  170. */
  171. computeFaceNormals(): void;
  172. /**
  173. * Computes vertex normals by averaging face normals.
  174. * Face normals must be existing / computed beforehand.
  175. */
  176. computeVertexNormals( areaWeighted?: boolean ): void;
  177. /**
  178. * Compute vertex normals, but duplicating face normals.
  179. */
  180. computeFlatVertexNormals(): void;
  181. /**
  182. * Computes morph normals.
  183. */
  184. computeMorphNormals(): void;
  185. /**
  186. * Computes bounding box of the geometry, updating {@link Geometry.boundingBox} attribute.
  187. */
  188. computeBoundingBox(): void;
  189. /**
  190. * Computes bounding sphere of the geometry, updating Geometry.boundingSphere attribute.
  191. * Neither bounding boxes or bounding spheres are computed by default. They need to be explicitly computed, otherwise they are null.
  192. */
  193. computeBoundingSphere(): void;
  194. merge(
  195. geometry: Geometry,
  196. matrix?: Matrix,
  197. materialIndexOffset?: number
  198. ): void;
  199. mergeMesh( mesh: Mesh ): void;
  200. /**
  201. * Checks for duplicate vertices using hashmap for specified number of decimal points, e.g. 4 for epsilon of 0.0001
  202. * Duplicated vertices are removed and faces' vertices are updated.
  203. */
  204. mergeVertices( precisionPoints?: number ): number;
  205. setFromPoints( points: Array<Vector2> | Array<Vector3> ): this;
  206. sortFacesByMaterialIndex(): void;
  207. toBufferGeometry(): BufferGeometry;
  208. static createBufferGeometryFromObject( object: Object3D ): BufferGeometry;
  209. toJSON(): any;
  210. /**
  211. * Creates a new clone of the Geometry.
  212. */
  213. clone(): Geometry;
  214. copy( source: Geometry ): this;
  215. /**
  216. * Removes The object from memory.
  217. * Don't forget to call this method when you remove an geometry because it can cuase meomory leaks.
  218. */
  219. dispose(): void;
  220. // 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.
  221. bones: Bone[];
  222. animation: AnimationClip;
  223. animations: AnimationClip[];
  224. }
  225. /**
  226. * Triangle face.
  227. */
  228. export class Face3 {
  229. /**
  230. * @param a Vertex A index.
  231. * @param b Vertex B index.
  232. * @param c Vertex C index.
  233. * @param normal Face normal or array of vertex normals.
  234. * @param color Face color or array of vertex colors.
  235. * @param materialIndex Material index.
  236. */
  237. constructor(
  238. a: number,
  239. b: number,
  240. c: number,
  241. normal?: Vector3,
  242. color?: Color,
  243. materialIndex?: number
  244. );
  245. constructor(
  246. a: number,
  247. b: number,
  248. c: number,
  249. normal?: Vector3,
  250. vertexColors?: Color[],
  251. materialIndex?: number
  252. );
  253. constructor(
  254. a: number,
  255. b: number,
  256. c: number,
  257. vertexNormals?: Vector3[],
  258. color?: Color,
  259. materialIndex?: number
  260. );
  261. constructor(
  262. a: number,
  263. b: number,
  264. c: number,
  265. vertexNormals?: Vector3[],
  266. vertexColors?: Color[],
  267. materialIndex?: number
  268. );
  269. /**
  270. * Vertex A index.
  271. */
  272. a: number;
  273. /**
  274. * Vertex B index.
  275. */
  276. b: number;
  277. /**
  278. * Vertex C index.
  279. */
  280. c: number;
  281. /**
  282. * Face normal.
  283. * @default new THREE.Vector3()
  284. */
  285. normal: Vector3;
  286. /**
  287. * Array of 3 vertex normals.
  288. * @default []
  289. */
  290. vertexNormals: Vector3[];
  291. /**
  292. * Face color.
  293. * @default new THREE.Color()
  294. */
  295. color: Color;
  296. /**
  297. * Array of 3 vertex colors.
  298. * @default []
  299. */
  300. vertexColors: Color[];
  301. /**
  302. * Material index (points to {@link Mesh.material}).
  303. * @default 0
  304. */
  305. materialIndex: number;
  306. clone(): Face3;
  307. copy( source: Face3 ): this;
  308. }