3D Color Code Calculator in Away3DLite

May 28, 2010

Color Code Calculator

I did this example to demonstrate how to interactively change the materials of a Collada file in Away3DLite. I build the model in Cinema4D and assigned bands and added colors to those bands. I looked up their names in the out putted Collada file and then assigned materials as requested form the Flash Builder ComboBox using change event methods.

Demo

Color Code Calculator

Color Code Calculator

Video

http://www.youtube.com/watch?v=Wgm14JHXyf8

Source

http://code.google.com/p/lv3d/downloads/detail?name=colorCode.zip

Code Discussion

Here’s example code for the first ComboBox

private function changeEvt1(e:Event):void

{

myOne = e.currentTarget.selectedIndex;

modelResistor.materialLibrary.getMaterial(“ID18”).material = myMatArray[myOne];

calcMyOhms();

}

Code for Calculator Ohms as discussed on the video.

private function calcMyOhms():void {

myOhms = (myOne*10 + myTwo)*Math.pow(10, multiplier[myThree]);

if (myOhms >= 1000000) {

myOhms /= 1000000;

myOutput.text = “Resistance = “ + String(myOhms) + ” MOhms, “ + tolerance[myFour];

} else {

if (myOhms >= 1000) {

myOhms /= 1000;

myOutput.text = “Resistance = “ + String(myOhms) + ” KOhms, “ + tolerance[myFour];

} else {

myOutput.text = “Resistance = “ + String(myOhms) + ” Ohms, “ + tolerance[myFour];

}}}

A similar 2D example was done on the web by Danny Goodman at

http://www.dannyg.com/examples/res2/resistor.htm

Enjoy!

private function changeEvt1(e:Event):void {

myOne = e.currentTarget.selectedIndex;

modelResistor.materialLibrary.getMaterial(“ID18”).material = myMatArray[myOne];

calcMyOhms();

}

private function changeEvt2(e:Event):void {

myTwo = e.currentTarget.selectedIndex;

modelResistor.materialLibrary.getMaterial(“ID8”).material = myMatArray[myTwo];

calcMyOhms();

}

private function changeEvt3(e:Event):void {

myThree = e.currentTarget.selectedIndex;

modelResistor.materialLibrary.getMaterial(“ID23”).material = myMatArray[myThree];

calcMyOhms();

}

private function changeEvt4(e:Event):void {

myFour = e.currentTarget.selectedIndex;

modelResistor.materialLibrary.getMaterial(“ID13”).material = myPerArray[myFour];

calcMyOhms();

}

Advertisements

Creating a Shuriken in Cinema4D (four videos)

May 18, 2010

Creating a Shuriken

In this four part series you learn how to create a Shuriken (throwing star) in Cinema4D.

1. Shuriken in Cinema4D – Photoshop

2. Shuriken in Cinema4D – Array Modifier

3. Shuriken in Cinema4D – Booleans

4. Shuriken in Cinema4D – Applying Textures

Download Model

http://code.google.com/p/lv3d/downloads/detail?name=throwingStar.zip


Humvee in Away3DLite (and PV3D) wheels and steering

May 18, 2010

Intro

In chapter 5 of my book, I discuss how to make a car’s wheels move forwards and backwards and steer. It is actually pretty easy to do in PV3D. But in Away3DLite it is not so obvious. So in the video below I discuss the difference and show you how to get wheel movement and steering working for both PV3D and Awa3DLite.

Video

Driving a Humvee in Away3dLite

Try It Out

Driving a Humvee

Driving a Humvee in Away3DLite

Code

To see the code click the link below:

Read the rest of this entry »


Using Booleans in Cinema4D

May 14, 2010

Intro

In the following two videos I show you how to use Booleans to build a small machine part and add textures to achieve a degree of realism.

Videos

Using Booleans in Cinema4D Part1

Using Booleans in Cinema4D Part2


Collada and Jiglib – how to get it working!

May 3, 2010

Into

I’ve been working on a number of Collada Jiglib projects so I thought I’d put a few videos (and some code) out there so people can use the Collada format in PV3D or Away3d. In the tutorials:

Video1: I start with Cinema4D create a die export it as a Collada file.

Video2: I show you how to bring it into Away3d and show how to hook it up and control it in Jiglib.

Video3:  I show you how to bring the Collada file into PV3D, controlling it in PV3D is very similar to that of Away3d and I’ll be doing a ton of other videos on building PV3D games in the further. Enjoy!

Demo

The demo is similar to the one created by Yagiz Gurgul on Active Tuts but I’ve upgraded it to Flash 10 and I am using a Collada file for the Dice as opposed to the standard square primitives that Yagiz used. In addition, I’ve moved it over to Flash Builder design view which gives me a ton of components and faster design, but does slow the 3D a little.

Dice and Table

Dice and Table

Videos

Collada and Jiglib – Building Cinema4D Dice

Collada and Jiglib – Controlling in Away3d

Collada and Jiglib – Loading into PV3D

Stub Code for Controlling in Away3d (Complete Code Below)

Here is the stub code for bringing in the Collada file and controlling it in Away3d.

private function createmyDice():void {

//model1 = Collada.parse(Charmesh, {scaling:10, material:material, mouseEnabled:false});
collada = new Collada();
collada.scaling = 1.4;

//var carSkin:ObjectContainer3D = ObjectContainer3D(event.loader.handle);
model1 = collada.parseGeometry(MyDie) as ObjectContainer3D;
model1.materialLibrary.getMaterial(“ID3”).material = material4;
model1.materialLibrary.getMaterial(“ID8”).material = material2;
model1.materialLibrary.getMaterial(“ID13”).material = material3;
model1.materialLibrary.getMaterial(“ID18”).material = material1;
model1.materialLibrary.getMaterial(“ID23”).material = material5;
model1.materialLibrary.getMaterial(“ID28”).material = material6;

dieBody= new JBox(new Away3dMesh(model1), 28, 28, 28);
physics.addBody(dieBody);

//model1.mouseEnabled = true;
scene.addChild(model1);
myDices.push(dieBody);
}

Stub Code for Importing into PV3D

Here is the stub code for bring the Collada file into PV3D. Controlling it is very similar to Away3d and you will be covering this in more detail in upcoming videos.

public function initCube() : void
{

// autoplay, name, loop animation
myCubeIs = new DAE(false,null,true);
myCubeIs.addEventListener( FileLoadEvent.LOAD_COMPLETE ,onmyLoad );
myCubeIs.load( ‘die.dae’ );
myCubeIs.addFileSearchPath(“assets/tex”);
myCubeIs.scale = 10;
myCubeIs.z = 300;
myCubeIs.x = -100;
myCubeIs.y = 300;
myCubeIs.rotationY = -90;

}

Full Source

To see the complete source for the Away3d version click the link below:

Read the rest of this entry »


Intertactive 3D Cube with Dynamic Textures

April 30, 2010

Intro

We are moving along with assignment 2 of chapter 2 of Professional Papervisoin3D. And in the first video below you learned how to build the standard Papervision3D class presented  in Chapter 2. And in the next three videos you learned how to use BasicView to build an interactive cube with dynamic textures. Dynamic means that you can change the textures while the program is running just by clicking on them.

PV3D Class

The Papervision3D Class PV3D Book

BasicView Interactive Cube Part 1

Building an Interactive Cube Part 1

BasicView Interactive Cube Part 2

Interactive Cube Part 2


To see the code for the interactive cube Part 1 click the link below:

Read the rest of this entry »


Tips for Optimizing 3D Web Games Part 1 and 2

April 22, 2010

Intro Optimizing 3D Web Games

In this video tutorial set your learn the tricks to optimizing 3D Games for the web.

Videos 1 and 2

Tips for Optimizing 3D Web Games Part 1

Tips for Optimizing 3D Web Games Part 2

Optimization Notes

Tips for Building 3D Games for the Web

3Games – qball (chapter 12), footBall, bowling buddies
elegantly simple and highly addictive

  1. Good news everything is getting faster
    Hey we are native now!
  2. What about cache – careful where you
    put your passwords!!!
  3. A Few Optimization Tips:
    Viewport size
    Unprojection vs Jiglib
    Sprites plus 3D
    Vertice Number
    Tranparency
    Mipmap
    Stage Quality

Video 2: Image Tricks

Optimize your images (the designer developer war)
— Photoshop export for the web!
Avoid Transparency
Mip map your images (2, 4, 8, 16, …1024
Reduce Viewport size (1/3rd + 2/3rd rule)

Count Vertices!!!
Combine low polygon with good sound!!!
This gives a real feel effect.

  • Book List from Chapter 10 Professional Papervison3D
  1. Viewport size-as mentioned earlier rendering your 3D objects to the stage is about 2/3rds of the CPU work. Whenever you can reduce viewport size this lessens the amount that needs to be rendered. So bring your viewport down to the point that you do not diminish game play. In the shooting game this has already been done. But when you design your next game keep this in mind. If you need to fill the entire screen do it with some static graphics.
  2. Transparency-transparency is real CPU killer in PV3D. So in the pool game, get rid of your transparent bounding box material and add a line3D outline instead. It’s not as cool but it’s faster. You’ll have to do a little reprogramming of the PV3D plugin and create a line3D bounding box class to accomplish this.

  3. Movie Clip Animation-Movie clips are expensive items on your CPU-they carry a lot of overhead. You can use a frame ripper instead, which cycles individual bitmaps, or just use a single graphic.

  4. Mipmap all your Graphics and Filters-you’ve already done this for the pool game, but keep this in mind as you create other games in the future.

  5. Use Solid Colors When Possible-whenever possible exchange your texture colors with a solid color. In the case of the pool game, you can dump all your ball textures for solid colors. However, this may save some resources, but it’s guaranteed to make your game look ugly. Use this option sparingly.

  6. Reduce Vertices Number-reducing vertices can make a big difference. For example, if your balls are 8×8 and you reduce them to 8×6 you’ve saved 16 vertices per ball or a total of 160 vertices for 10 balls. It adds up, so whenever possible bring your vertex count down.

  7. Drop the Bullet Imprint-adding more bitmap material slows your processor; dropping the bullet imprint will save some CPU resources.

  8. Drop the Spring Camera-the spring camera requires a few extra iterations and substituting in a Camera3D in this case will make little difference on how your game looks and performs.

  9. Remove tracer filters, line blur, and panel drop shadows-removing drop shadow from your panel will not change much, but removing the line trace blur filter will since you’re generating it every time you shoot.

  10. Remove the tracer line or replace it with a recycling particle or bitmap. The problem with line material in PV3D is that it accumulates in memory and even if you remove it properly, it still waits around for garbage collection. If you really need a tracer, use a recycling particle that doesn’t need to be removed from memory; another option is to use a bitmap.

  11. Drop the Skybox and add a simple background image. Skyboxes are beautiful but can add a serous lug to your game-especially if they are being moved often.

  12. Turn off scroll policies-in Flex, make sure that all scroll policies are turned off. Scroll bars require resources and turning them off saves on CPU resources.

  13. Keep stage quality low (stage.quality=”low”)-setting stage quality to a higher level will cause anti-aliasing to kick in, requiring a x2, or x4 iteration of every frame which is a significant processor hit. In most cases, keeping stage quality low doesn’t make a difference in appearance.

  14. Watch out for hidden background objects. Sometimes in game development objects are left invisible, layered in other objects, or left in the background. You might not see them, but your CPU does. So make sure that all unnecessary objects have been removed from your game.