2012-05-19 43 views
0

我從awayd3D開始,並沒有找到一個版本4.0beta的解決方案,我可以呼籲你。如何使用away3d 4.0 Beta中的多個燈光?

我已經做了許多研究互聯網,希望能找到使用燈光的解釋,而是與每個版本3.

我意識到了這一幕一些解釋(http://goupix.com/test上/)。您可以使用WASD鍵或箭頭鍵移動。

爲了實現這一幕,我有幾個文件: Exploration.as:創建現場,攝像頭和光線。 光:

PointLight light = new(); 
light.x = -2000; 
light.y = 1000; 
light.z = -1000; 
light.color 0xffeeaa =// Here, select the new color of the light source 
view.scene.addChild (light); 

ClassGeneratemap.as:用來裝飾我 ClassGenerateobjet.as生成的表格:由ClassGeneratemap調用和地點的元素在場景

public function onAssetComplete(event:AssetEvent):void { 
    if (event.asset.assetType == AssetType.MESH && event.asset.assetNamespace == token) { 
     AssetLibrary.removeEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete);    
     trace("position : " + posX + " : " + posY); 
     mesh = event.asset as Mesh; 
     mesh.geometry.scale(1); 
     mesh.x = -posX * instData.scale; 
     mesh.z = posY * instData.scale; 
     mesh.castsShadows = true ; 
     //trace("position : " + mesh.x + " : " + mesh.z); 
     instExploration.scene.addChild(mesh); 
    }//End If 
}//End onAssetComplete 

我實在看不出如何使用我放置的燈。我不知道這是否是正確的光。

我希望你能幫助我。 謝謝你從Away3D中的GitHub的

回答

0

拉例子會有所幫助。

https://github.com/away3d/away3d-examples-fp11

/** 
    * Initialize the lights 
    */ 
    private function initLights():void 
    { 
     moonLight = new DirectionalLight(); 
     moonLight.position = new Vector3D(3500, 4500, 10000); // Appear to come from the moon in the sky box. 
     moonLight.lookAt(new Vector3D(0, 0, 0)); 
     moonLight.diffuse = 0.5; 
     moonLight.specular = 0.25; 
     moonLight.color = 0xFFFFFF; 
     scene.addChild(moonLight); 

     cameraLight = new PointLight(); 
     cameraLight.diffuse = 0.25; 
     cameraLight.specular = 0.25; 
     cameraLight.color = 0xFFFFFF; 
     cameraLight.radius = 1000; 
     cameraLight.fallOff = 2000; 
     scene.addChild(cameraLight); 

     skyLight = new DirectionalLight(); 
     skyLight.diffuse = 0.1; 
     skyLight.specular = 0.1; 
     skyLight.color = 0xFFFFFF; 
     scene.addChild(skyLight); 

     lightPicker = new StaticLightPicker([moonLight, cameraLight, skyLight]); 

     //create a global fog method 
     fogMethod = new FogMethod(0, 200000, 0x000000); 
    } 

    private function createTreeShadow(x:Number, z:Number):void 
    { 
     // Paint on the terrain's shadow blend layer 
     var matrix:Matrix = new Matrix(); 
     var dx:Number = (x/terrainWidth + 0.5)*512 - 8; 
     var dy:Number = (-z/terrainDepth + 0.5)*512 - 8; 
     matrix.translate(dx, dy); 
     var treeShadowBitmapData = new BitmapData(16, 16, false, 0x0000FF); 
     treeShadowBitmapData.draw(createGradientSprite(16, 16, 0, 1), matrix); 
     blendBitmapData.draw(treeShadowBitmapData, matrix, null, BlendMode.ADD); 

     // Update the terrain. 
     blendTexture.bitmapData = blendBitmapData; // TODO: invalidation routine not active for blending texture 
    } 

    /** 
    * Initialize the material 
    */ 
    private function initMaterials():void 
    { 
     //create skybox texture 
     cubeTexture = new BitmapCubeTexture(new EnvPosX().bitmapData, new EnvNegX().bitmapData, new EnvPosY().bitmapData, new EnvNegY().bitmapData, new EnvPosZ().bitmapData, new EnvNegZ().bitmapData); 

     //create tree material 
     trunkMaterial = new TextureMaterial(new BitmapTexture(new TrunkDiffuse().bitmapData)); 
     trunkMaterial.normalMap = new BitmapTexture(new TrunkNormals().bitmapData); 
     trunkMaterial.specularMap = new BitmapTexture(new TrunkSpecular().bitmapData); 
     trunkMaterial.diffuseMethod = new BasicDiffuseMethod(); 
     trunkMaterial.specularMethod = new BasicSpecularMethod(); 
     trunkMaterial.addMethod(fogMethod); 
     trunkMaterial.lightPicker = lightPicker; 

     //create leaf material 
     leafMaterial = new TextureMaterial(new BitmapTexture(new LeafDiffuse().bitmapData)); 
     leafMaterial.addMethod(fogMethod); 
     leafMaterial.lightPicker = lightPicker; 

     //create height map 
     heightMapData = new BitmapData(512, 512, false, 0x0); 
     heightMapData.perlinNoise(200, 200, 4, uint(1000*Math.random()), false, true, 7, true); 
     heightMapData.draw(createGradientSprite(512, 512, 1, 0)); 

     //create terrain diffuse method 
     blendBitmapData = heightMapData.clone(); 
     blendBitmapData.threshold(blendBitmapData, blendBitmapData.rect, destPoint, ">", 0x444444, 0xFF00FF00, 0xFFFFFF, true); 
     blendBitmapData.colorTransform(blendBitmapData.rect, new ColorTransform(1, 1, 1, 1, 255, 0, 0, 0)); 
     blendBitmapData.applyFilter(blendBitmapData, blendBitmapData.rect, destPoint, new BlurFilter(16, 16, 3)); 
     blendTexture = new BitmapTexture(blendBitmapData); 
     terrainMethod = new TerrainDiffuseMethod([new BitmapTexture(new Grass().bitmapData), new BitmapTexture(new Rock().bitmapData), new BitmapTexture(new BitmapData(512, 512, false, 0x000000))], blendTexture, [1, 20, 20, 1]); 

     //create terrain material 
     terrainMaterial = new TextureMaterial(new BitmapTexture(heightMapData)); 
     terrainMaterial.diffuseMethod = terrainMethod; 
     terrainMaterial.addMethod(new FogMethod(0, 200000, 0x000000)); //TODO: global fog method affects splats when updated 
     terrainMaterial.lightPicker = lightPicker; 
    } 
+0

首先,非常感謝你。我用PointLight生成我的lightlightPicker = new StaticLightPicker([light]); )和材質(material.lightPicker = lightPicker;)。 我申請我的材料有我所有的網格。 結果如下:(http://goupix.com/test2/)。 該燈確實適用,但沒有陰影網格,並且導入時((.Obj與.Mtl))會丟失顏色。 對於陰影,我將其添加到我的網格上: mesh.castsShadows = true; 沒有結果 如果沒有爲網格的顏色無解,我會練UV展開,但我想,以避免給我的對象的簡單性。 謝謝 – Goupil

+0

用更多的例子更新了我的答案。我已經在我的Blog上編譯了GitHub示例,其中包含每個示例的源代碼:http://www.jasonsturges.com/blog/ –

+0

感謝您的幫助 – Goupil