Home Reference Source Repository

js/SceneKit/SCNPhysicsField.js

  1. 'use strict'
  2.  
  3. import NSObject from '../ObjectiveC/NSObject'
  4. //import SCNFieldForceEvaluator from './SCNFieldForceEvaluator'
  5. //import SCNVector3 from './SCNVector3'
  6. //import SCNPhysicsFieldScope from './SCNPhysicsFieldScope'
  7.  
  8. /**
  9. * An object that applies forces, such as gravitation, electromagnetism, and turbulence, to physics bodies within a certain area of effect.
  10. * @access public
  11. * @extends {NSObject}
  12. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield
  13. */
  14. export default class SCNPhysicsField extends NSObject {
  15.  
  16. /**
  17. * constructor
  18. * @access public
  19. * @constructor
  20. */
  21. constructor() {
  22. super()
  23.  
  24. // Specifying a Field’s Area of Effect
  25.  
  26. /**
  27. * A location marking the end of the field’s area of effect.
  28. * @type {SCNVector3}
  29. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388138-halfextent
  30. */
  31. this.halfExtent = null
  32.  
  33. /**
  34. * The area affected by the field, either inside or outside its region.
  35. * @type {SCNPhysicsFieldScope}
  36. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388136-scope
  37. */
  38. this.scope = null
  39.  
  40. /**
  41. * A Boolean value that determines whether the field’s area of effect is shaped like a box or ellipsoid.
  42. * @type {boolean}
  43. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388158-usesellipsoidalextent
  44. */
  45. this.usesEllipsoidalExtent = false
  46.  
  47. /**
  48. * The offset of the field’s center within its area of effect.
  49. * @type {SCNVector3}
  50. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388154-offset
  51. */
  52. this.offset = null
  53.  
  54. /**
  55. * The field’s directional axis.
  56. * @type {SCNVector3}
  57. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388128-direction
  58. */
  59. this.direction = null
  60.  
  61.  
  62. // Specifying a Field’s Behavior
  63.  
  64. /**
  65. * A multiplier for the force that the field applies to objects in its area of effect.
  66. * @type {number}
  67. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388132-strength
  68. */
  69. this.strength = 0
  70.  
  71. /**
  72. * An exponent that determines how the field’s strength diminishes with distance.
  73. * @type {number}
  74. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388146-falloffexponent
  75. */
  76. this.falloffExponent = 0
  77.  
  78. /**
  79. * The minimum value for distance-based effects.
  80. * @type {number}
  81. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388148-minimumdistance
  82. */
  83. this.minimumDistance = 0
  84.  
  85. /**
  86. * A Boolean value that determines whether the field’s effect is enabled.
  87. * @type {boolean}
  88. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388117-isactive
  89. */
  90. this.isActive = false
  91.  
  92. /**
  93. * A Boolean value that determines whether the field overrides other fields whose areas of effect it overlaps.
  94. * @type {boolean}
  95. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388126-isexclusive
  96. */
  97. this.isExclusive = false
  98.  
  99.  
  100. // Choosing Physics Bodies to Be Affected by the Field
  101.  
  102. /**
  103. * A mask that defines which categories this physics field belongs to.
  104. * @type {number}
  105. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388119-categorybitmask
  106. */
  107. this.categoryBitMask = 0
  108.  
  109. }
  110.  
  111. // Creating Physics Fields
  112.  
  113. /**
  114. * Creates a field that slows any object in its area of effect with a force proportional to the object’s velocity.
  115. * @access public
  116. * @returns {SCNPhysicsField} -
  117. * @desc Like the damping and angularDamping properties of a physics body, drag fields can simulate effects such as fluid friction or air resistance. Unlike those properties, drag fields can simulate different intensities of fluid friction in different areas of your scene. For example, you can use a drag field to represent underwater areas.The default falloffExponent value for a drag field is 0.0, indicating that the field’s effect is constant throughout its area of effect.
  118. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388164-drag
  119. */
  120. static drag() {
  121. return null
  122. }
  123.  
  124. /**
  125. * Creates a field whose forces circulate around an axis.
  126. * @access public
  127. * @returns {SCNPhysicsField} -
  128. * @desc The force on an object in a vortex field is tangential to the line from the object’s position to the field’s axis and proportional to the object’s mass. (The field’s axis is a line that is parallel to its direction vector and that passes through its center. For details, see the offset property.) For example, when a vortex field’s area of effect contains many objects, the resulting scene resembles a tornado: The objects simultaneously revolve around and fly away from the field’s center.By default, a vortex circulates counterclockwise relative to its direction vector. To make it circulate clockwise, set the field’s strength property to a negative value.The default falloffExponent value for a vortex field is 0.0, indicating that the field’s effect is constant throughout its area of effect.
  129. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388160-vortex
  130. */
  131. static vortex() {
  132. return null
  133. }
  134.  
  135. /**
  136. * Creates a field that accelerates objects toward its center.
  137. * @access public
  138. * @returns {SCNPhysicsField} -
  139. * @desc Because the force of gravity on an object is proportional to the object’s mass, this force accelerates all objects at the same distance from the field’s center by the same amount. The field’s strength property measures this acceleration in meters per second per second.By default, a radial gravity field attracts objects toward its center. To make it repel objects instead, set the field’s strength property to a negative value.The default falloffExponent value for a radial gravity field is 2.0, indicating that the field’s effect diminishes with the square of distance from its center.
  140. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388115-radialgravity
  141. */
  142. static radialGravity() {
  143. return null
  144. }
  145.  
  146. /**
  147. * Creates a field that accelerates objects in a specific direction.
  148. * @access public
  149. * @returns {SCNPhysicsField} -
  150. * @desc Because the force of gravity on an object is proportional to the object’s mass, this force accelerates all objects in the field’s area of affect by the same amount. The field’s strength property measures this acceleration in meters per second per second.By default, a linear gravity field accelerates objects in along its direction vector. To make it accelerate objects in the opposite direction, set the field’s strength property to a negative value.The default falloffExponent value for a linear gravity field is 0.0, indicating that the field’s effect is constant throughout its area of effect.
  151. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388130-lineargravity
  152. */
  153. static linearGravity() {
  154. return null
  155. }
  156.  
  157. /**
  158. * Creates a field that applies random forces to objects in its area of effect.
  159. * @access public
  160. * @param {number} smoothness - The amount of randomness in the field. A value of 0.0 specifies maximum noise, and a value of 1.0 specifies no noise at all.
  161. * @param {number} speed - The field’s variation over time. Specify 0.0 for a static field.
  162. * @returns {SCNPhysicsField} -
  163. * @desc Use this field type to simulate effects involving random motion, such as fireflies or gently falling snow.In calculating the direction and strength of the field’s effect on an object, SceneKit uses a Perlin simplex noise function. This function produces a velocity field that varies over time.The default falloffExponent value for a noise field is 0.0, indicating that the field’s effect is constant throughout its area of effect. This field type ignores the field’s direction property.
  164. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388150-noisefield
  165. */
  166. static noiseFieldAnimationSpeed(smoothness, speed) {
  167. return null
  168. }
  169.  
  170. /**
  171. * Creates a field that applies random forces to objects in its area of effect, with magnitudes proportional to those objects’ velocities.
  172. * @access public
  173. * @param {number} smoothness - The amount of randomness in the field. A value of 0.0 specifies maximum noise, and a value of 1.0 specifies no noise at all.
  174. * @param {number} speed - The field’s variation over time. Specify 0.0 for a static field.
  175. * @returns {SCNPhysicsField} -
  176. * @desc Like a noise field, a turbulence field applies forces in random directions to the objects that it affects. Unlike a noise field, a turbulence field applies a force whose magnitude is proportional to the speed of each affected object. For example, an object passing through a noise field shakes as it travels through the field, but an object passing through a turbulence field shakes more violently the faster it travels. The field’s strength property scales the magnitude of the turbulence effect.The default falloffExponent value for a turbulence field is 0.0, indicating that the field’s effect is constant throughout its area of effect.
  177. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388162-turbulencefield
  178. */
  179. static turbulenceFieldAnimationSpeed(smoothness, speed) {
  180. return null
  181. }
  182.  
  183. /**
  184. * Creates a field that pulls objects toward its center with a spring-like force.
  185. * @access public
  186. * @returns {SCNPhysicsField} -
  187. * @desc The force a spring field applies to objects in its area of effect is linearly proportional to the distance from the object to the center of the field. (That is, the field behaves according to Hooke’s Law of real-world spring forces.) An object placed at the center of the field and moved away will oscillate around the center, with a period of oscillation that is proportional to the object’s mass. The field’s strength property scales the magnitude of the spring effect—a larger strength simulates a stiffer spring.The default falloffExponent value for a spring field is 1.0, indicating that the field’s effect diminishes linearly with distance from its center.
  188. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388134-spring
  189. */
  190. static spring() {
  191. return null
  192. }
  193.  
  194. /**
  195. * Creates a field that attracts or repels objects based on their electrical charge and on their distance from the field’s center.
  196. * @access public
  197. * @returns {SCNPhysicsField} -
  198. * @desc Use this field type to make objects behave differently from one another when they enter a region, or to make an object's behavior different from its mass-based behavior. An electric field behaves according to the first part of the Lorentz force equation modeling real-world electromagnetic forces—the field applies a force whose magnitude is proportional to electric charge and distance.By default, physics bodies and particle systems have no electric charge, so they are unaffected by electric and magnetic fields. Use the charge property of a physics body or the particleCharge property of a particle system to add charge-based behavior.When the field’s strength value is positive (the default), it attracts bodies whose charge is negative and repels bodies whose charge is positive. To reverse this behavior, set the field’s strength property to a negative value.The default falloffExponent value for an electric field is 2.0, indicating that the field’s effect diminishes with the square of its distance from its center.
  199. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388152-electric
  200. */
  201. static electric() {
  202. return null
  203. }
  204.  
  205. /**
  206. * Creates a field that attracts or repels objects based on their electrical charge, velocity, and distance from the field’s axis.
  207. * @access public
  208. * @returns {SCNPhysicsField} -
  209. * @desc Use this field type to make objects behave differently from one another when they enter a region, or to make an object's behavior different from its mass based behavior. A magnetic field behaves according to the second part of the Lorentz force equation modeling real-world electromagnetic forces—the field applies a force determined by the cross product of an object’s velocity vector and the magnetic field vector at the object’s location, with magnitude proportional to the object’s electric charge. By default, physics bodies and particle systems have no electric charge, so they are unaffected by electric and magnetic fields. Use the charge property of a physics body or the particleCharge property of a particle system to add charge-based behavior.When the field’s strength value is positive (the default), the magnetic field vectors circulate counterclockwise relative to the field’s direction vector. (That is, the magnetic field models a real-world magnetic field created by current in a wire oriented in the field’s direction.) To make field vectors circulate clockwise, set the field’s strength property to a negative value.NoteThis SCNPhysicsField option models the real-world physics effect of magnetic fields on moving, electrically charged bodies, not the behavior of permanent magnets or electromagnets. To make objects in your scene simply attract or repel one another, use a different field type. For example, a field created by the radialGravity() method attracts or repels all dynamic bodies near it according to its strength property, and a field created by the electric() method selectively attracts or repels bodies according to their electric charge.The default falloffExponent value for a magnetic field is 2.0, indicating that the field’s effect diminishes with the square of distance from its center.
  210. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388168-magnetic
  211. */
  212. static magnetic() {
  213. return null
  214. }
  215.  
  216. // Creating Custom Physics Fields
  217.  
  218. /**
  219. * Creates a field that runs the specified block to determine the force a field applies to each object in its area of effect.
  220. * @access public
  221. * @param {SCNFieldForceEvaluator} block - A block that SceneKit runs for each object in the field’s area of effect. See SCNFieldForceEvaluator.
  222. * @returns {SCNPhysicsField} -
  223. * @desc For custom physics fields, SceneKit ignores the direction, strength, falloffExponent, and minimumDistance properties. Instead, SceneKit calls your block to determine the direction and magnitude of force to apply to each physics body or particle in the field’s area of effect.
  224. * @see https://developer.apple.com/documentation/scenekit/scnphysicsfield/1388140-customfield
  225. */
  226. static customFieldEvaluationBlock(block) {
  227. return null
  228. }
  229. }