Geometry.rst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. Geometry - Base class for geometries
  2. ----------------------------------------
  3. .. rubric:: Constructor
  4. .. class:: Geometry()
  5. Base class for geometries
  6. Encapsulates unique instances of vertex buffer objects in :class:`WebGLRenderer`
  7. .. rubric:: Attributes
  8. .. attribute:: Geometry.id
  9. Unique number of this geometry instance
  10. .. attribute:: Geometry.boundingBox
  11. Bounding box
  12. ::
  13. boundingBox = { min: new THREE.Vector3(), max: new THREE.Vector3() }
  14. .. attribute:: Geometry.boundingSphere
  15. Bounding sphere
  16. ::
  17. boundingSphere = { radius: float }
  18. .. attribute:: Geometry.materials
  19. Array of :class:`materials <Material>`
  20. Used with models containing multiple materials in a single geometry (with pass-through :class:`MeshFaceMaterial`)
  21. Face indices index into this array.
  22. .. rubric:: Attribute buffers
  23. .. attribute:: Geometry.faces
  24. Array of faces (:class:`Face3`, :class:`Face4`)
  25. .. attribute:: Geometry.vertices
  26. Array of :class:`vertices <Vertex>`
  27. Face indices index into this array.
  28. .. attribute:: Geometry.colors
  29. Array of vertex :class:`colors <Color>`, matching number and order of vertices.
  30. Used in :class:`ParticleSystem`, :class:`Line` and :class:`Ribbon`.
  31. :class:`Meshes <Mesh>` use per-face-use-of-vertex colors embedded directly in faces.
  32. .. attribute:: Geometry.faceUvs
  33. Array of face UV layers.
  34. Each UV layer is an array of :class:`UV` matching order and number of faces.
  35. .. attribute:: Geometry.faceVertexUvs
  36. Array of vertex UV layers.
  37. Each UV layer is an array of :class:`UV` matching order and number of vertices in faces.
  38. .. attribute:: Geometry.morphTargets
  39. Array of morph targets.
  40. Each morph target is JS object:
  41. ::
  42. morphTarget = { name: "targetName", vertices: [ new THREE.Vertex(), ... ] }
  43. Morph vertices match number and order of primary vertices.
  44. .. attribute:: Geometry.morphColors
  45. Array of morph colors.
  46. Morph colors have similar structure as morph targets, each color set is JS object:
  47. ::
  48. morphColor = { name: "colorName", colors: [ new THREE.Color(), ... ] }
  49. Morph colors can match either number and order of faces (face colors) or number of vertices (vertex colors).
  50. .. attribute:: Geometry.skinWeights
  51. Array of skinning weights (:class:`Vector4`), matching number and order of vertices.
  52. .. attribute:: Geometry.skinIndices
  53. Array of skinning indices (:class:`Vector4`), matching number and order of vertices.
  54. .. rubric:: Flags
  55. .. attribute:: Geometry.hasTangents
  56. True if geometry has tangents. Set in :func:`Geometry.computeTangents`
  57. ``default false``
  58. .. attribute:: Geometry.dynamic
  59. Set to `true` if attribute buffers will need to change in runtime (using ``dirty`` flags).
  60. Unless set to true internal typed arrays corresponding to buffers will be deleted once sent to GPU.
  61. ``default false``
  62. .. rubric:: Methods
  63. .. function:: Geometry.applyMatrix( matrix )
  64. Bake matrix transform directly into vertex coordinates
  65. :param Matrix4 matrix: matrix transform
  66. .. function:: Geometry.computeCentroids()
  67. Compute centroids for all faces
  68. .. function:: Geometry.computeFaceNormals()
  69. Compute face normals
  70. .. function:: Geometry.computeVertexNormals()
  71. Compute vertex normals by averaging face normals.
  72. Face normals must be existing / computed beforehand.
  73. .. function:: Geometry.computeTangents()
  74. Compute vertex tangents
  75. Based on http://www.terathon.com/code/tangent.html
  76. Geometry must have vertex UVs (layer 0 will be used).
  77. .. function:: Geometry.computeBoundingBox()
  78. Compute bounding box of the geometry, updating :attr:`Geometry.boundingBox` attribute.
  79. .. function:: Geometry.computeBoundingSphere()
  80. Compute bounding sphere of the geometry, updating :attr:`Geometry.boundingSphere` attribute.
  81. .. function:: Geometry.mergeVertices()
  82. Checks for duplicate vertices using hashmap.
  83. Duplicated vertices are removed and faces' vertices are updated.
  84. .. rubric:: Example
  85. ::
  86. // geometry with random points
  87. // (useful for example with ParticleSystem)
  88. var n = 10000;
  89. var geometry = new THREE.Geometry()
  90. for ( var i = 0; i < n; i ++ ) {
  91. var x = THREE.MathUtils.randFloatSpread( 1000 );
  92. var y = THREE.MathUtils.randFloatSpread( 1000 );
  93. var z = THREE.MathUtils.randFloatSpread( 1000 );
  94. var position = new THREE.Vector3( x, y, z );
  95. var vertex = new THREE.Vertex( position );
  96. geometry.vertices.push( vertex );
  97. }
  98. geometry.computeBoundingSphere();