PageRenderTime 6175ms CodeModel.GetById 6ms RepoModel.GetById 4ms app.codeStats 0ms

/sandy/as3/branches/3.0/src/sandy/core/data/Polygon.as

http://sandy.googlecode.com/
ActionScript | 684 lines | 331 code | 67 blank | 286 comment | 34 complexity | e8e5882514b5714f99b7cc68eb9447bf MD5 | raw file
  1. /*
  2. # ***** BEGIN LICENSE BLOCK *****
  3. Copyright the original author Thomas PFEIFFER
  4. Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.mozilla.org/MPL/MPL-1.1.html
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. # ***** END LICENSE BLOCK *****
  14. */
  15. package sandy.core.data
  16. {
  17. import flash.display.Sprite;
  18. import flash.events.Event;
  19. import flash.events.MouseEvent;
  20. import flash.geom.Point;
  21. import flash.geom.Rectangle;
  22. import flash.utils.Dictionary;
  23. import sandy.core.Scene3D;
  24. import sandy.core.scenegraph.Geometry3D;
  25. import sandy.core.scenegraph.IDisplayable;
  26. import sandy.core.scenegraph.Shape3D;
  27. import sandy.events.BubbleEvent;
  28. import sandy.events.BubbleEventBroadcaster;
  29. import sandy.materials.Appearance;
  30. import sandy.math.IntersectionMath;
  31. import sandy.math.VectorMath;
  32. import sandy.util.NumberUtil;
  33. import sandy.view.Frustum;
  34. /**
  35. * Polygon's are the building blocks of visible 3D shapes.
  36. *
  37. * @author Thomas Pfeiffer - kiroukou
  38. * @author Mirek Mencel
  39. * @since 1.0
  40. * @version 3.0
  41. * @date 24.08.2007
  42. */
  43. public final class Polygon implements IDisplayable
  44. {
  45. // _______
  46. // STATICS_______________________________________________________
  47. private static var _ID_:uint = 0;
  48. /**
  49. * This property lists all the polygons.
  50. * This is an helping property since it allows to retrieve a polygon instance from its unique ID.
  51. * Polygon objects have an unique ID with myPolygon.id.
  52. * Using : Polygon.POLYGON_MAP[myPolygon.id] returns myPolygon (for sure this example has no interesst except showing the use of the property.
  53. */
  54. public static var POLYGON_MAP:Dictionary = new Dictionary(true);
  55. // ______
  56. // PUBLIC________________________________________________________
  57. /**
  58. * [READ-ONLY] property
  59. * Unique polygon ID Number.
  60. */
  61. public const id:uint = _ID_++;
  62. /**
  63. * [READ-ONLY] property.
  64. * Link to the Shape3D instance this polygon is related too.
  65. */
  66. public var shape:Shape3D;
  67. /**
  68. * [READ-ONLY] property.
  69. * Refers to the Scene3D the shape is linked to.
  70. */
  71. public var scene:Scene3D;
  72. /**
  73. * [READ-ONLY] property.
  74. * Specify if the polygon has been clipped
  75. */
  76. public var isClipped:Boolean = false;
  77. /**
  78. * [READ-ONLY] property.
  79. * Array of clipped vertices. Check isClipped property first to see if this array shall be containing the useful data or not.
  80. */
  81. public var cvertices:Array;
  82. /**
  83. * [READ-ONLY] property.
  84. * Array of original vertices.
  85. */
  86. public var vertices:Array;
  87. /**
  88. * [READ-ONLY] property.
  89. */
  90. public var vertexNormals:Array;
  91. /**
  92. * [READ-ONLY] property.
  93. */
  94. public var normal:Vertex;
  95. /**
  96. * [READ-ONLY] property.
  97. */
  98. public var aUVCoord:Array;
  99. /**
  100. * [READ-ONLY] property.
  101. */
  102. public var aEdges:Array;
  103. /**
  104. * [READ-ONLY] property.
  105. */
  106. public var caUVCoord:Array;
  107. /**
  108. * [READ-ONLY] property.
  109. * This property contains the texture bounds as a Rectangle.
  110. */
  111. public var uvBounds:Rectangle;
  112. /**
  113. * Normal backface culling side is 1. -1 means that the opposite side is culled.
  114. */
  115. public var backfaceCulling:Number;
  116. /**
  117. * [READ-ONLY] property
  118. * Array of polygons that share an edge with the current polygon.
  119. */
  120. public var aNeighboors:Array = new Array();
  121. /**
  122. * [READ-ONLY] property.
  123. * Min values of this polygon
  124. */
  125. public var minBounds:Vector = new Vector();
  126. /**
  127. * [READ-ONLY] property.
  128. * Max values of this polygon
  129. */
  130. public var maxBounds:Vector = new Vector();
  131. /**
  132. * [READ-ONLY] property.
  133. * Mean values of this polygon
  134. */
  135. public var meanBounds:Vector = new Vector();
  136. /**
  137. * Creates a new polygon.
  138. *
  139. * @param p_oShape The shape this polygon belongs to
  140. * @param p_geometry The geometry this polygon is part of
  141. * @param p_aVertexID The vertexID array of this polygon
  142. * @param p_aUVCoordsID The UVCoordsID array of this polygon
  143. * @param p_nFaceNormalID The faceNormalID of this polygon
  144. * @param p_nEdgesID The edgesID of this polygon
  145. */
  146. public function Polygon( p_oOwner:Shape3D, p_geometry:Geometry3D, p_aVertexID:Array, p_aUVCoordsID:Array=null, p_nFaceNormalID:Number=0, p_nEdgesID:uint=0 )
  147. {
  148. shape = p_oOwner;
  149. m_oGeometry = p_geometry;
  150. // --
  151. backfaceCulling = 1;
  152. // --
  153. __update( p_aVertexID, p_aUVCoordsID, p_nFaceNormalID, p_nEdgesID );
  154. m_oContainer = new Sprite();
  155. // --
  156. POLYGON_MAP[id] = this;
  157. }
  158. /**
  159. * The broadcaster property.
  160. *
  161. * <p>The broadcaster is the property used to send events to listeners.</p>
  162. */
  163. public function get broadcaster():BubbleEventBroadcaster
  164. {
  165. return m_oEB;
  166. }
  167. /**
  168. * Adds a listener for specifical event.
  169. *
  170. * @param p_sEvent Name of the Event.
  171. * @param oL Listener object.
  172. */
  173. public function addEventListener(p_sEvent:String, oL:*) : void
  174. {
  175. m_oEB.addEventListener.apply(m_oEB, arguments);
  176. }
  177. /**
  178. * Removes a listener for specifical event.
  179. *
  180. * @param p_sEvent Name of the Event.
  181. * @param oL Listener object.
  182. */
  183. public function removeEventListener(p_sEvent:String, oL:*) : void
  184. {
  185. m_oEB.removeEventListener(p_sEvent, oL);
  186. }
  187. /**
  188. * Pre-compute several properties of the polygon in the same time.
  189. * List of the computed properties :
  190. * - visibility : if the polygon is visible
  191. */
  192. public function computeVisibility():void
  193. {
  194. // all normals are refreshed every loop. Face is visible is normal face to the camera
  195. var l_nDot:Number = ( m_oVisibilityRef.wx * normal.wx + m_oVisibilityRef.wy * normal.wy + m_oVisibilityRef.wz * normal.wz );
  196. l_nDot *= backfaceCulling;
  197. m_bVisible = ( l_nDot < 0 );
  198. }
  199. /**
  200. * Pre-compute several properties of the polygon in the same time.
  201. * List of the computed properties :
  202. * <ul>
  203. * <li>mean z depth : the mean z depth used for basic sorting</li>
  204. * <li>max bounds : the maximum bounds of the polygon</li>
  205. * <li>min bounds : the minimum bounds of the polygon</li>
  206. * <li>mean bounds : the mean of each components of the polygon. It is center actually.</li>
  207. * </ul>
  208. */
  209. public function precomputeBounds():void
  210. {
  211. const l_aVert:Array = vertices;
  212. // --
  213. meanBounds.reset();
  214. minBounds.resetToPositiveInfinity();
  215. maxBounds.resetToNegativeInfinity();
  216. // --
  217. for each ( var v:Vertex in l_aVert )
  218. {
  219. if( v.wx < minBounds.x ) minBounds.x = v.wx;
  220. else if( v.wx > maxBounds.x ) maxBounds.x = v.wx;
  221. // --
  222. if( v.wy < minBounds.y ) minBounds.y = v.wy;
  223. else if( v.wy > maxBounds.y ) maxBounds.y = v.wy;
  224. // --
  225. if( v.wz < minBounds.z ) minBounds.z = v.wz;
  226. else if( v.wz > maxBounds.z ) maxBounds.z = v.wz;
  227. // --
  228. meanBounds.x += v.wx;
  229. meanBounds.y += v.wy;
  230. meanBounds.z += v.wz;
  231. }
  232. // -- We normalize the sum and return it
  233. meanBounds.scale( 1 / l_aVert.length );
  234. }
  235. /**
  236. * Is this face visible?.
  237. * The method returns the visibility value pre computed after precompute method call. This getter shall be called afer the precompute call.
  238. * @return true if this face is visible, false otherwise.
  239. */
  240. public function get visible(): Boolean
  241. {
  242. return m_bVisible;
  243. }
  244. /**
  245. * Returns the real 3D position of the 2D screen position.
  246. * The 2D position is usually coming from :
  247. * <listing version="3.0">
  248. * var l_nClicX:Number = m_oScene.container.mouseX;
  249. * var l_nClicY:Number = m_oScene.container.mouseY;
  250. * </listing>
  251. *
  252. * @return the real 3D position which correspond to the intersection onto that polygone
  253. */
  254. public function get3DFrom2D( p_oScreenPoint:Point ):Vector
  255. {
  256. var l_nX:Number = (p_oScreenPoint.x - scene.camera.viewport.width2)/ scene.camera.viewport.width2;
  257. var l_nY:Number = -(p_oScreenPoint.y - scene.camera.viewport.height2)/scene.camera.viewport.height2;
  258. var l_oPoint:Vector = new Vector( l_nX, l_nY, 0 );
  259. // -- on prend la matrice de projection inverse
  260. var l_oMatrix:Matrix4 = scene.camera.invProjectionMatrix;
  261. l_oMatrix.vectorMult( l_oPoint );
  262. l_oMatrix = scene.camera.matrix;
  263. l_oMatrix.vectorMult( l_oPoint );
  264. // -- maintenant nous avons la direction du rayon logiquement.
  265. // -- reste a calculer son intersection avec le polygone
  266. var l_oNormale:Vector = normal.getVector();
  267. var l_oOrigineRayon:Vector = scene.camera.getPosition();
  268. l_oPoint.sub( l_oOrigineRayon );
  269. //on normalise le vecteur car c'est lui qui sert de vecteur directeur du rayon qui part
  270. l_oPoint.normalize();
  271. // on chope la constante du plan
  272. var l_nPlaneConst:Number = VectorMath.dot( (vertices[0] as Vertex).getVector(), l_oNormale );
  273. // Calcul le produit scalaire Normale du plan avec le vecteur directeur du rayon
  274. var l_nDotNormalePlanRayon:Number = l_oNormale.dot( l_oPoint );
  275. // In case the ray is parallel to the plane
  276. if( l_nDotNormalePlanRayon >= -NumberUtil.TOL && l_nDotNormalePlanRayon <= NumberUtil.TOL )
  277. return null;
  278. // distance from ray to plane
  279. var l_nDistRayonPlan:Number = (l_oOrigineRayon.dot( l_oNormale ))/(l_oNormale.getNorm());
  280. // lpane distance
  281. var t:Number = - l_nDistRayonPlan / l_nDotNormalePlanRayon
  282. // No collision
  283. if( t < NumberUtil.TOL )
  284. return null;
  285. // -- intersection point
  286. return new Vector( l_oOrigineRayon.x + t * l_oPoint.x,
  287. l_oOrigineRayon.y + t * l_oPoint.y,
  288. l_oOrigineRayon.z + t * l_oPoint.z );;
  289. }
  290. /**
  291. * Get the UVCoord under the 2D screen position after a mouse click or something
  292. * The 2D position is usually coming from :
  293. * <listing version="3.0">
  294. * var l_nClicX:Number = m_oScene.container.mouseX;
  295. * var l_nClicY:Number = m_oScene.container.mouseY;
  296. * </listing>
  297. *
  298. * @return the UVCoord under the 2D screen point
  299. */
  300. public function getUVFrom2D( p_oScreenPoint:Point ):UVCoord
  301. {
  302. var p0:Point = new Point(vertices[0].sx, vertices[0].sy);
  303. var p1:Point = new Point(vertices[1].sx, vertices[1].sy);
  304. var p2:Point = new Point(vertices[2].sx, vertices[2].sy);
  305. var u0:UVCoord = aUVCoord[0];
  306. var u1:UVCoord = aUVCoord[1];
  307. var u2:UVCoord = aUVCoord[2];
  308. var v01:Point = new Point(p1.x - p0.x, p1.y - p0.y );
  309. var vn01:Point = v01.clone();
  310. vn01.normalize(1);
  311. var v02:Point = new Point(p2.x - p0.x, p2.y - p0.y );
  312. var vn02:Point = v02.clone(); vn02.normalize(1);
  313. // sub that from click point
  314. var v4:Point = new Point( p_oScreenPoint.x - v01.x, p_oScreenPoint.y - v01.y );
  315. // we now have everything to find 1 intersection
  316. var l_oInter:Point = IntersectionMath.intersectionLine2D( p0, p2, p_oScreenPoint, v4 );
  317. // find vectors to intersection
  318. var vi02:Point = new Point( l_oInter.x - p0.x, l_oInter.y - p0.y );
  319. var vi01:Point = new Point( p_oScreenPoint.x - l_oInter.x , p_oScreenPoint.y - l_oInter.y );
  320. // interpolation coeffs
  321. var d1:Number = vi01.length / v01.length ;
  322. var d2:Number = vi02.length / v02.length;
  323. // -- on interpole linéairement pour trouver la position du point dans repere de la texture (normalisé)
  324. return new UVCoord( u0.u + d1*(u1.u - u0.u) + d2*(u2.u - u0.u),
  325. u0.v + d1*(u1.v - u0.v) + d2*(u2.v - u0.v));
  326. }
  327. /**
  328. * Returns an array containing the vertices, clipped by the camera frustum.
  329. *
  330. * @return The array of clipped vertices
  331. */
  332. public function clip( p_oFrustum:Frustum ):Array
  333. {
  334. isClipped = true;
  335. // For lines we only apply front plane clipping
  336. if( vertices.length < 3 )
  337. {
  338. clipFrontPlane( p_oFrustum );
  339. }
  340. else
  341. {
  342. cvertices = null;
  343. caUVCoord = null;
  344. // --
  345. cvertices = vertices.concat();
  346. caUVCoord = aUVCoord.concat();
  347. // --
  348. p_oFrustum.clipFrustum( cvertices, caUVCoord );
  349. }
  350. return cvertices;
  351. }
  352. /**
  353. * Perform a clipping against the near frustum plane.
  354. *
  355. * @return The array of clipped vertices
  356. */
  357. public function clipFrontPlane( p_oFrustum:Frustum ):Array
  358. {
  359. isClipped = true;
  360. cvertices = null;
  361. cvertices = vertices.concat();
  362. // If line
  363. if( vertices.length < 3 )
  364. {
  365. p_oFrustum.clipLineFrontPlane( cvertices );
  366. }
  367. else
  368. {
  369. caUVCoord = null;
  370. caUVCoord = aUVCoord.concat();
  371. p_oFrustum.clipFrontPlane( cvertices, caUVCoord );
  372. }
  373. return cvertices;
  374. }
  375. /**
  376. * Updates the vertices and normals for this polygon.
  377. *
  378. * <p>Calling this method make the polygon gets its vertice and normals by reference
  379. * instead of accessing them by their ID.<br/>
  380. * This method shall be called once the geometry created.</p>
  381. *
  382. * @param p_aVertexID The vertexID array of this polygon
  383. * @param p_aUVCoordsID The UVCoordsID array of this polygon
  384. * @param p_nFaceNormalID The faceNormalID of this polygon
  385. * @param p_nEdgesID The edgesID of this polygon
  386. */
  387. private function __update( p_aVertexID:Array, p_aUVCoordsID:Array, p_nFaceNormalID:uint, p_nEdgeListID:uint ):void
  388. {
  389. var i:int=0, l:int;
  390. // --
  391. vertexNormals = new Array();
  392. vertices = new Array();
  393. for each( var o:* in p_aVertexID )
  394. {
  395. vertices[i] = Vertex( m_oGeometry.aVertex[ p_aVertexID[i] ] );
  396. vertexNormals[i] = m_oGeometry.aVertexNormals[ p_aVertexID[i] ];
  397. i++;
  398. }
  399. // --
  400. m_oVisibilityRef = vertices[0];
  401. // -- every polygon does not have some texture coordinates
  402. if( p_aUVCoordsID )
  403. {
  404. var l_nMinU:Number = Number.POSITIVE_INFINITY, l_nMinV:Number = Number.POSITIVE_INFINITY,
  405. l_nMaxU:Number = Number.NEGATIVE_INFINITY, l_nMaxV:Number = Number.NEGATIVE_INFINITY;
  406. // --
  407. aUVCoord = new Array();
  408. i = 0;
  409. for each( var p:* in p_aUVCoordsID )
  410. {
  411. var l_oUV:UVCoord = UVCoord( m_oGeometry.aUVCoords[ p_aUVCoordsID[i] ] );
  412. aUVCoord[i] = l_oUV;
  413. if( l_oUV.u < l_nMinU ) l_nMinU = l_oUV.u;
  414. else if( l_oUV.u > l_nMaxU ) l_nMaxU = l_oUV.u;
  415. // --
  416. if( l_oUV.v < l_nMinV ) l_nMinV = l_oUV.v;
  417. else if( l_oUV.v > l_nMaxV ) l_nMaxV = l_oUV.v;
  418. // --
  419. i++;
  420. }
  421. // --
  422. uvBounds = new Rectangle( l_nMinU, l_nMinV, l_nMaxU-l_nMinU, l_nMaxV-l_nMinV );
  423. }
  424. // --
  425. normal = Vertex( m_oGeometry.aFacesNormals[ p_nFaceNormalID ] );
  426. // If no normal has been given, we create it ourself.
  427. if( normal == null )
  428. {
  429. var l_oNormal:Vector = createNormal();
  430. var l_nID:Number = m_oGeometry.setFaceNormal( m_oGeometry.getNextFaceNormalID(), l_oNormal.x, l_oNormal.y, l_oNormal.z );
  431. normal = Vertex( m_oGeometry.aFacesNormals[ l_nID ] );
  432. }
  433. // --
  434. aEdges = new Array();
  435. for each( var l_nEdgeId:uint in m_oGeometry.aFaceEdges[p_nEdgeListID] )
  436. {
  437. var l_oEdge:Edge3D = m_oGeometry.aEdges[ l_nEdgeId ];
  438. l_oEdge.vertex1 = m_oGeometry.aVertex[ l_oEdge.vertexId1 ];
  439. l_oEdge.vertex2 = m_oGeometry.aVertex[ l_oEdge.vertexId2 ];
  440. aEdges.push( l_oEdge );
  441. }
  442. }
  443. /**
  444. * Clears the container of this polygon from graphics.
  445. */
  446. public function clear():void
  447. {
  448. m_oContainer.graphics.clear();
  449. }
  450. /**
  451. * Displays this polygon on its container if visible.
  452. *
  453. * @param p_oScene The current scene this polygon is rendered into
  454. * @param p_oContainer The container to draw on
  455. */
  456. public function display( p_oScene:Scene3D, p_oContainer:Sprite = null ):void
  457. {
  458. scene = p_oScene;
  459. // --
  460. const lCont:Sprite = (p_oContainer)?p_oContainer:m_oContainer;
  461. if( m_bVisible )
  462. {
  463. m_oAppearance.frontMaterial.renderPolygon( p_oScene, this, lCont );
  464. }
  465. else
  466. {
  467. m_oAppearance.backMaterial.renderPolygon( p_oScene, this, lCont );
  468. }
  469. }
  470. /**
  471. * The container for this polygon.
  472. */
  473. public function get container():Sprite
  474. {
  475. return m_oContainer;
  476. }
  477. /**
  478. * @private
  479. */
  480. public function get depth():Number
  481. {
  482. return meanBounds.z;
  483. }
  484. /**
  485. * The z depth of this polygon.
  486. */
  487. public function set depth( p_nDepth:Number ):void
  488. {
  489. meanBounds.z = p_nDepth;
  490. }
  491. /**
  492. * Returns a string representing of this polygon.
  493. *
  494. * @return The string representation.
  495. */
  496. public function toString():String
  497. {
  498. return "sandy.core.data.Polygon::id=" +id+ " [Points: " + vertices.length + "]";
  499. }
  500. /**
  501. * Enables or disables object events for this polygon.
  502. *
  503. * <p>If a value of true is passed, the object events onPress, onRollOver and onRollOut are enabled.<br />.
  504. * To use them, you have to add listeners for the events.</p>
  505. *
  506. * @param b Pass true to enable the events, false to disable.
  507. */
  508. public function enableEvents( b:Boolean ):void
  509. {
  510. if( b && !mouseEvents )
  511. {
  512. container.addEventListener(MouseEvent.CLICK, _onInteraction);
  513. container.addEventListener(MouseEvent.MOUSE_UP, _onInteraction);
  514. container.addEventListener(MouseEvent.MOUSE_DOWN, _onInteraction);
  515. container.addEventListener(MouseEvent.ROLL_OVER, _onInteraction);
  516. container.addEventListener(MouseEvent.ROLL_OUT, _onInteraction);
  517. container.addEventListener(MouseEvent.DOUBLE_CLICK, _onInteraction);
  518. container.addEventListener(MouseEvent.MOUSE_MOVE, _onInteraction);
  519. container.addEventListener(MouseEvent.MOUSE_OVER, _onInteraction);
  520. container.addEventListener(MouseEvent.MOUSE_OUT, _onInteraction);
  521. container.addEventListener(MouseEvent.MOUSE_WHEEL, _onInteraction);
  522. }
  523. else if( !b && mouseEvents )
  524. {
  525. container.removeEventListener(MouseEvent.CLICK, _onInteraction);
  526. container.removeEventListener(MouseEvent.MOUSE_UP, _onInteraction);
  527. container.removeEventListener(MouseEvent.MOUSE_DOWN, _onInteraction);
  528. container.removeEventListener(MouseEvent.ROLL_OVER, _onInteraction);
  529. container.removeEventListener(MouseEvent.ROLL_OUT, _onInteraction);
  530. container.removeEventListener(MouseEvent.DOUBLE_CLICK, _onInteraction);
  531. container.removeEventListener(MouseEvent.MOUSE_MOVE, _onInteraction);
  532. container.removeEventListener(MouseEvent.MOUSE_OVER, _onInteraction);
  533. container.removeEventListener(MouseEvent.MOUSE_OUT, _onInteraction);
  534. container.removeEventListener(MouseEvent.MOUSE_WHEEL, _onInteraction);
  535. }
  536. mouseEvents = b;
  537. }
  538. protected function _onInteraction( p_oEvt:Event ):void
  539. {
  540. m_oEB.broadcastEvent( new BubbleEvent( p_oEvt.type, this, p_oEvt ) );
  541. }
  542. /**
  543. * Calculates and returns the normal vector of the polygon.
  544. *
  545. * @return The normal vector
  546. */
  547. public function createNormal():Vector
  548. {
  549. if( vertices.length > 2 )
  550. {
  551. var v:Vector, w:Vector;
  552. var a:Vertex = vertices[0], b:Vertex = vertices[1], c:Vertex = vertices[2];
  553. v = new Vector( b.wx - a.wx, b.wy - a.wy, b.wz - a.wz );
  554. w = new Vector( b.wx - c.wx, b.wy - c.wy, b.wz - c.wz );
  555. // we compute de cross product
  556. var l_normal:Vector = VectorMath.cross( v, w );
  557. // we normalize the resulting vector
  558. VectorMath.normalize( l_normal ) ;
  559. // we return the resulting vertex
  560. return l_normal;
  561. }
  562. else
  563. {
  564. return new Vector();
  565. }
  566. }
  567. /**
  568. * The appearance of this polygon.
  569. */
  570. public function set appearance( p_oApp:Appearance ):void
  571. {
  572. m_oAppearance = p_oApp;
  573. // --
  574. p_oApp.frontMaterial.init( this );
  575. p_oApp.backMaterial.init( this );
  576. }
  577. /**
  578. * @private
  579. */
  580. public function get appearance():Appearance
  581. {
  582. return m_oAppearance;
  583. }
  584. /**
  585. * Changes which side is the "normal" culling side.
  586. *
  587. * <p>The method also swaps the front and back skins.</p>
  588. */
  589. public function swapCulling():void
  590. {
  591. // -- swap backface culling
  592. backfaceCulling *= -1;
  593. }
  594. /**
  595. * Destroys the sprite attache to this polygon.
  596. */
  597. public function destroy():void
  598. {
  599. cvertices = null;
  600. vertices = null;
  601. }
  602. // _______
  603. // PRIVATE_______________________________________________________
  604. /** Reference to its owner geometry */
  605. private var m_oGeometry:Geometry3D;
  606. private var m_oAppearance:Appearance;
  607. /** array of ID of uv coordinates in geometry object */
  608. private var m_aUVCoords:Array;
  609. private var m_bVisible:Boolean = false;
  610. protected var m_oContainer:Sprite;
  611. protected var m_oVisibilityRef:Vertex;
  612. protected var m_oEB:BubbleEventBroadcaster = new BubbleEventBroadcaster();
  613. /** Boolean representing the state of the event activation */
  614. private var mouseEvents:Boolean = false;
  615. }
  616. }