Wednesday, June 30, 2010

Tracking Vertices In Away3D Animated 3D Models

Tracking Vertex Positions In Away3D MovieMesh Class For Animated Models In Away3dLite (Jan. 28th 2010 )

**Useful for interchangeable handheld weapons for models to find attachment points**

Add MovieMesh Variable Declaration:
public var leftHandx:Number;

public var leftHandy:Number;

public var leftHandz:Number;


MovieMesh.onEnterFrame:

Place after "while(i--)" update of all vertices:

var tempOffset:int = 100;

leftHandx = _vertices[(tempOffset*3)];

leftHandy = _vertices[(tempOffset*3) + 1];

leftHandz = _vertices[(tempOffset*3) + 2];


Added to MyProject code:

mySphere = new Sphere();
mySphere.radius = 10;
mySphere.x = mySphere.y = mySphere.z = 0;
scene.addChild(mySphere);


MyProject.onEnterFrame:

//trace(mesh.leftHandx);
mySphere.x = mesh.leftHandx;
mySphere.y = mesh.leftHandy;
mySphere.z = mesh.leftHandz;

Fixing MD2 Model Animation Play In Away3dLite

Fixing MD2 Model Animation Play ( Away3dLite - Jan. 28th 2010 )

I made a note of this fix early in development of a project where the MD2 animation kept playing in entirety initially and then played the desired loop.

I haven't verified this %100 as an issue as I was using certain test models at the time and attempting proper Md2 generation simultaneously. The following code is my modification to correct this MovieMesh play error in AS3:

In class MovieMesh.onEnterFrame:

//CGG - January 28th 2010 - 11:31 pm

//Added this check and set to stop animation from

//playing through from beginning before finally

//entering desired loop animation


if(_otime == 0){

_otime = getTimer();

}

//end of CGG edit above

NOTE: I checked this out again and I can't see any differences with or without it... was it a frame name problem???

NOTE: I think I just confirmed that this actually is a problem but the best test case is with two animations each with a sizable length like 70 frames. I could barely notice the issue but I uncommented the hack and the problem went away.

The version of Away3DLite should have been the most current as of Jan. 28th 2010.

I wonder if anyone else saw this?

Real Position of Object from Inside a Moving Container in Away3DLite Tutorial

Real Position of a Sphere from Inside a Moving Container in Away3DLite Tutorial (Feb 24th 2010)

The position of an object inside a container is in the local space of the container. Using the current sceneMatrix transformation of the container parent on the contained primitive's position yeilds the absolute position to use as a reference in the overall scene.


This is how to get the real position of a sphere from inside a moving container:

myBasketball.x = PlayerContainer.sceneMatrix3D.transformVector(mySphere.position).x;

myBasketball.y = PlayerContainer.sceneMatrix3D.transformVector(mySphere.position).y;

myBasketball.z = PlayerContainer.sceneMatrix3D.transformVector(mySphere.position).z;


As you can image, if you place a 3D object at some point in an Objectcontainer like a sphere, then you can use these points for reference in placing things like other models, explosions or calculation of any distance from that reference sphere. Do note that a sphere is visible and handy for a while but a non-rendered object with a position member variable itself will do.

All kinds of things are possible using this!

Best regards.

Deactivate Visibility for Bounding Boxes in Away3DLite Tutorial

No Ability to Deactivate Visibility for Bounding Boxes in Away3DLite (Feb 24th 2010)

Ability in is in Base Class Object3D for newer Away3DLite release but needs to be overridden.

//Create Invisible WireframeMaterial for Bounding Boxes
// This Away3D Lite version hack needed until support is added for "visible".
var zeroAlphaMaterial = new WireframeMaterial(0xFFFFFF, 0);


From: http://www.mail-archive.com/away3d-dev@googlegroups.com/msg07411.html

> > I've found where is the problem with WireframeMaterial alpha property,
> > in WireframeMaterial.as the following line
>
> > _graphicsStroke.fill = new GraphicsSolidFill(_color);
>
> > should be changed with
>
> > _graphicsStroke.fill = new GraphicsSolidFill(_color,
> > _alpha);

There are two instances of the line to correct. The important one is in the constructor.

Cheers!

Away3D Tutorial: Accessing Object Group Index from Bounding Box Collision Detection

Accessing Object Group Index from Bounding Box (Feb 24th 2010)

When the collision of a bounding box occurs in my 3D game I wanted to know which character the bounding box belongs too. The "character" is really an obectContainer in an array of objectContainers. Each element in the array represents one character and each element is an obectContainer containing the character model, bounding box and any accessories so they all travel together. The bounding box collision is therefore representative of it's parent's obectContainer collision "with another obectContainer" (which also has a bounding box).

So, I supposed the simplest way to do this would be to edit the Cube primitive class to contain an integer index to use to access other objects in the same group via their respective arrays.

I put the following into the Cube6.as Cube class file:

...
/**
* Creates a 3d Cube primitive.
*/
public class Cube6 extends AbstractPrimitive
{
private var _width:Number = 100;
private var _height:Number = 100;
private var _depth:Number = 100;
private var _segmentsW:int = 1;
private var _segmentsH:int = 1;
private var _segmentsD:int = 1;
private var _pixelBorder:int = 1;

//CGG Added
//Accessing Object Group Index from Bounding Box (Feb 24th 2010)
//Edit the Cube primitive class to contain an integer index to use to access other objects in the same
//group via their respective arrays including obectContainer and mesh(es).
public var groupIndex:int;

...


The var groupIndex:int; is public so we can set and get ourselves. Not ideal but it works.

Correcting Z-Sorting in Away3DLite: Away3D AS3 Tutorial

Away3DLite Tutorial (Feb 18th 2010)

I have a model of an indoor space and the characters feet are showing under the floor at time so I tried my hand at resolving the issue and this was it:

Here in AS3 we change the sort type using the relevant class which has recently changed names from MeshSortType.

Ex: stadium.sortType = SortType.BACK;

This was enough to correct the Z-sorting of the indoor model in Away3DLite. It may very well be the same thing you need to do in the Away3D library. I'm not sure. Unless you are using the new BSP tree in Away3D you will probably need this line.

Either this information was hard to get to or I'm just not very good at finding it but it took some time and trial.

Good luck on your games!

Tuesday, June 29, 2010

Setting Up Your Free Integrated Development Environment: FlashBuilder With Away3D

Installing FlashDevelop with Away3D is straightforward.

Firstly download FD.

Then download Adobe Flex SDK.

This link to the SDK refers to SDK 3.4. You can try a newer SDK version if you like, especially the 4.5 SDK. However, make sure you get roughly 120 megabyte zip file and not the open source version or other unless you want to try.

Here is the screenshot to setup the SDK in FlashDevelop. I've taken a creative liberty and just went ahead and drew in the missing instructions. I guess a picture isn't worth as much as the 3 or 4 words I had to put in. Ha:


So also, to quote the Flashdevelop website: "Java 1.6+ is required for the Flex compiler for ActionScript 3 development."

So make a quick run to the Sun Microsystems Java site and make sure you are installed to at least the 1.6 version of Java. Here is the link to the easy agent: http://www.java.com/en/download/

However, if you want to find 1.6 explicitly and go ahead with just that... congratulations because that is exactly what I did!

Enjoy! Ahhh. Stress Free Computing is what friends are for!