<?xml version="1.0"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ [Embed(source = "../assets/alternativa3d_small.png")] [Bindable] public var Logo:Class; import alternativa.engine3d.core.Mesh; import alternativa.engine3d.core.Object3D; import alternativa.engine3d.loaders.Loader3DS; import alternativa.engine3d.loaders.LoaderOBJ; import alternativa.engine3d.materials.TextureMaterialPrecision; import alternativa.utils.MeshUtils; import flash.display.Sprite; import flash.events.Event; import flash.filesystem.File; import flash.net.FileFilter; private var loader3ds:Loader3DS; private var loaderObj:LoaderOBJ; private var openFile:File = new File(); private var verticesNum:int; private var facesNum:int; private function onLoad3DModelClick():void{ openFile.addEventListener(Event.SELECT, onOpenFileComplete); openFile.browseForOpen("Open 3D model", [new FileFilter("3D model file (*.3ds,*.obj)", "*.3ds;*.obj;", "3DS;OBJ;")]); } private function onOpenFileComplete(event:Event):void { var path:String = event.target.nativePath.replace(/\\/g, "/"); if (openFile.extension == "3ds") { loader3ds = new Loader3DS(); loader3ds.smooth = true; loader3ds.precision = TextureMaterialPrecision.HIGH; loader3ds.addEventListener(Event.COMPLETE, onLoadingComplete); loader3ds.load(path); }else if (openFile.extension == "obj") { loaderObj = new LoaderOBJ(); loaderObj.smooth = true; loaderObj.precision = TextureMaterialPrecision.HIGH; loaderObj.addEventListener(Event.COMPLETE, onLoadingComplete); loaderObj.load(path); } } private function onLoadingComplete(e:Event):void { var pkg:String = "my.package"; outputField.text = ""; verticesNum = facesNum = 0; //go through each part of the model var loader:* = openFile.extension == "3ds" ? loader3ds : loaderObj for (var o:* in loader.content.children) { var object:Object3D = o; weldVerticesAndFaces(object); //output an ActionScript class from the mesh if (object is Mesh) { outputField.text += MeshUtils.generateClass(Mesh(object), pkg) + "\n\n"; verticesNum += Mesh(object).vertices.length; facesNum += Mesh(object).faces.length; } } geometryStatLabel.text = "Vertices: " + verticesNum + " Faces: " + facesNum; } // Optimizing object geometry private function weldVerticesAndFaces(object:Object3D):void { if (object is Mesh) { MeshUtils.autoWeldVertices(Mesh(object), 0.01); MeshUtils.autoWeldFaces(Mesh(object), 0.01, 0.001); } // Launching procedure for object's children for (var key:* in object.children) { weldVerticesAndFaces(key); } } ]]> </mx:Script> <mx:HBox paddingLeft="200"> <mx:Button label="Load 3D Model" click="onLoad3DModelClick()"/> <mx:Label id="geometryStatLabel" width="200" paddingTop="2" /> </mx:HBox> <mx:TextArea width = "100%" height = "100%" id = "outputField" / > <mx:Image source="{Logo}" /> </mx:WindowedApplication>
UPD: Added vertices and face counter
UPD2: Oops! I wasn't first who made AIR exporter, just found Alternativa Class Generating AIR App by Chris Rebstock
UPD3: Check out the version 2.0 of Alternativa3D Mesh Class Exporter by Randall W. Haws
05.04.2009. 04:46
dfdsfdf
Write a comment
* = required field