Hi All,
I’m having trouble loading a texture on a primitive Sphere.
Can anyone help?
I’m using Away3D.4.Beta and FlashDevelop.
This is a class that creates a sphere and adds it to Scene3D (lescene) and adds an EventListener to View3D (cam). Both View3D(cam) and Scene(lescene) are passed to it.
The code works fine (great actually) without the texture, just the color red, but when I attempt to load the texture, I just get a black screen.
The code is below. What am I doing wrong?
package
{
import away3d.cameras.Camera3D;
import away3d.containers.Scene3D;
import away3d.containers.View3D;
import away3d.entities.Mesh;
import away3d.materials.ColorMaterial;
import away3d.primitives.SphereGeometry;
import flash.display.Sprite;
import flash.events.Event;
import away3d.events.MouseEvent3D;
import flash.automation.MouseAutomationAction;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.geom.Vector3D;
import flash.net.URLRequest;
import flash.system.Capabilities;
import flash.utils.Timer;
import mx.controls.videoClasses.INCManager;
import away3d.cameras.*;
import away3d.containers.*;
import away3d.controllers.*;
import away3d.debug.*;
import away3d.entities.Mesh;
import away3d.extrusions.*;
import away3d.filters.*;
import away3d.lights.*;
import away3d.materials.*;
import away3d.materials.lightpickers.*;
import away3d.materials.methods.*;
import away3d.primitives.*;
import away3d.textures.*;
import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.text.*;
import flash.ui.*;
/**
* ...
* @author SimNations
*/
public class spherey extends Sprite
{
//Objects
private var mesh:Mesh;
private var sphereGeometry:SphereGeometry;
private var sphereMaterial:TextureMaterial;
//Embeds
[Embed(source = "../../3d_objects/Textures/globeprototype.jpg")]
private var map:Class;
public function spherey(cam,lescene)
{
init(cam,lescene);
}
private function init(cam,lescene):void
{
startEngine(cam,lescene );
}
private function startEngine(cam,lescene):void
{
sphereGeometry = new SphereGeometry(500,100,100);
sphereMaterial = new TextureMaterial(new BitmapTexture((new map()).bitmapData));
mesh = new Mesh(new SphereGeometry(500,100,100), sphereMaterial);
lescene.addChild(mesh);
cam.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void
{
mesh.rotationY++;
event.target.render();
}
}
}
Also, the location of the embed is correct, the code works when the sphere is a color instead of a texture.
private function startEngine(cam,lescene):void
{
sphereGeometry = new SphereGeometry(500,100,100);
sphereMaterial = new ColorMaterial( 0xff0000 );
mesh = new Mesh(sphereGeometry, sphereMaterial);
lescene.addChild(mesh);
cam.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}