Away3D Sprite3D 2D screen dimensions


Hi, I’m using Away3D to create a globe with clickable icons orbiting around, and rollover text appearing below.

I have been creating the icons as Sprite3D entities, with Sprite3D elements below with TextureMaterials generated from text drawn to a bitmap, hidden until rollover the icon.

However if I place the text Sprite3D below the icon by a y distance the text position will appear inconsistent when the camera rotates around the scene.

Therefore I’m trying to translate the position of bottom of the Sprite3D icon entity into screen dimensions, or get the Sprite3D icon height in screen dimensions, as they always face the screen.

I know the height in 3D space, and can get the bounds, but that doesn’t help when rotating the camera and seeing the bounding box, or sphere in 3D.

Is there any method to obtain the 2D screen dimensions of a sprite3D?



It looks like you’ll need to calculate the projection of the object

This seems to speak to the topic:

Does any of this help? Please let me know what you try and how it works


Thanks, that pointed me in the right direction, I wasn’t quite able to get the exact height, but with some tweaking did get a consistent result…

var iconDist:Float = getScreenSpaceZ(sprite3D);
var viewH:Float = 2 * ((Math.tan((lensP.fieldOfView / 2) * (Math.PI / 180))) * iconDist);
var iconH:Float = ((sprite3D.height / viewH) * view.height) * 0.88;
var iconPos:Vector3D = view.project(sprite3D.scenePosition);

function getScreenSpaceZ(objectContainer:ObjectContainer3D):Float {
var screenSpacePosition:Vector3D = new Vector3D();
var modelViewProjection:Matrix3D = objectContainer.sceneTransform.clone();
modelViewProjection.copyColumnTo(3, screenSpacePosition);
return screenSpacePosition.z;