Showing posts with label 3D. Show all posts
Showing posts with label 3D. Show all posts

Tuesday, 27 September 2016

Sound and Motion


A couple of new experiments testing the Maximo system for use in Unity, and synchronising animation and sound together. I feel Unity is missing a sound bar in the animation timeline, which would enable more accurate synching, and be a big help with the animation.
The figure is again from my forthcoming AR book about the universe.

WebGL demo

Sunday, 28 August 2016

Hello Unity, AIR I still love you.

It's been quite a slow summer workwise, so I've had plenty time on my hands.
I've been toying with an idea to create a "digital pop-up book", that is to say a book that comes complete with a google cardboard headset, and combines a story with Augmented and Virtual Reality.

I created the first version in AIR, and did manage to get everything working. However, performance was not great. I was using four Stage3D Proxies, which worked fine on my own phone, an Oppo 7 Find, but on smaller phones some levels would disappear for no apparent reason, though I suspect there wasn't enough VRAM available. The Oppo has a dedicated graphics chip, and can easily fool you into thinking everything's pukka.

So, time to look at alternatives. I've messed with Unity since the very early days, when I actually talked with David Helgason, one of the founders, and got a free license. The whole thing started in Denmark, and I was a member of the Web3D Consortium, still trying to make solutions with X3D. At this time Flash ruled supreme, so there was no point (for me) to learn Unity. I'd made a javascript bridge between Flux Player (a then open-source X3D engine) and Flash Player, and was having a whale of a time programming in ActionScript and seeing results in 3D. Made a few good solutions on that basis, before Flux player suddenly became a closed technology, and carried a very hefty license fee.

Just when I thought I would have to drop Flash, in order to carry on working with Web3D, Stage3D came along and I've rarely looked back since. But it's time to look forward.

Now, as then, when I open Unity I can't help feeling I've gone back to the Flash MX days.
Attaching scripts to actual graphical objects the way we used to, each MovieClip having an onClipEvent(load) and onClipEvent(enterFrame). I wonder if that was the inspiration for Unity's Start(), Update() template?
In Unity the MovieClip is loosely replaced by the GameObject. That's another thing that put me off Unity. It assumes you're making a game, which generally I'm not.

Unity allows you to program in JavaScript or C#. I was tempted to go with the JavaScript approach, but that seemed like a step backwards after all that AS3 OOP goodness, so I've learned to use C#.
The transition has been completely painless, for apart from slight differences in syntax, everything is quite familiar.

I'm used to sitting with pages of code in FlashDevelop, and only seeing my 3D creations after compiling. I actually wanted a similar workflow in Unity, though now I am getting used to the way Unity works, and the ability to create structure, without necessarily having a "Main" class.
(I found out how to do that too, but don't need my comfort blanket quite as much any more :)
In Unity you do set a lot of variable and properties through the User Interface, but the user interface is created from your own code, so basically if you work the way I do, you are building a custom user interface for Editing and tweeking your application as you go along. This is actually a very cool approach. I just never got that far in my previous brief attempts to master Unity.

Once you discover the power of a full blown 3D engine, it's easy to go mad.
As I work primarily on Mobile and tablet, I have had to tone it down a bit, but it's fantastic to be able to work in a WYSIWYG environment again, the way we used to in the early Flash years.

Visual Studio is a pleasure to code in. Once I got the intellisense working, I've been able to use it to discover all the properties and methods available on different types of objects and I'm now feeling just as at home as in FlashDevelop.

Unlike most Flashers, I'm not quitting AS3 to take up a new technology, just adding to my toolbox.
Now I'm feeling comfortable with C# a whole new world has opened up and I'm excited to see where it takes me.

My first experiments have been in "Mixed Reality", that is a combination of Virtual and Augmented reality using the Vuforia library. Sometimes it's so easy it feels like cheating. While ActionScript has always been a challenging platform to master (and therefore in itself very satisfying when getting something to work!!), the combination of Unity and C# provides a powerhouse of new possibilities, as all the simple stuff is taken care of. I'm not used to anything being "under the hood", and even libraries like Away3D, I've customised and modified for my own ends.

Though I've had to go from Flash Hero to Unity Zero, I'm quickly clawing my way up to where I can call myself a Unity Developer.

Friday, 2 September 2011

Playing Havok with Flash 11


click here to open (requires Flash 11 beta2 or higher)

I remember the title of a book for salesmen, called "Fake it 'til You Make It", the idea being to fake being successful until you actually become successful. While I haven't been able to make a physics engine to rival Havok in AS3, I have found a novel way to fake it by using reactor (powered by Havok in 3D Studio MAX) to create simulations I can export to Away3D. 
The resulting animation is written into a series of bitmaps that together form a small movie of the vertex movements.

Although the animation is baked (and the observant will notice it runs in a ping-pong loop right now) it's still possible to adjust the amount of effect (here "Wind Speed") programmatically, so you could call it "Half Baked". 
Borrowing from a bloke called Einstein, I applied my own little "theory of relativity" and registered deviations from the rest position instead of absolute values. This way you can "mix" in the animation and even apply it to completely different meshes.

I soon realised that the resulting "animation movie" or "video space warp"  (the funny coloured blocks you see when not running in Fullscreen) was actually resolution independent, that is to say it could be applied to meshes of any number of vertices. That helped solve another issue I was having, LOD. With this image based method you can achieve seamless level of detail changes even while the animation is running.
Flash is great at interpolating pixel colours, so you can even read values between pixels without much maths.

I realise that one could just register all the vertex positions into a ByteArray (which is actually what is happening under the hood) but I think it's nice to be able to see the animation and it's certainly easier to interpolate between values for different Mesh resolutions.
Another benefit I'm exploring is streaming the animation, after all video streaming and compression are built into Flash, so why not? Take it a step further and you could stream 3D scenes over an ordinary TV signal.

If you'd got the time and $'s you could completely redefine the idea of "3D TV"...

Much more to come, I suspect :O)


Thursday, 16 June 2011

BroomHill tech demo

To celebrate the newly unveiled Away3D website, and to showcase the power of Broomstick and Molehill compared to previous Flash players and Away3D frameworks, I wanted to share this little client demo. (Incubator player required).

UPDATE: Flash 11 Beta is out on labs and the example has been modified to run under the new F11 plugin. Incubator users should update before clicking the image below.

Zooming in (mousewheel) reveals detailed textures mixing bitmap and vector graphics. (Just type in the box to change the text).


Getting even closer you can see the actual structure of the micro-mesh, even the microscopic holes. 


 And my favourite, the "shwoosh", a real-time physics simulation that just shows how different this player/framework combo really is.
Congratulations Away3D team on this awesome new framework and site :) 

Tuesday, 17 May 2011

Mocap to Molehill, via 3D Studio MAX and Away3D Broomstick

After seeing David Lenaerts excellent Broomstick example, I've been eager to find a workflow to bring motion capture data into Flash. It took a while to work out, not being familiar with the MD5 format at all, but it turned out those nice guys at Away3D had already done all the hard work. I was thinking I'd have to map the bones of MAX's Biped to some other custom "MD5 scheme", but to my delight I discovered the parser is extremely generic and works with any bone structure I throw at it. I'd like to share my findings, not least in case I forget them before I need to do it again :O)

First a quick demo to show where we're headed...

(Click image to open, Flash 11 or incubator is required.) 

WARNING: The page loads around 14Mb of Motion Capture data, so be patient. When it's finished the "player" should start moving on his own. Click to put the flash window in focus, then use arrow keys to run, and the top row of keys (Q to I) to trigger different mocap files.  

You'll notice the motion is quite faithfully replicated, though there are some problems with the figure/bone structure around the shoulders. That could be fixed given the time, but I was satisfied with this as a proof of concept.
For this recipe you will need:
If you use that particular model you will see that it comes already rigged using Biped.
Biped is one of the Bone systems that ships with Max. Some love it, some hate it. The good thing is there's alot of free motion capture data recorded in the ".bip" format, to get you started.

Normally you use Max's Physique modifier together with Biped. This is a quite advanced system using muscles and tendons. The MD5 format doesn't support that system directly, so we need to use a Skin modifier instead. 
(Click for larger image)

After you open the soccer player, select the model, right click on the modifier and select "Collapse All".
Now you should have an Editable Mesh. This is the only format the MD5 exporter can work with so it's worth remembering.
Now we have an Editable Mesh and a Biped lined up with each other, but not attached in any way.
With the player still selected, choose the "Skin" modifier.
Where it says Bones, press the "Add" button and assign all the bones of the Biped to the Skin modifier (this will be all the objects in the scene). Then you modifier stack should look like this:


Now it's time to load some Motion Capture (or Mocap) Data. Select Bip01 (easiest by pressing the H key and selecting it from the list of scene objects) and then under the motion panel, press the Load icon and find a .bip file from your harddrive. If you don't have any .bip files, here's one from the Max Tutorials.


You will find a folder full of .bip files on your Max DVD under Tutorials, as well as loads of free downloads on the net. 
So now we should have an animation when you press play. The Soccer player should move in perfect synch with your Biped. You might notice a few odd bulges, especially round the legs and feet.


This is caused be the legs "pulling" on each other, and it's now we need to understand a little bit about how Skin and Bones (in this case Biped) work. 

Each bone acts upon a group of vertices in the Skin. A vertex may have more than one bone acting upon it. So for each bone there is an array of indices for the vertices in the model that it effects, and not only that, but each of those vertices has a "weight", i.e. the amount the bone pulls on that vertex.
To make it easier in 3D Studio, and other 3D programs, the bones are assigned an Envelope. This simply means a sausage shape around the bone's core that encapsulates the vertices. If in 3D studio, we select the soccer player again and "Edit Envelopes", when we select a bone from the list, the envelope of that bone is shown in the viewport.

Note, your own viewport may not look exactly the same, depending on the settings under "Display".
In the illustration you can see the envelope of the Left Foot. There are highlighted in colour, the vertices it effects. Red means they're effected a lot, blue means they're effected a little. Notice that some vertices on the other foot are highlighted in blue. This has happened because in the models start position, the feet were close together, and therefore the vertices on one foot were within the envelope of the other. This is the cause of many issues when setting up Bone systems, also referred to as Rigging.
Max offers many ways of editing envelopes, but I'm only going to talk about one quick and dirty method for now. The darker red circles around the foot represent the limits of the effect area for that bone. By clicking on the small grey boxes where they intersect you can select that outer limit, and then adjust it's radius, either by dragging on it, or more precisely with the number spinner in the menu. By making it smaller, at some stage the vertices of the other foot are no longer effected. You need to adjust both feet before the model starts to look right. Then continue with the carves and thighs.
This subject is covered better in other tutorials on the net, but that should get you started.

NOTE: Make sure you have no zero weights in your model. If a vertex is connected to a bone with a weight of 0.000, it has the effect of attaching that vertex to the root of the model when imported into Away3D.
To avoid this, when you have finished rigging, set the "Remove Zero Limit" in the skin modifier palette to 0.01 and hit "Remove Zero Weights". You are then ready to export.

Finally it's time to export to MD5. Under Max Script, choose Run Script and find the MD5 exporter script you downloaded earlier. I tend to put my scripts in the script folder of Max, just because it's the default directory opened by Max. 


Choose export and you'll be prompted to choose a name for your file. Then you will be asked for another name for the animation file. These two files (.md5mesh and .md5anim) are needed for the mocap animation, and generally speaking need to come from the same model. However, when you have exported one mesh, you can then apply another bip file and tick "export md5anim only" so you use the same model with different motion files, as in the example.

NOTE: When you press "Export", your computer will most likely freeze. Max Script, much like other scripting languages, can paralyse your processor when running through big loops, and believe me there's a lot of number crunching and writing going on here. My advice, go make a cup of coffee. On my machine the exporter hasn't actually crashed yet, though I have sometimes lost patience with it and restarted Max. You can improve performance, by going into Max's preferences and increasing the allocated memory for script. (Customize>Preferences>Max Script> Initial Heap Allocation). I set mine to 50Mb. 

Now all that's left is to look at the source for David Lenaerts example from the Away3D repository and start swapping his files out with your own. I have included the entire source of my effort here, though admittedly it's not commented very well. The material has been made into a mipmap, i.e. resized to a square in Photoshop.
For some reason the texture coordinates get reversed between md5 and Broomstick. I guess this may change in future builds, but for now the work around was simply to reverse the number on the players shirt in Photoshop.

Disclaimer: The Broomstick branch of Away3D is in constant development, as is the Flash player, and there is no guarantee these files will work with your installed library, without a little tweeking :O)
(They are compiled against the github version, 24th may.)

NOTE: A difference in the coordinate space between MD5 format and Flash results in all models and animations being mirrored on the x-axis when viewed in Away3D 4.0
To see animations and models as they appear in MAX, simply apply a scaleX = -1; after import to Away3D.

Enjoy! And please comment with your successes, failures, comments and tips!

UPDATE: In response to the high demand, (from MatOfLink at least) here's a method for putting guns in hands, shoes on feet, hats on head, etc.
When your MD5 mesh has loaded, add a Loader3D to it. This is where your prop will appear.


gunholder = new Loader3D();
gunholder.addEventListener(LoaderEvent.RESOURCE_COMPLETE, adjustGun);
_mesh.addChild(gunholder);


So far so good. When the gun loads it will likely be twisted in relation to the rest of the model, depending on which format it is and which software it was exported from. For obj files coming from Max I've found this simple routine aligns the object the same way as in Max. At the same time you can apply materials.


private function adjustGun(evt:LoaderEvent):void {

var i:int;
var gunMat:BitmapFileMaterial = new BitmapFileMaterial("assets/images/gun.jpg");
for (i = 0; i < gunholder.numChildren; i++) {
var m:Mesh = gunholder.getChildAt(i) as Mesh;
m.rotationX = 90; 
m.rotationY = 90;
m.material = gunMat;
}
}


Now your gun should be in the viewport. You need to know the index of the particular bone you want to follow. This you can either read in the debugger, by trial and error, or via the jointIndexFromName from name function on the skeleton class (later...)


Once you know the index of the bone (called "joint" in Away3d) you want to follow add this to your rendering loop:


gunHolder.transform = (_mesh.animationState as SkeletonAnimationState).globalPose.jointPoses[26].toMatrix3D();


And that's it! You basketball player is now armed and dangerous.
If I get round to it I'll post an updated source. Otherwise shout out below for help!


Now let's see some games...





Saturday, 16 April 2011

Waves and models



A practical application of a wave formula, animating a Manta Ray.

To keep the body steady while animating the "wings" the formula applies amplitude depending on distance from the centre, multiplied by a cosine to give a fairly smooth transition from centre to wing tip. The formula is still fairly simple and can definatly be improved upon. The movement, though graceful is not true to life (yet).

The Coast/Swim button will freeze and start the animation less abruptly then simply turning animation on and off.

This demo was inspired by a WebGL JellyFish by Aleksandar Rodic.

The source files are there. The model, by "Kare Ola" can be downloaded from TurboSquid

Friday, 15 April 2011

Wave Modifier



Spurned on by the success of my first Away3D 4.0 Experiment and what with it being friday afternoon, I thought I'd try another one.
After looking at the docs (I know, cheating really) I tried making a wave modifier.
Considering the maths is all on the CPU it runs quite well. There is massive room for optimisation by making the wave function run as a GPU program. Maybe something for next friday...

Looking at the code it might look complicated, but that's just me over-engineering the demo. The interesting bit is "incrementWave" that basically moves all vertices in the Z plane using a sign function, depending on their x and y positions.

"Change Image" gives you a grid pattern so you can see the wave more clearly.

Thursday, 14 April 2011

Away3d 4.0

Now that the Flash player 11 alpha is in the wild, the Away3d team have released Broomstick, a GPU accelerated version, with the familiar feel of Away.
Development with Molehill is not for the faint hearted, and accessing the alpha technology through an alpha framework is bound to cause you to start smoking again, but hey, it's also fun to pioneer new technology.

For a primer on the "new" way to do 3D, and a sum up of the technologies, you could do worse than check out this presentation, "brief" (about 100 slides) about Flash, WebGL and Unity. http://www.inear.se/2011/04/a-brief-introduction-to-3d/

Lucky for me, I've got time to play with this stuff right now.
Experiments to follow...

Monday, 28 September 2009

3D Studio MAX clone - alpha 0.0.1 :)

A friend of mine has been making 2D floorplan tools in Flash since MX.
A couple of years ago I built a 3D option for him, based on the then open source Flux player(X3D).
When MediaMachines turned into Vivaty, the javascript API broke and player was no longer open source, and that was the end of the solution we spent 6 months developing. Ouch! Since then we've been looking for another option based on open source technology.
In the meantime, maybe flash has come of age to do this type of thing?
I've seen Autodesk's attempt, and while I understand their thinking, for me going totally isometric/single angle is just too big a compromise.


As a proof of concept I used a couple of hours making a demo in Away3DLite. Out of laziness and lack of time I've used the Plane primitive for walls, where a custom class is called for to add thickness and get around z-ordering issues.

So here it is, the simplest 3D editor you're likely to see :)
http://www.videometry.net/floorplan/


Use the pencil to draw a few boxes and hit the "3D" icon for a rough 3d model. Be warned at the moment the eraser just clears everything, without a prompt.

UPDATE: Save floorplan or 3d drawing as .png, straight to your harddisk.
Flash 10 required, but hey, you wouldn't be here if you didn't have FP10, right? :)

Monday, 21 September 2009

Atomic Fusion



Still playing around with Away3dLite.

It's a huge advantage when you want to extend a framework for your own purposes, that the framework itself is compact and understandable. That's certainly the case with this lastest version of Away3d. I've been working for some time with high fidelity models, X3D import and custom material filters. This work has been easy to migrate to Away3dLite, which is an even faster rendering engine then anything I've been able to code. I look forward to publishing all the fruits of this labour, but for now here's a demo done last friday afternoon just for the fun of it.

http://www.videometry.net/away3d/chopper.html
and source files...
http://www.videometry.net/away3d/Chopper.zip

Enjoy!

Sunday, 13 September 2009

Away3d lite, first test

The first test og Away3dLite looks promising.
http://www.videometry.net/away3d/AwayTest.html
(Click the screen to start)

I fudged the BitmapMaterial so I could use a shader as input.
At 30 fps there seems to be no performance hit at all. At higher framerates the shader does cause a dip compared to using a plain bitmap. The size of textures seems to affect framerates dramitically when using shaders generally.

Saturday, 12 September 2009

Normal Mapping



Normal mapping has now been added to Atomic.

Normal maps provide a fast alternative to, for example phong shading and other lighting models, and at the same time enhances simple geometry.
The normal filter adds less than 1Kb to the size of the engine, but adds a fast, smooth, directional lighting.

Click the image to open the example, click and drag to rotate and zoom

Tuesday, 8 September 2009

Atomic Kitten

Atomic, the new 3D renderer is purring like a kitten, even with full mapping and baked ambient occlusion.
http://www.videometry.net/atomic/town.html



There's zoom when you click and drag in the y-axis. I discovered to my horror the scrollwheel *still* doesn't work natively in Flash player 10 on Mac. Sorry about that, will use alternative from now on...

Wednesday, 2 September 2009

Introducing Atomic

Here's a first glimpse of our new 3D class for Flash10, Atomic.
Wait a while for the 300K model to load then click the screen to start. There's some primitve navigation via mouse position.

This actual t-shirt design is available at http://www.bluebaldur.com/

The idea of Atomic is to be like the atom itself, very small yet surprisingly powerful.
Rendering quality is the number one priority, closely followed by speed. Materials are written as shaders in Pixel Bender. The example uses a material that combines a Normal and Diffuse map.

Why a new "flash 3D engine"? With Flashplayer 10, a little knowledge of 3D maths and shaders, the developer can arguably achieve just as good, and maybe even better results using Flashes inbuilt classes than importing large external libraries.
The missing element right now is that Flash player supports no native 3D formats, and that the drawing API does not support native z-sorting. Atomic handles these two issues, leaving the rest up to the developer and the particular project.