I’ve been playing around with merging some cubes, but getting a weird result, the cubes come out really dark, or weirdly shaded, as if all faces are pointing in the same direction
See the attachments for how they look before and after merging, or have a go for yourself here:
******************************
Merge test
******************************
Here’s my code:
package
{
import away3d.containers.ObjectContainer3D;
import away3d.controllers.HoverController;
import away3d.entities.Mesh;
import away3d.lights.PointLight;
import away3d.materials.lightpickers.StaticLightPicker;
import flash.display.MovieClip;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.text.TextField;
import away3d.containers.View3D;
import away3d.cameras.Camera3D;
import away3d.debug.AwayStats;
import away3d.primitives.CubeGeometry;
import away3d.materials.ColorMaterial;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.display.StageQuality;
import away3d.filters.MotionBlurFilter3D;
import away3d.filters.BloomFilter3D;
import away3d.tools.commands.Merge;
/**
* ...
* @author Mark
*/
public class Main extends Sprite
{
var view:View3D;
var camera:Camera3D;
var _light:PointLight;
var lightPicker:StaticLightPicker;
var testCube:Mesh;
var cubeArray:Array = new Array();
var cubesContainer:ObjectContainer3D = new ObjectContainer3D();
var mBlurFilter:MotionBlurFilter3D;
var bloomFilt:BloomFilter3D;
var camController:HoverDragController;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
init3D();
makeMergeButton();
}
public function init3D():void
{
trace ("init 3D");
view = new View3D();
mBlurFilter = new MotionBlurFilter3D(.3);
bloomFilt = new BloomFilter3D (15, 15, .9, 0, 3);
this.addChild(view);
view.antiAlias = 10;
//view.filters3d = [mBlurFilter, bloomFilt];
view.backgroundColor = 0xffffff;
camera = view.camera;
camController = new HoverDragController(camera, stage);
addChild(new AwayStats(view));
_light = new PointLight();
_light.x = -600;
_light.z = -400;
_light.y = 300;
_light.color = 0xfffffff;
view.scene.addChild(_light);
lightPicker = new StaticLightPicker([_light]);
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
view.scene.addChild(cubesContainer);
makeCubes();
}
private function makeMergeButton():void
{
trace ("Making MergeButton");
var mergeButton:MovieClip = new MovieClip();
var mergeButtonShape:Shape = new Shape();
mergeButtonShape.graphics.lineStyle(2);
mergeButtonShape.graphics.beginFill(0xaaffaa);
mergeButtonShape.graphics.drawRoundRect(0, 0, 200, 40, 5);
mergeButtonShape.graphics.endFill;
mergeButton.addChild(mergeButtonShape);
var mergeButtonText:TextField = new TextField ();
mergeButtonText.text = "Merge Cubes";
mergeButtonText.mouseEnabled = false;
mergeButtonText.x = (mergeButton.width / 2) - (mergeButtonText.width / 2);
mergeButton.addChild(mergeButtonText);
mergeButton.addEventListener(MouseEvent.CLICK, mergeCubes);
mergeButton.buttonMode = true;
mergeButton.x = stage.stageWidth - mergeButton.width - 20;
mergeButton.y = 20;
addChild(mergeButton);
}
private function mergeCubes(e:Event):void
{
trace ("merging Cubes");
for (var i:uint = 0; i < cubesContainer.numChildren; i++)
{
trace ("Found cube number " + i);
}
var merged:Merge = new Merge
var merger:Merge = new Merge(true, false);
var mergedCubes:Mesh = new Mesh(null);
merger.applyToContainer(mergedCubes, cubesContainer);
cubesContainer.visible = false;
view.scene.addChild(mergedCubes)
}
private function test3D():void
{
var testMat:ColorMaterial = new ColorMaterial ();
testMat.lightPicker = lightPicker;
var cubeGeom:CubeGeometry = new CubeGeometry (1000, 100, 100);
testCube = new Mesh (cubeGeom, testMat);
view.scene.addChild(testCube);
}
private function makeCubes():void
{
for (var i:uint; i < 10; i++)
{
var testMat:ColorMaterial = new ColorMaterial (Math.random()*0xFFFFFF);
testMat.lightPicker = lightPicker;
var cubeGeom:CubeGeometry = new CubeGeometry (100, 100, 100);
var Cube = new Mesh (cubeGeom, testMat);
Cube.x = (Math.random() * 1000) - 500;
Cube.y = (Math.random() * 1000)-500;
Cube.z = (Math.random() * 1000)-500;
cubesContainer.addChild(Cube);
cubeArray.push (Cube);
}
}
private function onEnterFrame(e :Event):void
{
view.render();
}
}
}