How do I create 3D cylinder, sphere and cone using Actionscript 3 (Flash 10)? - actionscript-3

I want to create a 3D cylinder, sphere, cone using Actionscript for Flash Player 10. Is there any available class?
I also want to know how to paint gradient, wrap text and texture around them. It would be nice if these class have these functions. I can't use non DisplayObject in this project so PV3D is not an option

As Cameron says, you should probably use a framework like PV3D or Away3D. That said, all those frameworks are written in AS so you could roll your own.
Here are a few examples I created using only the fp10 3d engine:
http://actionsnippet.com/?p=1726
http://actionsnippet.com/?p=2092
http://actionsnippet.com/?p=2097
http://actionsnippet.com/?p=2158
You can create primative shapes using parametric equations:
sphere :
x = r sin(u) cos(v)
y = r cos(u) cos(v)
z = r sin(v)
For a cylinder you can just use the equation for a circle and extrude it:
x = r cos(t)
y = r sin(t)
z = increase at some interval to the height of the cylinder
I can post some additional information about this topic if your interested.

There are 3D drawing functions for Flash 10, but I don't think they support wrapping text around a 3D object. It sounds like you need a 3D framework. Some popular ones (there's lots):
Sandy3D
Papervision3D
Away3D
Keep mind that Adobe has announced that it will soon be releasing a new version of Flash with built-in hardware-accelerated 3D rendering APIs (codenamed "molehill").

Related

AS3 3D-Renders slowly

Good time.
As you know,3d shapes in as3 are flat surfaces and we can make polyhedrons by moving and rotating that flat surfaces in the three dimensions.
BUT......
what about Non-Polyhedra shapes(spheres,cylinders)??
One way is to make surfaces using flat shapes.
An example to make a cylinder; you can copy this code to see what happens:
import flash.display.Sprite;
const angle:Number=Math.PI/180;
var numOfSides:uint=200;
//number of sides around
var pixWidth:uint=4;
//width and height of sides
var cldHeight:uint=20;
//height of cylinder
var s:Sprite=new Sprite();
s.graphics.beginFill(0xffffff*Math.random());
s.graphics.drawRect(0,0,pixWidth,pixWidth);
addChild(s);
this.cacheAsBitmap=true;
for(var n:uint=1;n<cldHeight;n++){
for(var i:uint=1;i<numOfSides;i++){
var prevS:Sprite=s;
s=new Sprite();
s.graphics.beginFill(0xffffff*Math.random());
s.graphics.drawRect(0,0,pixWidth,pixWidth);
s.x= prevS.x + Math.cos(-prevS.rotationY*angle)*s.width;
s.y=n*pixWidth;
s.z=prevS.z+Math.sin(-prevS.rotationY*angle)*s.width;
s.rotationY=-i*(360/numOfSides);
s.cacheAsBitmap=true;
addChild(s);
}
s=new Sprite();
}
and my problems:
Flash now renders EXTREMELY slow :-(
please improve this code or suggest a better one.
A few minor notes on the code:
Don't forget to end the fill when you're done(e.g. s.graphics.endFill() after the drawRect() call)
cacheAsBitmap works well for display objects without rotation applied if I can remember
4000 (200*20) Sprites with 3D transformations applied might push the display list a bit.
Remember to also sort the sprites
I recommend checking out these resources:
Flash & Math blog Icosahedron 3D tutorial
Senocular's exhaustive FP10 Drawing API article (using drawTriangles() would be more efficient since you'll have a single Sprite on the display list)
If you want to draw the vertices, it should be pretty fast to draw the 3D points projected to 2D on a bitmap
All of the above use Flash Player 10's features, but it might be much simpler to use a 3D API like Away3D which already provides easy ways to draw cylinders (with textures) at very high speeds(especially newer versions that use hardware acceleration)

Action Script: Drawing on video

I was wondering how to draw over a video like this.
http://www.bannerblog.com.au/2009/06/burger_king_sharpie.php
I'm not sure that in the example is drawing process over video. As for me It's a 3d model with video background. And you could sync prerecorded states with 3d object transformations (position, rotation, mesh transformations), or create well textured object.
Here for your tutorial how to draw over the 3D objects
Easy! Use Adobe After Effects (or any number of other compositing programs).

How to draw different shapes using pencil on group container and resize and rotate it in flex4?

All operations like moving,rotating,resizing drawn shape can be performed.I'm using as3 and flex4.6.
It seems like you have to use object handles library for moving,rotating, re sizing shapes ..
you can download this library from the below links.
https://github.com/marc-hughes/ObjectHandles
http://www.objecthandles.com/

Away3d Camera Path

How to know the coordinates of the path if you know the azimuthal angle. I wanna move my camera around an object in away 3d.
Move camera in Spherical coordinate system by Interpolating from starting azimuthal angle to target - it will be your trajectory.
You can convert from\to Cartesian coordinate system to retrive\pass current coordinate to away3d renderer.
You all so may want to use non-linear camera acceleration(for more realistic feel) it can be implemented with Bézier curves
PS. I will be thankful if your publish you realisation because i will need this functional in my next project. You will save me a lot of time :)
Or just use translation and rotation methods that camera inherits from Object3D it's all covered in Away3D example projects. Allso Away3D has path helper package

ActionScript / Flash - Programatically Bitmap-Fill IDE Drawn Vectors?

my current situation maybe akin to me painting myself into a corner.
i have many vector shapes drawn with the Flash Professional CS5 IDE, which have been converted into sprite objects and exported to actionscript. for example, here are 3 shapes:
i want to programatically fill each shape with a bitmap from my library. i realize i can fill these shapes with library bitmaps in the IDE, but i need to scale the bitmaps at runtime as well as swap them out for others.
how is it possible to programatically bitmap-fill shapes drawn within the IDE at runtime without having to also programatically redraw them?
what about using your shapes as masks rather than going through a painful on the fly drawing process ?
it would go like :
bitmap.mask = shape;
as long as shape is a DisplayObject, it should work.
otherwise you can still use a JSFL to export your shapes, store them as arrays of points and draw them at runtime.
here's a basic JSFL export tool
http://ericlin2.tripod.com/bugwire/bugwiret.html
here's an advanced JSFL tool:
http://www.lidev.com.ar/?p=192
here's a ( shamelessly self-promoting :) ) example of an application:
http://en.nicoptere.net/?p=1331
[EDIT]
NB when compiled, your vector shapes are turned into opcode, a set of instructions that you can't read easily.
it remains possible though: http://wahlers.com.br/claus/blog/hacking-swf-1-shapes-in-flash/ but still it's a bit complex if the same result can be achieived with masks :)