Jump to content
Search Community

Search the Community

Showing results for tags 'away3d starling 3dsmax'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • GreenSock Forums
    • GSAP
    • Banner Animation
    • Jobs & Freelance
  • Flash / ActionScript Archive
    • GSAP (Flash)
    • Loading (Flash)
    • TransformManager (Flash)

Product Groups

  • Club GreenSock
  • TransformManager
  • Supercharge

Categories

There are no results to display.


Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Personal Website


Twitter


CodePen


Company Website


Location


Interests

Found 1 result

  1. Hello Everyone and Happy New year! I have been fully re-working my website using Greensock (Flash) to leverage the Starling Away3D framework. I have found that many people ask the same questions about how to use the incredible power of the Greensock code to take care of the loading of Starling and Away3D assets: Here are some code examples from the Preloader ClassFile: 1. LoaderMax loader that queues and loads a 3DSMax (Obj) model, myModel, for a second Content Classfile: //======================================================== //*** Variable declarations for Main Loader.*** // //======================================================== private var mainQueue:LoaderMax = new LoaderMax({name: "mainQueue", rawProgress: 1, onProgress: ProgressHandler, onComplete: completeHandler}); //========================================================== //*** LoaderMax Loader.*** // //========================================================== LoaderMax.defaultAuditSize = false; mainQueue.append(myModel); mainQueue.load(); mainQueue.addEventListener(LoaderEvent.COMPLETE, completeHandler); mainQueue.addEventListener(LoaderEvent.PROGRESS, ProgressHandler); 2. Here is a close look at the DataLoader Variable that I am using in the Loader above. The DataLoader has the model path (assets/myModel.obj) and the name (SkyScraper) that I am giving the model, so that I can access it in the other class file //========================================================================= //*** Variable declarations for Away3D Model Preloading.*** // //========================================================================= private var myModel:DataLoader = new DataLoader("assets/myModel.obj", {name: "SkyScraper", format: "text", rawProgress: 1, autoPlay: false}); This is all that is needed in the preloader class. The 3DSMax model will be loaded by the DataLoader in text format. The next step is important and must be done before testing: 1. Open the .obj file in notepad and make sure that the path to the .mtl file is correct. In my example I had to re-write the path from Object: myModel to Object: assets/myModel since the .obj file and its .mtl file were added to the assets folder for my website. If you do not do this, you have the chance of encountering a Network streaming error complaining about the inability to resolve your .mtl file location when testing your flash page. I will now show you how to access the model information that we need in the content class. Here are the code examples from my Content Class File, which needs to access the model data so that it can be shown in the content page: //======================================================== // //*** DataLoaders for Model Meshes.*** //*** Mesh Variable Declarations.*** // //======================================================== private var skyScraperModelText:String = LoaderMax.getContent("SkyScraper"); private var modelMesh:Mesh; In the code chunk above, I have asked to getContent on the name of the DataLoader from the Preloader classfile and that information has been stored in the new string variable skyScraperModelText. I have also declared a new mesh variable "modelMesh" for later usage. //=========================================================== // //*** Loader for the Portfolio Mesh *** // //=========================================================== meshLoader = new Loader3D(); meshLoader.loadData(skyScraperModelText); meshLoader.addEventListener(AssetEvent.ASSET_COMPLETE, modelLoaderHandler); This chunk of code allows the Loader3D (Away3D) to have access to the Obj model data that we have already pre-loaded using Greensock. The new eventListener will then fire our last chunk of code, which will load the Obj data from the String variable and start applying textures to each 3DsMax model layer that I created when setting the model up: NOTE: Most of the code below is extraneous to the act of loading the model into the content class so that it can be rendered on a webpage. I have left it in so that you can see the process that I am using to dynamically apply my own texture to the mesh layer. There are actually 9 case switches in my real code that apply 8 different textures to the 8 different model layers, but 1 is enough for the example. private function modelLoaderHandler(e:AssetEvent):void { trace("Portfolio Symbol Mesh Loaded!"); //============================================================== // //*** Set up Away3D Model Textures and Assign the Lights. *** // //============================================================== var boxModelCubeTexBase:Texture2DBase = new BitmapTexture(boxModelCube.rawContent.bitmapData); var boxModelOuterRingTexBase:Texture2DBase = new BitmapTexture(boxModelOuterRing.rawContent.bitmapData); var boxModelInnerRingTexBase:Texture2DBase = new BitmapTexture(boxModelInnerRing.rawContent.bitmapData); var boxModelLettersTexBase:Texture2DBase = new BitmapTexture(boxModelLetters.rawContent.bitmapData); switch (String(profileMeshVar)) { case "0": runFirstMaterialSwitchPA(); // MaxBody Mesh break; case "1": meshLoader.removeEventListener(AssetEvent.ASSET_COMPLETE, modelLoaderHandler); trace("Profile Model Ready for Render Engine!!!"); break; } function runFirstMaterialSwitchPA():void { trace("Applying First Profile Model Material!") //======================================================================== // //*** First Material is applied to the Main Box Object *** // //======================================================================== switch (String(e.asset.assetType)) { case "mesh": // Assign mesh modelMesh = e.asset as Mesh; // Loop through mesh assigning materials to the sub meshes for each (var m:SubMesh in modelMesh.subMeshes) { trace("APPLYING PROFILE MATERIAL TO SURFACE 0!!!!!"); //============================================================= // //*** Set up Away3D Model Textures and Assign the Lights. *** // //============================================================= var cubeMaterial:ColorMaterial = new ColorMaterial(0xffffff); cubeMaterial.ambientColor = 0xdd5525; cubeMaterial.ambient = 1; //0xdd5525; cubeMaterial.specular = .5; cubeMaterial.diffuseMethod = new CelDiffuseMethod(3); cubeMaterial.specularMethod = new CelSpecularMethod(); cubeMaterial.addMethod(new OutlineMethod(0x000000, 5, true)); CelSpecularMethod(cubeMaterial.specularMethod).smoothness = .01; CelDiffuseMethod(cubeMaterial.diffuseMethod).smoothness = .01; cubeMaterial.normalMap = Cast.bitmapTexture(boxModelCubeTexBase); cubeMaterial.repeat = true; cubeMaterial.lightPicker = lightPicker; //============================================================= // //*** Find the Model Assets using the Loader and their Level. * // //============================================================= m.material = cubeMaterial; } break; case "material": trace("This is a material and not a model!!!"); break; default: trace("UNHANDLED ASSET TYPE: " + e.asset.assetType); break; } } The true take-away chunk of code from the bit above is part of the first switch statement: switch (String(e.asset.assetType)) { case "mesh": // Assign mesh modelMesh = e.asset as Mesh; blah blah blah more code { The e.asset String is being converted to a mesh and my modelMesh variable is being declared equal to it and therefore now contains the important Obj model asset information. Voila!!! The later code uses switch statements to apply different textures to the different Obj model layers, but that is for another topic I hope that someone else finds this useful and wastes less time searching for answers -Cheers
×
×
  • Create New...