color each triangles of a Plane in a different color

9 views
Skip to first unread message

fdb

unread,
Aug 3, 2009, 3:05:33 AM8/3/09
to away3d.dev
Hello, I'd like to know the most efficient way to color each triangles
of a Plane in a different color or most generally each triangle of any
surface of a primitive.


I know how to color a certain side of a primitives:

cube.cubeMaterials.left = new ColorMaterial(0xffffff);

but not a specific triangle.

Is there a way to point to this triangle ?

ben

unread,
Aug 3, 2009, 8:15:32 AM8/3/09
to away3d.dev
Hi,
you mean like this :
http://www.vimeo.com/4526936 ( at 0:30 min)

I assume this is a self promotional answer !
;-)

fdb

unread,
Aug 3, 2009, 8:46:38 AM8/3/09
to away3d.dev
Yes like this. Do you want to share the tips ?

Darcey Lloyd

unread,
Aug 3, 2009, 9:13:46 AM8/3/09
to away3...@googlegroups.com
I experimented with maybe something you may find useful to what you want to do.
 
which led to
and
 
I created an object, then using each 3 points of each triangle in the mesh array of that object (i think it was) i looped through them all creating triangles and colouring them as i looped through. I don't have the code to hand but that idea may help?
 
D
 
 
 
 
 
 


 
2009/8/3 fdb <florent....@gmail.com>

Darcey Lloyd

unread,
Aug 3, 2009, 10:52:18 AM8/3/09
to away3...@googlegroups.com
Just remembered some more info, it was something along the lines of for each (var f:face in myplane) or for each (var v:vertex in myplane.vertexes) for the below tests that I created generating an array of triangles within with colourmaterial applied to each.
 
Regarding the video example you showed, if your object it recreated this way, on moue over can apply a new colourmaterial to the triangle.
 
D

2009/8/3 Darcey Lloyd <darcey...@gmail.com>

fdb

unread,
Aug 3, 2009, 11:31:43 AM8/3/09
to away3d.dev
Don't you want to share the as file on you swf ? Some code will be
appreciated.

I just want to know the code to put 2 differents colors on each
triangle of a Plane.

On Aug 3, 4:52 pm, Darcey Lloyd <darcey.ll...@gmail.com> wrote:
> Just remembered some more info, it was something along the lines of for each
> (var f:face in myplane) or for each (var v:vertex in myplane.vertexes) for
> the below tests that I created generating an array of triangles within with
> colourmaterial applied to each.
>
> Regarding the video example you showed, if your object it recreated this
> way, on moue over can apply a new colourmaterial to the triangle.
>
> D
>
> 2009/8/3 Darcey Lloyd <darcey.ll...@gmail.com>
>
> > I experimented with maybe something you may find useful to what you want to
> > do.
>
> >http://www.allforthecode.co.uk/development/away3d/on_dev/01.swf
> > which led to
> >http://www.allforthecode.co.uk/development/away3d/on_dev/04.swf
> > and
> >http://www.allforthecode.co.uk/development/away3d/on_dev/03.swf
>
> > I created an object, then using each 3 points of each triangle in the mesh
> > array of that object (i think it was) i looped through them all creating
> > triangles and colouring them as i looped through. I don't have the code to
> > hand but that idea may help?
>
> > D
>
> > 2009/8/3 fdb <florent.dibart...@gmail.com>

Darcey Lloyd

unread,
Aug 3, 2009, 11:40:32 AM8/3/09
to away3...@googlegroups.com
I don't have the code on me at the moment Florent, I'm at work :(
 
I re-create the object in triangles and then change their material colour.
 
But best i can remember is it was something along the lines of:
 
 
 

package

{

import away3d.cameras.HoverCamera3D;

import away3d.containers.Scene3D;

import away3d.containers.View3D;

import away3d.core.base.Face;

import away3d.materials.ColorMaterial;

import away3d.materials.WireframeMaterial;

import away3d.primitives.Plane;

import away3d.primitives.Triangle;

import flash.display.MovieClip;

import flash.events.Event;

public class Away3DTest extends MovieClip

{

private var scene:Scene3D;

private var camera:HoverCamera3D;

private var view:View3D;

public function Away3DTest()

{

scene =

new Scene3D();

camera =

new HoverCamera3D();

view =

new View3D({scene:scene,camera:camera});

// setup camera

camera.panangle = 0;

camera.tiltangle = 0;

camera.targetpanangle = camera.panangle = 0;

camera.targettiltangle = camera.tiltangle = 0;

camera.mintiltangle = -90;

camera.maxtiltangle = 20;

camera.zoom = 2;

camera.focus = 125;

camera.distance = 250;

view.x = 400/2;

view.y = 400/2;

// Create object

plane =

new Plane();

plane.width = 300;

plane.height = 300;

plane.bothsides =

true;

plane.segmentsH = 2;

plane.segmentsW = 2;

var mat:WireframeMaterial = new WireframeMaterial(0x000000);

plane.material = mat;

view.scene.addChild(plane);

var nTriangleCount:Number = 0;

for each (var f:Face in plane.faces)

{

nTriangleCount++

trace("Triangle " + nTriangleCount);

trace("\t" + "Vertex point 1: " + f.v0.toString());

trace("\t" + "Vertex point 2: " + f.v1.toString());

trace("\t" + "Vertex point 3: " + f.v2.toString());

trace("");

var m:ColorMaterial = new ColorMaterial((Math.random()*100000));

var t:Triangle = new Triangle();

t.bothsides =

true;

t.a = f.v0;

t.b = f.v1;

t.c = f.v2;

view.scene.addChild(t);

}

this.addChild(view);

this.addEventListener(Event.ENTER_FRAME,render);

}

private var plane:Plane;

// --------------------------------------------------------------------------------------------

private function render(e:Event):void

{

// Camera mouse control

camera.targettiltangle = 80 - (stage.mouseY / 2);

camera.targetpanangle = 100 - (stage.mouseX / 2);

//plane.rotationX += 2;

//plane.rotationY += 2;

camera.hover();

view.render();

}

// --------------------------------------------------------------------------------------------

}

}

 
 
 
 
but the for each could have been
 

for

each (var v:Vertex in plane.vertices)

{

 
 
I will see if I still have the dev code back home and post later for you if I do.
 
 
D
 
 
 
 
 
 
 


 
2009/8/3 fdb <florent....@gmail.com>

fdb

unread,
Aug 3, 2009, 11:45:21 AM8/3/09
to away3d.dev
Thank you. I really appreciate.

On Aug 3, 5:40 pm, Darcey Lloyd <darcey.ll...@gmail.com> wrote:
> I don't have the code on me at the moment Florent, I'm at work :(
>
> I re-create the object in triangles and then change their material colour.
>
> But best i can remember is it was something along the lines of:
>
> *
>
> package* {
>
> *import* away3d.cameras.HoverCamera3D;
>
> *import* away3d.containers.Scene3D;
>
> *import* away3d.containers.View3D;
>
> *import* away3d.core.base.Face;
>
> *import* away3d.materials.ColorMaterial;
>
> *import* away3d.materials.WireframeMaterial;
>
> *import* away3d.primitives.Plane;
>
> *import* away3d.primitives.Triangle;
>
> *import* flash.display.MovieClip;
>
> *import* flash.events.Event;
>
> *public* *class* Away3DTest *extends* MovieClip
>
> {
>
> *private* *var* scene:Scene3D;
>
> *private* *var* camera:HoverCamera3D;
>
> *private* *var* view:View3D;
>
>  *public* *function* Away3DTest()
>
> {
>
> scene = *new* Scene3D();
>
> camera = *new* HoverCamera3D();
>
> view = *new* View3D({scene:scene,camera:camera});
>
> *// setup camera
> *
>
> camera.panangle = 0;
>
> camera.tiltangle = 0;
>
> camera.targetpanangle = camera.panangle = 0;
>
> camera.targettiltangle = camera.tiltangle = 0;
>
> camera.mintiltangle = -90;
>
> camera.maxtiltangle = 20;
>
> camera.zoom = 2;
>
> camera.focus = 125;
>
> camera.distance = 250;
>
> view.x = 400/2;
>
> view.y = 400/2;
>
>  *// Create object
> *
>
> plane = *new* Plane();
>
> plane.width = 300;
>
> plane.height = 300;
>
> plane.bothsides = *true*;
>
> plane.segmentsH = 2;
>
> plane.segmentsW = 2;
>
> *var* mat:WireframeMaterial = *new* WireframeMaterial(0x000000);
>
> plane.material = mat;
>
> view.scene.addChild(plane);
>
>  *var* nTriangleCount:Number = 0;
>
> *for* *each* (*var* f:Face *in* plane.faces)
>
> {
>
> nTriangleCount++
>
> *trace*(*"Triangle "* + nTriangleCount);
>
> *trace*(*"\t"* + *"Vertex point 1: "* + f.v0.toString());
>
> *trace*(*"\t"* + *"Vertex point 2: "* + f.v1.toString());
>
> *trace*(*"\t"* + *"Vertex point 3: "* + f.v2.toString());
>
> *trace*(*""*);
>
> *var* m:ColorMaterial = *new* ColorMaterial((Math.random()*100000));
>
> *var* t:Triangle = *new* Triangle();
>
> t.bothsides = *true*;
>
> t.a = f.v0;
>
> t.b = f.v1;
>
> t.c = f.v2;
>
> view.scene.addChild(t);
>
> }
>
>   *this*.addChild(view);
>
> *this*.addEventListener(Event.ENTER_FRAME,render);
>
> }
>
> *private* *var* plane:Plane;
>
> *//
> --------------------------------------------------------------------------------------------
> *
>
> *private* *function* render(e:Event):*void
> *
>
> {
>
> *// Camera mouse control
> *
>
> camera.targettiltangle = 80 - (stage.mouseY / 2);
>
> camera.targetpanangle = 100 - (stage.mouseX / 2);
>
> *//plane.rotationX += 2;
> *
>
> *//plane.rotationY += 2;
> *
>
> camera.hover();
>
> view.render();
>
> }
>
> *//
> --------------------------------------------------------------------------------------------
> *
>
>   }
>
> }
>
> but the for each could have been
>
> *for* *each* (*var* v:Vertex *in* plane.vertices)
>
> *{*
>
> I will see if I still have the dev code back home and post later for you if
> I do.
>
> D
>
> 2009/8/3 fdb <florent.dibart...@gmail.com>
> > > >> > you mean like this :http://www.vimeo.com/4526936( at 0:30 min)

Darcey Lloyd

unread,
Aug 3, 2009, 3:47:27 PM8/3/09
to away3...@googlegroups.com
Hi Florent,

I've just had a search through my code local archives and am unable to locate the dev tests from those links I gave you. You should however be able to SWF Decompile them and get the code that was used. But the quick test code I gave you earlier was along the lines of what was used.

D



2009/8/3 fdb <florent....@gmail.com>
Message has been deleted

fdb

unread,
Aug 3, 2009, 5:38:25 PM8/3/09
to away3d.dev
Yes I'm fine, the code you gave me this afternoon was just what I was
looking for.

On Aug 3, 9:47 pm, Darcey Lloyd <darcey.ll...@gmail.com> wrote:
> Hi Florent,
> I've just had a search through my code local archives and am unable to
> locate the dev tests from those links I gave you. You should however be able
> to SWF Decompile them and get the code that was used. But the quick test
> code I gave you earlier was along the lines of what was used.
>
> D
>
> 2009/8/3 fdb <florent.dibart...@gmail.com>
Reply all
Reply to author
Forward
0 new messages