This Part of the Shaders Tutorial series will show you how to add colorMaterial shader to either a dae imported object or to a basic primitive.

Colour Material Shader Example

Colour Material Shader Example

If you are a novice, it is advised that you follow this tutorial from the initial section that can be found here, which explains how to set up the files and the scene. Otherwise please read on.

This code is pretty basic / self explanatory, so  I will not be explaining much about it. If you do require any help, just post a comment below.

 

package colorMat {
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFormat;

import org.papervision3d.cameras.CameraType;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.view.BasicView;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.objects.DisplayObject3D;

public class colorMat extends Sprite
{
private var view:BasicView;
private var color:ColorMaterial;
private var sphere:Sphere;

private var tf:TextField;
private var format:TextFormat;

private var dae:DAE;
private var daeFile:String;
private var daeMaterialName:String;

public function colorMat()
{
view = new BasicView(300, 300, false, false, CameraType.FREE);
view.renderer = new BasicRenderEngine(); addChild(view);

color = new ColorMaterial(0xFFD700);

//If you just wanted to add solid colour to a primitive
//object then use the code below
//sphere = new Sphere(color, 150, 8, 8);
//view.scene.addChild(sphere);

//If you want to add colour to a dae object then use this code
daeFile = "YourDAEFILENAME.dae";
dae = new DAE();
dae.load(daeFile, new MaterialsList ( { all:color } ));
dae.scale = 100;

view.scene.addChild(dae);
//OR
view.scene.addChild(sphere);

format = new TextFormat("Arial", 10, 0xFFFFFF);
tf = new TextField(); tf.width = 200; tf.text = "Colour Material (Solid Colour)";
tf.x = 10; tf.y = 10; tf.setTextFormat(format);
addChild(tf);

addEventListener(Event.ENTER_FRAME, onRenderViewport);
}

 

 

 

 

private function onRenderViewport(e:Event):void

{
//spin object on Y axis
dae.rotationY ;
view.singleRender();
}
}
}

If you have been following this tutorial series from the beginning, you will want to add the following code to your MainShader.as file that you created, in order to run your movie.

package {
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.view.BasicView;

import colorMat.colorMat;

public class MainShader extends Sprite {

private var color:colorMat;

 

 

 

public function MainShader() {

color = new colorMat(); color.x = 250;
addChild(color);
}
}
}

If you like this tutorial, why not sign up to our RSS feeds and recieve the latest updates straight to your inbox/reader!

Feel free to leave a comment if you require an help/suggestions, and I will get back to you ASAP. 😀

Be Sociable, Share!

3 Responses to “colorMaterial shader adding Solid Colour to objects”

  • ZesEagefsNo Gravatar says:

    Great site this thierryzoghbi.co.uk and I am really pleased to see you have what I am actually looking for here and this this post is exactly what I am interested in. I shall be pleased to become a regular visitor :)

  • adminNo Gravatar says:

    Thanks for your comment 😀

  • papeBlupt says:

    great site this thierryzoghbi.co.uk great to see you have what I am actually looking for here and this this post is exactly what I am interested in. I shall be pleased to become a regular visitor :)

Leave a Reply

This site is using OpenAvatar based on

Subscribe
Follow me on Twitter
free counters
PayPal Donation
If you like this blog and the help it has given you, why not donate for this good cause? Click on the button below to pay Safely and Securely through PayPal.
Thanks.