Desktop to ios

Software: Away3D 4.x

cledus, Newbie
Posted: 01 October 2013 03:00 PM   Total Posts: 11

Hi all!

I’m having a problem and I hope someone can help me. I would be so grateful.
I have a desktop app where the user can upload a texture to a model. I’m saving this texture so the user can load it at a later time. My problem is when I try to publish to ios. I have change file to cameraroll, so browsing for the image works. The problem appears when I try to save and apply the texture, then the app freezes. Here is the code that works for the desktop (iv’e added some code to the final function so the texture that is uploaded doesn’t have to be aspect 1:1):

function browseTexturesClicked()
{
 textureFile 
= new File();
 
textureFile.browseForOpen("Open"[new FileFilter("JPG""*.jpg")]);
 
textureFile.addEventListener(Event.SELECTonTextureSelected);
}

function onTextureSelected(evt:Event):void
{
 loadPreset 
false
 textureFile
.addEventListener(Event.COMPLETEtextureLoaded);
 
textureFile.load();
 
textureFile.removeEventListener(Event.SELECTonTextureSelected);
}

function textureLoaded(evt:Event):void
{
 removeEventListener
(Event.ENTER_FRAMErender);
 var 
ba:ByteArray textureFile.data;
 
textureLoader = new Loader();
 
textureLoader.contentLoaderInfo.addEventListener(Event.COMPLETEtextureMaterial);
 
textureLoader.loadBytes(ba);
 
textureFile.removeEventListener(Event.COMPLETEtextureLoaded);
}

function textureMaterial(evt:Event):void
{
 
var bitmapToSave:ByteArray textureFile.data;
 var 
bitmapFileName:String "temptextures/" "texture" + (currSelectedTexture+1).toString() + ".jpg"
 
var bitmapFile:File File.applicationStorageDirectory.resolvePath(bitmapFileName);
 var 
bitmapFileStream:FileStream = new FileStream();
 
 
bitmapFileStream.open(bitmapFileFileMode.WRITE);
 
bitmapFileStream.writeBytes(bitmapToSave0bitmapToSave.length);
 
bitmapFileStream.close()
 
 
currSelectedModelXml.children()[4].children()[currSelectedTexture].children()[1] "texture" + (currSelectedTexture+1).toString() + ".jpg"

 
var shortSide:Number
 
var longSide:Number
 
var widthLongest:Boolean true
 
 longSide 
evt.target.content.bitmapData.width
 shortSide 
evt.target.content.bitmapData.height
 
if(shortSide longSide)
 
{
  widthLongest 
false
  shortSide 
evt.target.content.bitmapData.width
  longSide 
evt.target.content.bitmapData.height
 }
 
 
var divideNumLarge:Number 1024/longSide
 
var divideNumSmall:Number 1024/shortSide

 
var matrix:Matrix = new Matrix();
 
 if(
widthLongest == true)
 
{
  matrix
.scale(divideNumLargedivideNumSmall);
 
}
 
else
 
{
  matrix
.scale(divideNumSmalldivideNumLarge);
 
}
 
 
var smallBMD:BitmapData = new BitmapData(10241024false0x000000);
 
smallBMD.draw(evt.target.content.bitmapDatamatrixnullnullnull,true);


 
tempBitmapTexture = new BitmapTexture(smallBMD);
 
 var 
currModel:Mesh AssetLibrary.getAsset(currSelectedObj) as Mesh;
 
TextureMaterial(currModel.material).texture tempBitmapTexture;
 
 
addEventListener(Event.ENTER_FRAMErender);

And here is the code for the ios:

function browseTexturesClicked()
{
 textureFile 
= new CameraRoll()
 
textureFile.browseForImage();
 
textureFile.addEventListener(MediaEvent.SELECTonTextureSelected);
}

function onTextureSelected(evt:MediaEvent):void
{
 loadPreset 
false
 
var promise:MediaPromise evt.data as MediaPromise;
 
textureFile.removeEventListener(MediaEvent.SELECTonTextureSelected);
 
mobileTextureLoader = new Loader();
 
mobileTextureLoader.contentLoaderInfo.addEventListener(Event.COMPLETEtextureLoaded);
 
mobileTextureLoader.loadFilePromise(promise);
}

function textureLoaded(evt:Event):void
{
 removeEventListener
(Event.ENTER_FRAMErender);

 var 
bitmapToSave:ByteArray evt.currentTarget.content.data;
 
 var 
bitmapFileName:String "temptextures/" "texture" + (currSelectedTexture+1).toString() + ".jpg"
 
var bitmapFile:File File.applicationStorageDirectory.resolvePath(bitmapFileName);
 var 
bitmapFileStream:FileStream = new FileStream();
 
 
bitmapFileStream.open(bitmapFileFileMode.WRITE);
 
bitmapFileStream.writeBytes(bitmapToSave0bitmapToSave.length);
 
bitmapFileStream.close()
 
 
currSelectedModelXml.children()[4].children()[currSelectedTexture].children()[1] "texture" + (currSelectedTexture+1).toString() + ".jpg"

 
var shortSide:Number
 
var longSide:Number
 
var widthLongest:Boolean true
 
 longSide 
evt.target.content.bitmapData.width
 shortSide 
evt.target.content.bitmapData.height
 
if(shortSide longSide)
 
{
  widthLongest 
false
  shortSide 
evt.target.content.bitmapData.width
  longSide 
evt.target.content.bitmapData.height
 }
 
 
var divideNumLarge:Number 1024/longSide
 
var divideNumSmall:Number 1024/shortSide

 
var matrix:Matrix = new Matrix();
 
 if(
widthLongest == true)
 
{
  matrix
.scale(divideNumLargedivideNumSmall);
 
}
 
else
 
{
  matrix
.scale(divideNumSmalldivideNumLarge);
 
}
 
 
var smallBMD:BitmapData = new BitmapData(10241024false0x000000);
 
smallBMD.draw(evt.target.content.bitmapDatamatrixnullnullnull,true);

 
tempBitmapTexture = new BitmapTexture(smallBMD);

 var 
currModel:Mesh AssetLibrary.getAsset(currSelectedObj) as Mesh;
 
TextureMaterial(currModel.material).texture tempBitmapTexture;

 
addEventListener(Event.ENTER_FRAMErender);
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X