Geometry.rst 5.5 KB

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