Skip to content
Browse files

another fix for saving external textures

  • Loading branch information...
1 parent 23c78f6 commit b7e85215da04da7841729be5984450ae5a8df8d9 @80prozent 80prozent committed Jul 3, 2013
View
51 awaybuilder-core/src/awaybuilder/utils/encoders/AWDEncoder.as
@@ -1224,10 +1224,10 @@ package awaybuilder.utils.encoders
}
else {
_blockBody.writeByte(0);//external
- var extension:String="jpg";
+ var extension:String=".jpg";
if(bitMapHasTransparency(tex.bitmapData,tex.bitmapData.rect.width,tex.bitmapData.rect.height))
- extension="png";
- var texturePath:String="textures/"+getFileName(tex.name)+"."+extension;
+ extension=".png";
+ var texturePath:String="textures/"+getFileName(tex.name, extension);
_blockBody.writeUnsignedInt(texturePath.length);
_blockBody.writeUTFBytes(texturePath);
}
@@ -1244,12 +1244,16 @@ package awaybuilder.utils.encoders
return returnID;
}
- private function getFileName(fullPath: String) : String
+ private function getFileName(fullPath: String, extension:String, cubeMapPrefix:String="") : String
{
var fSlash: int = fullPath.lastIndexOf("/");
var bSlash: int = fullPath.lastIndexOf("\\"); // reason for the double slash is just to escape the slash so it doesn't escape the quote!!!
var slashIndex: int = fSlash > bSlash ? fSlash : bSlash;
- return fullPath.substr(slashIndex + 1);
+ var thisname:String=fullPath.substr(slashIndex + 1);
+ if(thisname.toLowerCase().lastIndexOf(extension) != thisname.length - extension.length)
+ thisname+=cubeMapPrefix+extension
+ thisname = thisname.replace(" ", "%20");
+ return thisname
}
// encode TextureBlock (id=83)
private function _encodeCubeTextures(cubeTexture:CubeTextureVO) : uint
@@ -1284,41 +1288,40 @@ package awaybuilder.utils.encoders
var texturePath:String;
_blockBody.writeByte(0);//external
_blockBody.writeUTF(cubeTexture.name);
- var extension:String="jpg";
- extension="jpg";
+ var extension:String=".jpg";
if(bitMapHasTransparency(cubeTexture.positiveX,cubeTexture.positiveX.rect.width,cubeTexture.positiveX.rect.height))
- extension="png";
- texturePath="textures/"+getFileName(cubeTexture.name)+"_posX."+extension;
+ extension=".png";
+ texturePath="textures/"+getFileName(cubeTexture.name,extension,"_posX.");
_blockBody.writeUnsignedInt(texturePath.length);
_blockBody.writeUTFBytes(texturePath);
- extension="jpg";
+ extension=".jpg";
if(bitMapHasTransparency(cubeTexture.negativeX,cubeTexture.negativeX.rect.width,cubeTexture.negativeX.rect.height))
- extension="png";
- texturePath="textures/"+getFileName(cubeTexture.name)+"_negX."+extension;
+ extension=".png";
+ texturePath="textures/"+getFileName(cubeTexture.name,extension,"_negX.");
_blockBody.writeUnsignedInt(texturePath.length);
_blockBody.writeUTFBytes(texturePath);
- extension="jpg";
+ extension=".jpg";
if(bitMapHasTransparency(cubeTexture.positiveY,cubeTexture.positiveY.rect.width,cubeTexture.positiveY.rect.height))
- extension="png";
- texturePath="textures/"+getFileName(cubeTexture.name)+"_posY."+extension;
+ extension=".png";
+ texturePath="textures/"+getFileName(cubeTexture.name,extension,"_posY.");
_blockBody.writeUnsignedInt(texturePath.length);
_blockBody.writeUTFBytes(texturePath);
- extension="jpg";
+ extension=".jpg";
if(bitMapHasTransparency(cubeTexture.negativeY,cubeTexture.negativeY.rect.width,cubeTexture.negativeY.rect.height))
- extension="png";
- texturePath="textures/"+getFileName(cubeTexture.name)+"_negY."+extension;
+ extension=".png";
+ texturePath="textures/"+getFileName(cubeTexture.name,extension,"_negY.");
_blockBody.writeUnsignedInt(texturePath.length);
_blockBody.writeUTFBytes(texturePath);
- extension="jpg";
+ extension=".jpg";
if(bitMapHasTransparency(cubeTexture.positiveZ,cubeTexture.positiveZ.rect.width,cubeTexture.positiveZ.rect.height))
- extension="png";
- texturePath="textures/"+getFileName(cubeTexture.name)+"_posZ."+extension;
+ extension=".png";
+ texturePath="textures/"+getFileName(cubeTexture.name,extension,"_posZ.");
_blockBody.writeUnsignedInt(texturePath.length);
_blockBody.writeUTFBytes(texturePath);
- extension="jpg";
+ extension=".jpg";
if(bitMapHasTransparency(cubeTexture.negativeZ,cubeTexture.negativeZ.rect.width,cubeTexture.negativeZ.rect.height))
- extension="png";
- texturePath="textures/"+getFileName(cubeTexture.name)+"_negZ."+extension;
+ extension=".png";
+ texturePath="textures/"+getFileName(cubeTexture.name,extension,"_negZ.");
_blockBody.writeUnsignedInt(texturePath.length);
_blockBody.writeUTFBytes(texturePath);
View
24 awaybuilder-desktop/src/awaybuilder/desktop/model/DesktopDocumentService.as
@@ -142,8 +142,7 @@ package awaybuilder.desktop.model
saveBitmapDataToFile(CubeTextureVO(tex).positiveY,CubeTextureVO(tex).name+"_posY",textureDirectory)
saveBitmapDataToFile(CubeTextureVO(tex).negativeY,CubeTextureVO(tex).name+"_negY",textureDirectory)
saveBitmapDataToFile(CubeTextureVO(tex).positiveZ,CubeTextureVO(tex).name+"_posZ",textureDirectory)
- saveBitmapDataToFile(CubeTextureVO(tex).negativeZ,CubeTextureVO(tex).name+"_negZ",textureDirectory)
-
+ saveBitmapDataToFile(CubeTextureVO(tex).negativeZ,CubeTextureVO(tex).name+"_negZ",textureDirectory)
}
}
}
@@ -154,28 +153,35 @@ package awaybuilder.desktop.model
var encoder : ISceneGraphEncoder = new AWDEncoder();
var returnArray:Array=AWDEncoder(encoder)._encodeBitmap(_bitmapData);
var bytes:ByteArray=returnArray[0];
- extension="jpg";
+ extension=".jpg";
if (returnArray[1])
- extension="png";
- if(textureName.toLowerCase().lastIndexOf(FILE_EXTENSION) != textureName.length - extension.length)
- textureName+="."+extension
+ extension=".png";
+ if(textureName.toLowerCase().lastIndexOf(extension) != textureName.length - extension.length)
+ textureName+=extension
+
var textureFile:File = textureDirectory.resolvePath(textureName);
- if (!textureFile.exists){
+ if (!textureFile.exists){
+ var textureName:String = textureFile.name;
+ textureFile=textureDirectory.resolvePath(textureName);
var saveStream:FileStream = new FileStream();
saveStream.open(textureFile, FileMode.WRITE);
saveStream.writeBytes(bytes);
saveStream.close();
- }
-
+ }
}
+
public function save(document:DocumentModel, path:String):void
{
var bytes:ByteArray = new ByteArray();
var encoder:ISceneGraphEncoder = new AWDEncoder();
var success:Boolean = encoder.encode(document, bytes);
+ if (!document.globalOptions.embedTextures){
+ saveExternalTextures(document,path)
+ }
try
{
+
var file:File = new File(path);
var saveStream:FileStream = new FileStream();
saveStream.open(file, FileMode.WRITE);

0 comments on commit b7e8521

Please sign in to comment.
Something went wrong with that request. Please try again.