Having trouble wrapping a Sphere in a Texture/Bitmap

Software: Away3D 4.x

dubletar, Member
Posted: 22 March 2012 12:51 PM   Total Posts: 73

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_FRAMEonEnterFrame);
   
}
   
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 ColorMaterial0xff0000 );
   
mesh = new Mesh(sphereGeometrysphereMaterial);
   
lescene.addChild(mesh);
   
cam.addEventListener(Event.ENTER_FRAMEonEnterFrame);
 
   

Ontheronix, Jr. Member
Posted: 22 March 2012 01:24 PM   Total Posts: 37   [ # 1 ]

For so far I see, it should work. Try with some non-embed bitmapData?

   

dubletar, Member
Posted: 22 March 2012 01:28 PM   Total Posts: 73   [ # 2 ]

When I use the texture script, all I get is a black screen. Nothing shows, at all. When I change back to the color, the full script runs. I can try without the embed and see how that goes.

How would I do it without an Embed? (Still trying to learn the basics since the update to Away3D.4.Beta)

   

Ontheronix, Jr. Member
Posted: 22 March 2012 01:30 PM   Total Posts: 37   [ # 3 ]

Hmm I think that you can access the bitmapData of a Shape (see AS3 Shape class) .

   

Vice, Member
Posted: 22 March 2012 01:41 PM   Total Posts: 58   [ # 4 ]

try:

var bmp : Bitmap = new map() as Bitmap;
sphereMaterial = new TextureMaterial(new BitmapTexture(bmp.bitmapData));

   

dubletar, Member
Posted: 22 March 2012 11:58 PM   Total Posts: 73   [ # 5 ]

Thanks Vice, but all I get is a black screen. downer

A completely black screen.. nothing shows.

   

dubletar, Member
Posted: 23 March 2012 11:47 AM   Total Posts: 73   [ # 6 ]

Does anyone know what Im doing wrong?

   

Qbrain, Member
Posted: 23 March 2012 04:37 PM   Total Posts: 92   [ # 7 ]

is your texture a square file with multiplications from 2?

so for example 256x256, 1024*1024 or 2048*2048?

-Q

   

dubletar, Member
Posted: 24 March 2012 12:18 AM   Total Posts: 73   [ # 8 ]

No, the texture isnt. Should I make it so? I could do that.

Ill try it.

   

Dr Schizo, Newbie
Posted: 24 March 2012 02:41 PM   Total Posts: 11   [ # 9 ]

I didn’t test the code but that should make it:

// creating the mesh
var geometry:SphereGeometry = new SphereGeometry (100);
var 
sphere:Mesh = new Mesh(geometry);
scene.addChild(sphere);

// loading texture
var url:String 'image.jpg';
var 
Ldr:Loader = new Loader();
Ldr.load(new URLRequest(url));
Ldr.contentLoaderInfo.addEventListener(Event.COMPLETEonComplete);
function 
onComplete(e:Event):void
{
     
var bitmap:Bitmap Bitmap(Ldr.content);
     var 
bitmapData:BitmapData bitmap.bitmapData;
     var 
texture:BitmapTexture = new BitmapTexture(bitmapData);
     var 
material:TextureMaterial = new TextureMaterial();
     
material.texture texture;
     
sphere.material material;
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X