Skip to content

Commit

Permalink
drag and drop inside materials
Browse files Browse the repository at this point in the history
  • Loading branch information
keyemkey committed Jul 7, 2013
1 parent a4358c8 commit 0c33881
Show file tree
Hide file tree
Showing 29 changed files with 413 additions and 149 deletions.
4 changes: 3 additions & 1 deletion awaybuilder-core/src/awaybuilder/CoreContext.as
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ package awaybuilder
import awaybuilder.controller.scene.DeleteCommand; import awaybuilder.controller.scene.DeleteCommand;
import awaybuilder.controller.scene.ReparentAnimationCommand; import awaybuilder.controller.scene.ReparentAnimationCommand;
import awaybuilder.controller.scene.ReparentLightCommand; import awaybuilder.controller.scene.ReparentLightCommand;
import awaybuilder.controller.scene.ReparentMaterialEffectCommand;
import awaybuilder.controller.scene.ReparentObjectCommand; import awaybuilder.controller.scene.ReparentObjectCommand;
import awaybuilder.controller.scene.RotateCommand; import awaybuilder.controller.scene.RotateCommand;
import awaybuilder.controller.scene.ScaleCommand; import awaybuilder.controller.scene.ScaleCommand;
Expand All @@ -81,10 +82,10 @@ package awaybuilder
import awaybuilder.controller.scene.TranslateCommand; import awaybuilder.controller.scene.TranslateCommand;
import awaybuilder.controller.scene.TranslatePivotCommand; import awaybuilder.controller.scene.TranslatePivotCommand;
import awaybuilder.controller.scene.events.SceneEvent; import awaybuilder.controller.scene.events.SceneEvent;
import awaybuilder.model.ApplicationModel;
import awaybuilder.model.AssetsModel; import awaybuilder.model.AssetsModel;
import awaybuilder.model.DocumentModel; import awaybuilder.model.DocumentModel;
import awaybuilder.model.UndoRedoModel; import awaybuilder.model.UndoRedoModel;
import awaybuilder.model.ApplicationModel;
import awaybuilder.view.components.CoreEditor; import awaybuilder.view.components.CoreEditor;
import awaybuilder.view.components.EditStatusBar; import awaybuilder.view.components.EditStatusBar;
import awaybuilder.view.components.EditToolBar; import awaybuilder.view.components.EditToolBar;
Expand Down Expand Up @@ -153,6 +154,7 @@ package awaybuilder
commandMap.mapEvent(SceneEvent.REPARENT_OBJECTS, ReparentObjectCommand); commandMap.mapEvent(SceneEvent.REPARENT_OBJECTS, ReparentObjectCommand);
commandMap.mapEvent(SceneEvent.REPARENT_LIGHTS, ReparentLightCommand); commandMap.mapEvent(SceneEvent.REPARENT_LIGHTS, ReparentLightCommand);
commandMap.mapEvent(SceneEvent.REPARENT_ANIMATIONS, ReparentAnimationCommand); commandMap.mapEvent(SceneEvent.REPARENT_ANIMATIONS, ReparentAnimationCommand);
commandMap.mapEvent(SceneEvent.REPARENT_MATERIAL_EFFECT, ReparentMaterialEffectCommand);


commandMap.mapEvent(SceneEvent.CHANGE_MESH, ChangeMeshCommand); commandMap.mapEvent(SceneEvent.CHANGE_MESH, ChangeMeshCommand);
commandMap.mapEvent(SceneEvent.CHANGE_SUBMESH, ChangeSubMeshCommand); commandMap.mapEvent(SceneEvent.CHANGE_SUBMESH, ChangeSubMeshCommand);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package awaybuilder.controller.scene
import awaybuilder.model.DocumentModel; import awaybuilder.model.DocumentModel;
import awaybuilder.model.vo.scene.AssetVO; import awaybuilder.model.vo.scene.AssetVO;
import awaybuilder.model.vo.scene.CubeTextureVO; import awaybuilder.model.vo.scene.CubeTextureVO;
import awaybuilder.model.vo.scene.EffectMethodVO; import awaybuilder.model.vo.scene.EffectVO;


public class AddNewCubeTextureCommand extends HistoryCommandBase public class AddNewCubeTextureCommand extends HistoryCommandBase
{ {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ package awaybuilder.controller.scene
import awaybuilder.controller.history.HistoryCommandBase; import awaybuilder.controller.history.HistoryCommandBase;
import awaybuilder.controller.scene.events.SceneEvent; import awaybuilder.controller.scene.events.SceneEvent;
import awaybuilder.model.DocumentModel; import awaybuilder.model.DocumentModel;
import awaybuilder.model.vo.scene.EffectMethodVO; import awaybuilder.model.vo.scene.EffectVO;
import awaybuilder.model.vo.scene.MaterialVO; import awaybuilder.model.vo.scene.MaterialVO;
import awaybuilder.model.vo.scene.SharedEffectVO;
import awaybuilder.utils.AssetUtil; import awaybuilder.utils.AssetUtil;


public class AddNewEffectMethodCommand extends HistoryCommandBase public class AddNewEffectMethodCommand extends HistoryCommandBase
Expand All @@ -20,16 +21,16 @@ package awaybuilder.controller.scene
{ {
material = event.items[0] as MaterialVO; material = event.items[0] as MaterialVO;
} }
var oldValue:EffectMethodVO = event.oldValue as EffectMethodVO; var oldValue:EffectVO = event.oldValue as EffectVO;
var newValue:EffectMethodVO = event.newValue as EffectMethodVO; var newValue:EffectVO = event.newValue as EffectVO;


if( event.isUndoAction ) if( event.isUndoAction )
{ {
document.removeAsset( document.methods, oldValue ); document.removeAsset( document.materials, oldValue );
} }
else else
{ {
document.methods.addItemAt( newValue, 0 ); document.materials.addItemAt( newValue, 0 );
} }


if( material ) if( material )
Expand All @@ -40,7 +41,7 @@ package awaybuilder.controller.scene
} }
else else
{ {
material.effectMethods.addItem(newValue); material.effectMethods.addItem( new SharedEffectVO(newValue));
} }
material.fillFromMaterial( material ); material.fillFromMaterial( material );
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package awaybuilder.controller.scene
{ {
import awaybuilder.controller.history.HistoryCommandBase; import awaybuilder.controller.history.HistoryCommandBase;
import awaybuilder.controller.scene.events.SceneEvent; import awaybuilder.controller.scene.events.SceneEvent;
import awaybuilder.model.vo.scene.EffectMethodVO; import awaybuilder.model.vo.scene.EffectVO;


public class ChangeEffectMethodCommand extends HistoryCommandBase public class ChangeEffectMethodCommand extends HistoryCommandBase
{ {
Expand All @@ -11,9 +11,9 @@ package awaybuilder.controller.scene


override public function execute():void override public function execute():void
{ {
var newAsset:EffectMethodVO = event.newValue as EffectMethodVO; var newAsset:EffectVO = event.newValue as EffectVO;


var vo:EffectMethodVO = event.items[0] as EffectMethodVO; var vo:EffectVO = event.items[0] as EffectVO;


saveOldValue( event, vo.clone() ); saveOldValue( event, vo.clone() );


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ package awaybuilder.controller.scene
{ {
if( !event.oldValue ) if( !event.oldValue )
{ {
var oldValue:Dictionary = new Dictionary(); var oldValue:Vector.<DroppedAssetVO> = new Vector.<DroppedAssetVO>();
for each( var item:DroppedAssetVO in event.newValue ) for each( var item:DroppedAssetVO in event.newValue )
{ {
var newItem:DroppedAssetVO = new DroppedAssetVO(); var newItem:DroppedAssetVO = new DroppedAssetVO();
Expand All @@ -116,7 +116,7 @@ package awaybuilder.controller.scene
newItem.newPosition = item.newPosition; newItem.newPosition = item.newPosition;
newItem.oldParent = item.newParent; newItem.oldParent = item.newParent;
newItem.oldPosition = item.oldPosition; newItem.oldPosition = item.oldPosition;
oldValue[item.value] = newItem; oldValue.push(newItem);
} }
event.oldValue = oldValue; event.oldValue = oldValue;
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,125 @@
package awaybuilder.controller.scene
{
import awaybuilder.controller.history.HistoryCommandBase;
import awaybuilder.controller.history.HistoryEvent;
import awaybuilder.controller.scene.events.SceneEvent;
import awaybuilder.model.AssetsModel;
import awaybuilder.model.vo.DroppedAssetVO;
import awaybuilder.model.vo.scene.AssetVO;
import awaybuilder.model.vo.scene.EffectVO;
import awaybuilder.model.vo.scene.LightVO;
import awaybuilder.model.vo.scene.MaterialVO;
import awaybuilder.model.vo.scene.SharedEffectVO;

import flash.utils.Dictionary;

import mx.collections.ArrayCollection;

public class ReparentMaterialEffectCommand extends HistoryCommandBase
{
[Inject]
public var event:SceneEvent;

[Inject]
public var assets:AssetsModel;

override public function execute():void
{
saveOldValue( event, event.newValue );

if( event.isUndoAction )
{
undo();
return;
}
var material:MaterialVO;

for each( var item:DroppedAssetVO in event.newValue )
{
if( item.value is EffectVO )
{
if( item.newParent == item.oldParent ) return;

if( item.newParent && !item.oldParent )
{
material = item.newParent as MaterialVO;
if( material && !itemIsInList(material.effectMethods, item.value as AssetVO) )
{
if( item.newPosition < material.effectMethods.length )
{
material.effectMethods.addItemAt( new SharedEffectVO(item.value as EffectVO), item.newPosition );
}
else
{
material.effectMethods.addItem( new SharedEffectVO(item.value as EffectVO) );
}
}
}
}
}

commitHistoryEvent( event );
}
private function undo():void
{
var material:MaterialVO;

for each( var item:DroppedAssetVO in event.newValue )
{
if( item.value is LightVO )
{

if( item.oldParent )
{
material = item.oldParent as MaterialVO;
if( material && itemIsInList(material.effectMethods, item.value as AssetVO) )
{
removeItem( material.effectMethods, item.value as AssetVO );
}
}
}
}
}
private function itemIsInList( collection:ArrayCollection, asset:AssetVO ):Boolean
{
for each( var a:AssetVO in collection )
{
if( a.equals( asset ) ) return true;
}
return false;
}

private function removeItem( source:ArrayCollection, oddItem:AssetVO ):void
{
for (var i:int = 0; i < source.length; i++)
{
var item:AssetVO = source[i] as AssetVO;
if( item.equals( oddItem ) )
{
source.removeItemAt( i );
i--;
}
}
}

override protected function saveOldValue( event:HistoryEvent, prevValue:Object ):void
{
if( !event.oldValue )
{
var oldValue:Vector.<DroppedAssetVO> = new Vector.<DroppedAssetVO>();
for each( var item:DroppedAssetVO in event.newValue )
{
var newItem:DroppedAssetVO = new DroppedAssetVO();
newItem.value = item.value;
newItem.newParent = item.oldParent;
newItem.newPosition = item.newPosition;
newItem.oldParent = item.newParent;
newItem.oldPosition = item.oldPosition;
oldValue.push(newItem);
}
event.oldValue = oldValue;
}
}

}
}
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import flash.events.Event;


public static const CHANGE_GLOBAL_OPTIONS:String = "changeGlobalOptions"; public static const CHANGE_GLOBAL_OPTIONS:String = "changeGlobalOptions";


public static const REPARENT_MATERIAL_EFFECT:String = "reparentMaterialEffect";
public static const REPARENT_ANIMATIONS:String = "reparentAnimations"; public static const REPARENT_ANIMATIONS:String = "reparentAnimations";
public static const REPARENT_OBJECTS:String = "reparentObjects"; public static const REPARENT_OBJECTS:String = "reparentObjects";
public static const REPARENT_LIGHTS:String = "reparentLights"; public static const REPARENT_LIGHTS:String = "reparentLights";
Expand Down
10 changes: 5 additions & 5 deletions awaybuilder-core/src/awaybuilder/model/AssetsModel.as
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ package awaybuilder.model
import awaybuilder.model.vo.scene.CameraVO; import awaybuilder.model.vo.scene.CameraVO;
import awaybuilder.model.vo.scene.ContainerVO; import awaybuilder.model.vo.scene.ContainerVO;
import awaybuilder.model.vo.scene.CubeTextureVO; import awaybuilder.model.vo.scene.CubeTextureVO;
import awaybuilder.model.vo.scene.EffectMethodVO; import awaybuilder.model.vo.scene.EffectVO;
import awaybuilder.model.vo.scene.GeometryVO; import awaybuilder.model.vo.scene.GeometryVO;
import awaybuilder.model.vo.scene.LensVO; import awaybuilder.model.vo.scene.LensVO;
import awaybuilder.model.vo.scene.LightPickerVO; import awaybuilder.model.vo.scene.LightPickerVO;
Expand Down Expand Up @@ -247,14 +247,14 @@ package awaybuilder.model
camera.x = camera.y = camera.z = 0; camera.x = camera.y = camera.z = 0;
return GetAsset(camera) as CameraVO; return GetAsset(camera) as CameraVO;
} }
public function CreateProjectiveTextureMethod( textureProjector:TextureProjectorVO ):EffectMethodVO public function CreateProjectiveTextureMethod( textureProjector:TextureProjectorVO ):EffectVO
{ {
var method:EffectMethodBase = new ProjectiveTextureMethod( GetObject(textureProjector) as TextureProjector ); var method:EffectMethodBase = new ProjectiveTextureMethod( GetObject(textureProjector) as TextureProjector );
method.name = "ProjectiveTexture " + AssetUtil.GetNextId("ProjectiveTexture"); method.name = "ProjectiveTexture " + AssetUtil.GetNextId("ProjectiveTexture");


return GetAsset( method ) as EffectMethodVO; return GetAsset( method ) as EffectVO;
} }
public function CreateEffectMethod( type:String ):EffectMethodVO public function CreateEffectMethod( type:String ):EffectVO
{ {
var method:EffectMethodBase; var method:EffectMethodBase;
switch( type ) switch( type )
Expand Down Expand Up @@ -302,7 +302,7 @@ package awaybuilder.model
EnvMapMethod(method).mask = GetObject(defaultTexture) as Texture2DBase; EnvMapMethod(method).mask = GetObject(defaultTexture) as Texture2DBase;
break; break;
} }
return GetAsset( method ) as EffectMethodVO; return GetAsset( method ) as EffectVO;
} }
public function CreateSkyBox():SkyBoxVO public function CreateSkyBox():SkyBoxVO
{ {
Expand Down
20 changes: 3 additions & 17 deletions awaybuilder-core/src/awaybuilder/model/DocumentModel.as
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package awaybuilder.model
import awaybuilder.model.vo.scene.AssetVO; import awaybuilder.model.vo.scene.AssetVO;
import awaybuilder.model.vo.scene.ContainerVO; import awaybuilder.model.vo.scene.ContainerVO;
import awaybuilder.model.vo.scene.CubeTextureVO; import awaybuilder.model.vo.scene.CubeTextureVO;
import awaybuilder.model.vo.scene.EffectMethodVO; import awaybuilder.model.vo.scene.EffectVO;
import awaybuilder.model.vo.scene.GeometryVO; import awaybuilder.model.vo.scene.GeometryVO;
import awaybuilder.model.vo.scene.LightPickerVO; import awaybuilder.model.vo.scene.LightPickerVO;
import awaybuilder.model.vo.scene.LightVO; import awaybuilder.model.vo.scene.LightVO;
Expand Down Expand Up @@ -159,17 +159,6 @@ package awaybuilder.model
if( lights ) lights.addEventListener(CollectionEvent.COLLECTION_CHANGE, assets_collectionChangeHandler ); if( lights ) lights.addEventListener(CollectionEvent.COLLECTION_CHANGE, assets_collectionChangeHandler );
} }


public function get methods():ArrayCollection
{
return _documentVO.methods;
}
public function set methods(value:ArrayCollection):void
{
if( methods ) methods.removeEventListener(CollectionEvent.COLLECTION_CHANGE, assets_collectionChangeHandler );
_documentVO.methods = value;
if( methods ) methods.addEventListener(CollectionEvent.COLLECTION_CHANGE, assets_collectionChangeHandler );
}

public function fill( data:DocumentVO ):void public function fill( data:DocumentVO ):void
{ {
animations = new ArrayCollection( animations.source.concat( data.animations.source ) ); animations = new ArrayCollection( animations.source.concat( data.animations.source ) );
Expand All @@ -178,12 +167,11 @@ package awaybuilder.model
scene = new ArrayCollection( scene.source.concat( data.scene.source ) ); scene = new ArrayCollection( scene.source.concat( data.scene.source ) );
textures = new ArrayCollection( textures.source.concat( data.textures.source ) ); textures = new ArrayCollection( textures.source.concat( data.textures.source ) );
lights = new ArrayCollection( lights.source.concat( data.lights.source ) ); lights = new ArrayCollection( lights.source.concat( data.lights.source ) );
methods = new ArrayCollection( methods.source.concat( data.methods.source ) );
} }


public function getAllAssets():Array public function getAllAssets():Array
{ {
var assets:Array = scene.source.concat(materials.source.concat(textures.source.concat(animations.source.concat(methods.source.concat(geometry.source.concat(lights.source)))))); var assets:Array = scene.source.concat(materials.source.concat(textures.source.concat(animations.source.concat(geometry.source.concat(lights.source)))));
return assets; return assets;
} }


Expand All @@ -204,7 +192,6 @@ package awaybuilder.model
materials = new ArrayCollection(); materials = new ArrayCollection();
textures = new ArrayCollection(); textures = new ArrayCollection();
geometry = new ArrayCollection(); geometry = new ArrayCollection();
methods = new ArrayCollection();
animations = new ArrayCollection(); animations = new ArrayCollection();
lights = new ArrayCollection(); lights = new ArrayCollection();
_globalOptions = new GlobalOptionsVO(); _globalOptions = new GlobalOptionsVO();
Expand Down Expand Up @@ -266,15 +253,14 @@ package awaybuilder.model
{ {
case( asset is ObjectVO ): case( asset is ObjectVO ):
return scene; return scene;
case( asset is EffectVO ):
case( asset is MaterialVO ): case( asset is MaterialVO ):
return materials; return materials;
case( asset is TextureVO ): case( asset is TextureVO ):
case( asset is CubeTextureVO ): case( asset is CubeTextureVO ):
return textures; return textures;
case( asset is GeometryVO ): case( asset is GeometryVO ):
return geometry; return geometry;
case( asset is EffectMethodVO ):
return methods;
case( asset is LightVO ): case( asset is LightVO ):
case( asset is LightPickerVO ): case( asset is LightPickerVO ):
return lights; return lights;
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ package awaybuilder.model
break; break;
case AssetType.EFFECTS_METHOD: case AssetType.EFFECTS_METHOD:
assets.checkEffectMethodForDefaulttexture(event.asset as EffectMethodBase) assets.checkEffectMethodForDefaulttexture(event.asset as EffectMethodBase)
_document.methods.addItem( assets.GetAsset( event.asset ) ); _document.materials.addItem( assets.GetAsset( event.asset ) );
break; break;
case AssetType.LIGHT: case AssetType.LIGHT:
var light:LightBase = event.asset as LightBase; var light:LightBase = event.asset as LightBase;
Expand Down
Loading

0 comments on commit 0c33881

Please sign in to comment.