Archive for August, 2007

Papervision3D : Introduction of 3D world in Flash

August 30, 2007

Without going in detail about how to download and configure the classpath to use Papervision3D ( if anybody needs the informatin, we can discuss it in the replies ;) ),I will jump directly into code to make a cube, add a material to it and view the object through a camera.To keep things simple, We will be using Flash CS3 IDE, though it can be done in Flex Builder IDE or even free Flex SDK.

1. Create a new Flash file, and name it “intro.fla”.
2. Apply a Document class for “intro.fla” and name it as “Main”. A class file with name “Main.as” must be present in the same folder where “intro.fla” is present.
seting-document-class.gif
Lets write the class now in the “Main.as” file. As usual we will start it with a package declaration as below.
package {
public class Main extends Sprite{

}
}

Now, we will add some import statements for we are going to use those classes in our code as below.
import flash.display.Sprite;

import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.Cube;
import org.papervision3d.materials.MaterialsList;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.scenes.Scene3D;

A new method call is added inside the constructor to make things organised.The updated “Main” class will look as below

package {
import flash.display.Sprite;

import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.Cube;
import org.papervision3d.materials.MaterialsList;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.scenes.Scene3D;

public class Main extends Sprite{
public function Main():void{
init3D();
}
private function init3D():void{
}
}

Now its time to define some properties of the class.We need a container to contain all of our objects.To create the 3D objects we must need a “Scene”.Inside scene we need a “container” for our 3D objects.We are going to make a cube, so we need a “cube” property type also.Till now we need below properties
private var container:Sprite;
private var myScene:Scene3D;
private var rootNode:DisplayObject3D;
private var myCube:Cube;

But without applying material, we can not see a 3D object.So we need Material type also.For this example we will use “Wireframe” material.To apply material we must have a “MaterialsList”, so the new properties are
private var myMatList:MaterialsList;
private var wireMat:WireframeMaterial;

Well, everything is set, finally to look at the 3D scene, we must need a Camera.
private var myCam:Camera3D;

As all the properties are set, I am going to write down the full class file below, then we will discuss about the inside code.
package {
import flash.display.Sprite;

import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.Cube;
import org.papervision3d.materials.MaterialsList;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.scenes.Scene3D;

public class Main extends Sprite{

private var container:Sprite;
private var myScene:Scene3D;
private var rootNode:DisplayObject3D;
private var myCube:Cube;
private var myMatList:MaterialsList;
private var wireMat:WireframeMaterial;
private var myCam:Camera3D;

public function Main():void{
init3D();
}
private function init3D():void{
container=new Sprite();
addChild(container);
container.x=300;
container.y=300;
myScene=new Scene3D(container);
rootNode=new DisplayObject3D(”rootNode”);
myScene.addChild(rootNode);

myMatList=new MaterialsList();
wireMat=new WireframeMaterial(0×000000,1);
myMatList.addMaterial(wireMat,”all”);

myCube=new Cube(myMatList,400,400,400,1,1,1);
rootNode.addChild(myCube);

myCam=new Camera3D();
myCam.x=800;
myCam.y=250;
myCam.z=-400;
//myCam.zoom=10;
//myCam.focus=100;

myScene.renderCamera(myCam);
}
}
}

Well, at this point if you compile and publish the file, you should be able to see a cube with wireframe material as below
final3d.gif
Lets see,what have we done.Firstly “container” is created which is a “Sprite”.This is added to stage and positioned at (300,300).Positioning is required because of the way flash uses its co-ordinate system.We know that flash co-ordinate starts at the left hand top cornore of the stage.If we do not move “container” to the positive direction, then we might not see the created objects as they will go beyound the stage.
Next, a “Scene3D” object created inside the “container”.This object will have all the 3D objects we will create.But to create a 3D object we will need another object of type “DisplayObject3D”, which is actually the container of all the 3D objects and the “Scene3D” is the container of all the “DisplayObject3D” objects.The hyrarchy is as below

Sprite>>>Scene3D>>>DisplayObject3D>>>3D objects

Well, now we will create the 3D object “cube”.But for any 3D objects to be created a material must be created to apply to the object.So first we will create the material and then proceed to create the 3D object with the material.We are going to use “WireframeMaterial” and this material must be added to a “MaterialsList” object type.This is required for a 3D object a material is applied as a “MaterialsList” object.Actually there is more to it, but for simplycity lets assume that we must create a “MaterialsList” and add a matrial to it, so that while creating a 3D object we will apply “MaterialsList”.The material creation is done as
myMatList=new MaterialsList();
wireMat=new WireframeMaterial(0×000000,1);
myMatList.addMaterial(wireMat,”all”);
Next, we will create the 3D object “Cube” as below
myCube=new Cube(myMatList,400,400,400,1,1,1);
rootNode.addChild(myCube);

Thats all for the creation of a 3D object.Hold on a minute, but how to see it.In a 3D environment, one needs a camera to look at objects, even we have our “eyes” which are nothing but cameras to view the world ( Which I think is a 3D enviroment, do not you think so ? ).So finally we must add a camera to view the scene as below
myCam=new Camera3D();
myCam.x=800;
myCam.y=250;
myCam.z=-400;

Again, we have positioned the camera, so as to it will look at the scene not any where else, you can play arround with the camera position and see for yourself how it affects the view.

The last step is to tell flash that everythign is set, now please render the view.This is done by telling to render a particular camera view.There may be more than one cameras in your environment, but you are intersted to view it from a specific camera.So you have to tell, which camera to be rendered.In our case we will do it as
myScene.renderCamera(myCam);
Try experimenting different values for the positioning of “container”, “camera” etc and see the result.This shows a very basic Object creation with a very standard material type.This basically takes you to a quick tour of the PV3D engine.Hopefully this makes some sence and may encourage you to do a lot of 3D Flashing ;)

Added to Macromedia XML News Aggregator

August 30, 2007

Well, good news is this blog of mine is now added to the Macromedia XML News Aggregator (MXNA 2.0). Today I got a mail from Christian Cantrell and Mike Chambers saying the same. I am so happy :), this post just shares my happiness. Thank you guys for approving it to the Macromedia XML News Aggregator.

Architecture after a long time

August 26, 2007

After almost 3 years, I got a chance to work for my old profession(Architecture). This was a quick presentation(a conceptual presentation) for one of my friend in a remote location. He was suppose to get the new client and this presentation was the key. On the other hand, my dear friend had no idea how much work has to be done to convince the client.All he and his office were doing for all the day long was the plans of the hotel.But what about the presentation !!? So in the night around 9PM he called me up and asked whether we can finish it up by today itself (till the next morning).I said yes, a it was the SAT evening and I was searching for a work to get myself refreshed of the current software development works.
Below, is one of the images from the above presentation.From ground up it took me 5 hrs to complete the whole presentation.Amazing, not because I have done it, but because the software is awesome.

one.jpg

Here is the story,I got all the plans from my friend at around 10PM.The first thing came to my mind was Autodesk Revit (its built on BIM technology).I started of the work in REVIT, since I was not in touch for a long long time, it took me some time to get into the speed.I quickly started building the Hotel and around 3AM in the morning, I was almost done with the presentation.The plans, sections, sectional perspectives, exterior perspectives and all the views with shadows :). The experience was awesome and I seriously feel bad about my fellow architects who are still doing their job in AutoCAD.Must try REVIT.

two.jpg

I mailed my friend all the jpgs produced and hit bed around 4AM in the morning.My friend called me up around 8AM and asked how can you made all these in such a small time.I answered with “REVIT”.Well, I am neither a sales person nor promoting Revit in any fashion.But the only thing I would say is “If you are an Architect and doing Architectural projects, whether small or big, must try Revit”.Today, my dear friend is presenting the client, I hope all the best for him.

So, submission at last ( Microsoft goes Opensource )

August 7, 2007

I never thought that would happen, but its very true. Microsoft has already produced a lot of Open source projects lately. And there is a whole portal at Microsoft which talk and share Open source projects by the company.

Whether, we call it their submission or we see it as our own community grow, but the thing is Open source has got potential and power and the FUTURE.

The company which talked a lot about not making products open source, has opened up itself into Open source!! huh.

CAD on FLash !! Its “Floorplanner”.

August 6, 2007

Now, this is one of the best things I have seen and expecting for a long long time. After graduated as an architect I have always worked in AutoCAD and knew all its know hows. But at times I thought of why to use DWF or even PDF to share my CAD drawings rather there should be an easy and one software to do all this. When I got to know Flash, I thought may be Flash is the best option to share drawings or even create it. No point for using high priced products for sharing or creating drawings .

I think finally I got my dreams come true. Here is the online CAD, where one can not only create and print plans, but also share the same. Have a look at Floorplanner.