Away3D 4 Broomstick TransformBitmapMaterial

118 views
Skip to first unread message

Darcey Lloyd

unread,
Apr 12, 2011, 7:09:48 AM4/12/11
to away3d.dev
Hi,

Has anyone got TransformBitmapMaterial working in broomstick?

Thanks

Darcey

John Brookes

unread,
Apr 12, 2011, 8:17:53 AM4/12/11
to away3...@googlegroups.com
I would guess its better done though that AGAL thang but.

I was playing about with shifting the UVs other day didnt do rotation.

Make sure the bitmapmaterial has tile set to true.

private function incrementUV(m:Mesh, pos:Point):void
{
    var v:Vector.<Number> = SubGeometry(m.geometry.subGeometries[0]).UVData;
    for (var i:int = 0; i < v.length; i=i+2)
    {
        v[i] += pos.x;
        v[i + 1] += pos.y;
        SubGeometry(m.geometry.subGeometries[0]).updateUVData(v);
    }
}

private function scaleUV(m:Mesh, pos:Point):void
{
    var v:Vector.<Number> = SubGeometry(m.geometry.subGeometries[0]).UVData;
    for (var i:int = 0; i < v.length; i=i+2)
    {
        v[i] += ( pos.x - 1) * 0.5;
        v[i + 1] += (pos.y - 1) * 0.5;
       
        v[i] /= pos.x
        v[i + 1] /= pos.y;
       
        SubGeometry(m.geometry.subGeometries[0]).updateUVData(v);
    }
}

eg
incrementUV(plane, new Point(0.01, 0.01));
scaleUV(plane, new Point(0.99, 0.99));


No idea how safe/good.
was just playing about :)

Darcey Lloyd

unread,
Apr 12, 2011, 8:39:37 AM4/12/11
to away3...@googlegroups.com
Nice, works well, got me a repeating texture and animated.

I've not heard of the AGAL thing, I just done a quick google on it, but I think I'm going to need some examples or docs regarding what it's all about and how to use it.

I am attempting to re-construct this in Broomstick:
and then add to it.

I did try regular poly for the floor like I used in 3.6 but the texture ends up radial. So I'm hoping a plane which is bigger than an outer sphere's diameter will nicely clip the places to form a circular floor in the center of the sphere where the floor will move via your incrementUV function. Testing testing testing...

Cheers for those two functions very handy :)

D

themightyatom

unread,
Apr 14, 2011, 9:36:38 AM4/14/11
to Away3D.dev
Thanks a lot John, I'd been trying to make textures tile en
Broomstick,
and this put me on the right track :)
I've published an example and source to help any other lost souls...

http://videometry.net/broomstick/TextureBroomstick.html


Vatrobot

unread,
Apr 14, 2011, 9:59:20 AM4/14/11
to Away3D.dev
Hi Atom & John,

very usefull post + cool demo, help me alot on other matter too.
For everyone else who stumbled upon Johns "Make sure the
bitmapmaterial has tile set to true." like me:
There is no 'tile'-property in BitmapMaterial-Class, I gues John meant
'bmpMat.repeat = true;'
Please correct me, if I'm wrong.

regards,
Vatro

John Brookes

unread,
Apr 14, 2011, 10:05:41 AM4/14/11
to away3...@googlegroups.com
Yep repeat not tile
Old skool papervision ;)

Should also point out there is actually already a scaleUV function in Broomstick.
Didn't notice it when playing.

Apprentice

unread,
Apr 14, 2011, 11:20:44 AM4/14/11
to Away3D.dev
I know OpenGL has such a thing as a "Texture Matrix" transforming uv
coordinates. That'd be more efficient, transferring computation to gpu
as much as possible to offload cpu. I guess you'd probably have to
write your own fragment shader program for that though and somehow
integrate it with Away3D4 ;o No idea how to do that though :P

themightyatom

unread,
Apr 15, 2011, 3:20:15 AM4/15/11
to Away3D.dev
Oh yes, there's the scaleUV :)

I added an example with that too.
The inbuilt scaleUV accepts just one parameter, so it scales X and Y
by the same amount.
The "manual" approach offers a bit more control, and hopefully
understanding :)

John Brookes

unread,
Apr 15, 2011, 7:55:24 AM4/15/11
to away3...@googlegroups.com
Needed some rotation so did this

private function rotateUV(m:Mesh, rotationDeg:Number, rotateAbout:Point):void

{
    var v:Vector.<Number> = SubGeometry(m.geometry.subGeometries[0]).UVData;
    var r:Number= rotationDeg*(Math.PI/180);

   
    for (var i:int = 0; i < v.length; i=i+2)
    {
        v[i] -= rotateAbout.x;
        v[i + 1] -= rotateAbout.y;
        v[i] = v[i] * Math.cos(r) + v[i + 1] * -Math.sin(r);
        v[i + 1] = v[i] * Math.sin(r) +v[i + 1] * Math.cos(r);
        v[i] += rotateAbout.x;
        v[i + 1] += rotateAbout.y;
    }
    SubGeometry(m.geometry.subGeometries[0]).updateUVData(v);
}

//eg rotate 1 deg about center
rotateUV(plane, 1, new Point(0.5, 0.5));

//eg rotate 90deg about topLeft
rotateUV(plane, 90, new Point(0,0));
Reply all
Reply to author
Forward
0 new messages