Hi Everyone,
I am new in Away3D. I would like to ask the help of everyone because I have been trying to make this code work for the past few days and it seems I am stuck with this LightPicker thingy.
Basically this is my code for initializing the PointLight and LightPicker which is then I used to apply on the texture material of my 3DS file.
private var staticLightPicker:StaticLightPicker;
private var pointlight_0:PointLight;
private function initLights():void
{
pointlight_0 = new PointLight();
pointlight_0.ambientColor = 0xFFFFFF;
pointlight_0.diffuse = 1;
pointlight_0.z = 0;
pointlight_0.x = 0;
pointlight_0.y = 500;
pointlight_0.castsShadows = false;
pointlight_0.ambient = 0.5;
pointlight_0.fallOff = Number.MAX_VALUE ;
pointlight_0.name = "pointlight_0";
pointlight_0.specular = 0.8;
pointlight_0.color = 0xFFFFFF;
pointlight_0.radius = Number.MAX_VALUE ;
// Setup the static light picker
staticLightPicker = new StaticLightPicker([pointlight_0]);
// Add the light to the Away3D scene
scene.addChild(pointlight_0);
}
private var objLoader3d:Loader3D;
private function loadMapObj():void
{
Parsers.enableAllBundled();
var loaderContext:AssetLoaderContext = new AssetLoaderContext(true, "assets2");
objLoader3d = new Loader3D();
objLoader3d.addEventListener(AssetEvent.ASSET_COMPLETE, mapObjAssetLoaded);
objLoader3d.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onAwdComplete);
objLoader3d.load(new URLRequest("assets2/Map_LVL3.3DS"), loaderContext);
}
private function onAwdComplete(e:LoaderEvent):void
{
container3D.addChild(objLoader3d);
}
private var mapTextureMaterial:MaterialBase;
private function mapObjAssetLoaded(e:AssetEvent):void
{
switch (String(e.asset.assetType))
{
case AssetType.MESH:
break;
case AssetType.TEXTURE:
break;
case AssetType.MATERIAL:
if (e.asset is TextureMaterial) {
mapTextureMaterial = e.asset as TextureMaterial;
(mapTextureMaterial as TextureMaterial).lightPicker = staticLightPicker;
(mapTextureMaterial as TextureMaterial).diffuseLightSources = LightSources.LIGHTS;
} else {
mapTextureMaterial = e.asset as ColorMaterial;
(mapTextureMaterial as ColorMaterial).lightPicker = staticLightPicker;
}
break;
case AssetType.GEOMETRY:
break;
default:
break;
}
}
Normally, the 3DS file without LightPicker on my code looks like as per attachment 1.
Using prefab, I attached a LightPicker with it and it looks like as per attachment No 2.
However, if I assign my LightPicker on TextureMaterial in my code it appears like as per attachment No 3. The meshes looks ugly and nothing like attachment no 2.
Any help is greatly appreciated.
Edit: From Prefab3D, it is reporting this message whenever I load the 3DS file:
One or more normals buffers were either empty or invalid(65)
The normals buffer was rebuilded.
If this is what’s causing my problem, how do I do the same thing like Prefab3D to fix the normals as I load the 3DS file.