@@ -25,19 +25,25 @@ import flx3d.Flx3DUtil;
2525import haxe .io .Path ;
2626import openfl .Assets ;
2727#end
28-
2928import flixel .FlxCamera ;
3029
31- class Flx3DCamera extends FlxCamera {
30+ class Flx3DCamera extends FlxCamera
31+ {
3232 #if THREE_D_SUPPORT
3333 private static var __3DIDS : Int = 0 ;
3434
3535 public var view : View3D ;
3636
3737 var meshes : Array <Mesh > = [];
38- public function new (X : Int = 0 , Y : Int = 0 , Width : Int = 0 , Height : Int = 0 , DefaultZoom : Float = 1 ) {
38+
39+ public function new (X : Int = 0 , Y : Int = 0 , Width : Int = 0 , Height : Int = 0 , DefaultZoom : Float = 1 )
40+ {
3941 if (! Flx3DUtil .is3DAvailable ())
40- throw " [Flx3DCamera] 3D is not available on this platform. Stages in use: " + Flx3DUtil .getTotal3D () + " , Max stages allowed: " + FlxG .stage .stage3Ds .length + " ." ;
42+ throw " [Flx3DCamera] 3D is not available on this platform. Stages in use: "
43+ + Flx3DUtil .getTotal3D ()
44+ + " , Max stages allowed: "
45+ + FlxG .stage .stage3Ds .length
46+ + " ." ;
4147 super (X , Y , Width , Height , DefaultZoom );
4248 __cur3DStageID = __3DIDS ++ ;
4349
@@ -49,7 +55,8 @@ class Flx3DCamera extends FlxCamera {
4955 FlxG .stage .addChild (view );
5056 }
5157
52- public override function render () {
58+ public override function render ()
59+ {
5360 super .render ();
5461
5562 view .x = FlxG .game .x + FlxG .game .scaleX * (flashSprite .x + flashSprite .scaleX * (_scrollRect .x + _scrollRect .scaleX * (_scrollRect .scrollRect .x )));
@@ -65,7 +72,8 @@ class Flx3DCamera extends FlxCamera {
6572 view .render ();
6673 }
6774
68- public function addModel (assetPath : String , callback : Asset3DEvent -> Void , ? texturePath : String , smoothTexture : Bool = true ) {
75+ public function addModel (assetPath : String , callback : Asset3DEvent -> Void , ? texturePath : String , smoothTexture : Bool = true )
76+ {
6977 var model = Assets .getBytes (assetPath );
7078 if (model == null )
7179 throw ' Model at ${assetPath } was not found.' ;
@@ -79,36 +87,43 @@ class Flx3DCamera extends FlxCamera {
7987 if (texturePath != null )
8088 material = new TextureMaterial (Cast .bitmapTexture (Assets .getBitmapData (texturePath , true , false )), smoothTexture );
8189
82- return loadData (model , context , switch (Path .extension (assetPath ).toLowerCase ()) {
90+ return loadData (model , context , switch (Path .extension (assetPath ).toLowerCase ())
91+ {
8392 case " dae" : new DAEParser ();
8493 case " md2" : new MD2Parser ();
8594 case " md5" : new MD5MeshParser ();
8695 case " awd" : new AWDParser ();
87- default : new OBJParser ();
88- }, (event : Asset3DEvent ) -> {
89- if (event .asset != null && event .asset .assetType == Asset3DType .MESH ) {
90- var mesh : Mesh = cast event .asset ;
91- if (material != null )
92- mesh .material = material ;
93- meshes .push (mesh );
94- }
95- callback (event );
96- });
96+ default : new OBJParser ();
97+ }, (event : Asset3DEvent ) ->
98+ {
99+ if (event .asset != null && event .asset .assetType == Asset3DType .MESH )
100+ {
101+ var mesh : Mesh = cast event .asset ;
102+ if (material != null )
103+ mesh .material = material ;
104+ meshes .push (mesh );
105+ }
106+ callback (event );
107+ });
97108 }
98109
99110 private var __cur3DStageID : Int ;
100111 private var _loaders : Map <Asset3DLibraryBundle , AssetLoaderToken > = [];
101112
102- private function loadData (data : Dynamic , context : AssetLoaderContext , parser : ParserBase , onAssetCallback : Asset3DEvent -> Void ): AssetLoaderToken {
113+ private function loadData (data : Dynamic , context : AssetLoaderContext , parser : ParserBase , onAssetCallback : Asset3DEvent -> Void ): AssetLoaderToken
114+ {
103115 var token : AssetLoaderToken ;
104116
105117 var lib : Asset3DLibraryBundle = Asset3DLibraryBundle .getInstance (' Flx3DView- ${__cur3DStageID }' );
106118 token = lib .loadData (data , context , null , parser );
107119
108- token .addEventListener (Asset3DEvent .ASSET_COMPLETE , (event : Asset3DEvent ) -> {
120+ token .addEventListener (Asset3DEvent .ASSET_COMPLETE , (event : Asset3DEvent ) ->
121+ {
109122 // ! Taken from Loader3D https://github.com/openfl/away3d/blob/master/away3d/loaders/Loader3D.hx#L207-L232
110- if (event .type == Asset3DEvent .ASSET_COMPLETE ) {
111- var obj : ObjectContainer3D = switch (event .asset .assetType ) {
123+ if (event .type == Asset3DEvent .ASSET_COMPLETE )
124+ {
125+ var obj : ObjectContainer3D = switch (event .asset .assetType )
126+ {
112127 case Asset3DType .LIGHT : expect (event .asset , LightBase );
113128 case Asset3DType .CONTAINER : expect (event .asset , ObjectContainer3D );
114129 case Asset3DType .MESH : expect (event .asset , Mesh );
@@ -126,36 +141,42 @@ class Flx3DCamera extends FlxCamera {
126141 onAssetCallback (event );
127142 });
128143
129- token .addEventListener (LoaderEvent .RESOURCE_COMPLETE , (_ ) -> {
144+ token .addEventListener (LoaderEvent .RESOURCE_COMPLETE , (_ ) ->
145+ {
130146 trace (" Loader Finished..." );
131147 });
132148
133- _loaders .set (lib ,token );
149+ _loaders .set (lib , token );
134150
135151 return token ;
136152 }
137153
138- override function destroy () {
154+ override function destroy ()
155+ {
139156 if (meshes != null )
140- for (mesh in meshes )
157+ for (mesh in meshes )
141158 mesh .dispose ();
142159
143160 var bundle = Asset3DLibraryBundle .getInstance (' Flx3DView- ${__cur3DStageID }' );
144161 bundle .stopAllLoadingSessions ();
145162 @:privateAccess {
146- if (bundle ._loadingSessions != null ) {
147- for (load in bundle ._loadingSessions ) {
163+ if (bundle ._loadingSessions != null )
164+ {
165+ for (load in bundle ._loadingSessions )
166+ {
148167 load .dispose ();
149168 }
150169 }
151170 Asset3DLibrary ._instances .remove (' Flx3DView- ${__cur3DStageID }' );
152171 }
153172
154173 FlxG .stage .removeChild (view );
155- try {
174+ try
175+ {
156176 view .dispose ();
157- } catch (e ) {
158-
177+ }
178+ catch (e )
179+ {
159180 }
160181
161182 super .destroy ();
@@ -164,4 +185,4 @@ class Flx3DCamera extends FlxCamera {
164185 public function addChild (c )
165186 view .scene .addChild (c );
166187 #end
167- }
188+ }
0 commit comments