New Minko 2 Feature: Ray Casting
Ray casting is a maths feature that makes it possible to fetch all the objects that will cross a "ray". A ray is - as you might have guessed - a simple virtual line represented by an origin point and a direction. It was recently implemented into Minko 2 in the Ray class. More than just the definition of a ray, we also need to be able to test it against some bounding volumes.
This is why we added the following methods:
- BoundingSphere.testRay() to test the intersection between a ray and a bounding sphere
- BoundingBox.testRay() to test the intersection between a ray and a bounding box
Ray casting can be used to add basic mouse interactivity. It is far less powerful than actual pixel-picking - which provides pixel-perfect mouse events and supports hardware accelerated animations - but it is simpler to use and lighter in most cases. Now that Minko has both ray casting and pixel-picking, you're free too chose the methods that fits your needs!
Here is a demo of the ray casting in action:
The code for this application is in the RaycastingExample in minko-examples. Here is how the mouse interactivity is handled:
private function mouseClickHandler(event : MouseEvent) : void { if (_selected) _selected.properties.setProperty('diffuseColor', 0xffffffff); _selected = scene.cast(camera.unproject(event.stageX, event.stageY))[0]; if (_selected) _selected.properties.setProperty('diffuseColor', 0xff0000ff); } |
Getting Started With Minko 2
Update: you can read all of Minko's tutorials on our developers Hub
Update: you can also download the developers reference!
Here is a little blog post for anyone who wants to get started using Minko 2 "from scratch". If you want to build Minko from the sources, be able to easily update it whenever necessary and work with the open source samples this tutorial is for you!
But first things first, a little summary of what's available code-wise:
- minko: Minko's core, and that's already a lot of features (old and new). Among them: the scene graph API, the rendering API, ActionScript shaders with the new compiler/API, ray casting...
- minko-collada: the enhanced Collada extension (minko-collada) to load Collada (*.dae) files.
- minko-picking: the extension to add pixel-perfect mouse interactivity.
- minko-examples: a repository full a simple samples targeting one feature at a time.
And now what is about to be released:
- minko-lighting: the lighting engine extension. We've added a lot of cool features and optimizations, such as projected shadows for every light types.
- minko-3ds and minko-obj: extensions to respectively handle the 3DS and OBJ file formats.
- minko-jiglibflash: the extension to plug JigLibFlash into Minko and add 3D physics
A lot of people ask me about tutorials. The tutorials available on the Hub are not for Minko 2 but for the older version. We didn't have enough time to update them, and that's why we provide minko-examples. It's a lot easier to update and to maintain. But of course, the old tutorials will be ported and a lot of new tutorials will be added in June.
Now let's get started...
Read more...
Optimized AABB-Ray Intersection
As I am working on ray casting for Minko 2, I need to test the intersection between an axis aligned bounding box (AABB) and a ray. In order to do this, I implemented the slab method. Here is how it looks in AS3:
public function testRay(ray : Ray, transform : Matrix4x4 = null, maxDistance : Number = Number.POSITIVE_INFINITY) : Boolean { var localOrigin : Vector4 = transform ? transform.transformVector(ray.origin, TMP_VECTOR4) : ray.origin; var ox : Number = localOrigin.x; var oy : Number = localOrigin.y; var oz : Number = localOrigin.z; var localDirection : Vector4 = transform ? transform.deltaTransformVector(ray.direction, TMP_VECTOR4) : ray.direction; localDirection.normalize(); var dx : Number = 1.0 / localDirection.x; var dy : Number = 1.0 / localDirection.y; var dz : Number = 1.0 / localDirection.z; var minX : Number = _min.x; var minY : Number = _min.y; var minZ : Number = _min.z; var maxX : Number = _max.x; var maxY : Number = _max.y; var maxZ : Number = _max.z; var tx1 : Number = (minX - ox) * dx; var tx2 : Number = (maxX - ox) * dx; var min : Number = tx1 < tx2 ? tx1 : tx2; var max : Number = tx1 > tx2 ? tx1 : tx2; var tmin : Number = min; var tmax : Number = max; var ty1 : Number = (minY - oy) * dy; var ty2 : Number = (maxY - oy) * dy; min = ty1 < ty2 ? ty1 : ty2; max = ty1 > ty2 ? ty1 : ty2; tmin = tmin > min ? tmin : min; tmax = tmax < max ? tmax : max; var tz1 : Number = (minZ - oz) * dz; var tz2 : Number = (maxZ - oz) * dz; min = tz1 < tz2 ? tz1 : tz2; max = tz1 > tz2 ? tz1 : tz2; tmin = tmin > min ? tmin : min; tmax = tmax < max ? tmax : max; return tmax >= Math.max(0, tmin) && tmin < maxDistance; } |
You can find this method in the latest version of the BoundingBox class on github. If you have questions/suggestions, you can post in the comments or on Aerys Answers.
Rave Artificial Intelligence Framework
Developer Tomas Vymazal has released a first video of "Rave", his Artificial Intelligence (AI) framework. This AI framework is built with ActionScript and uses Minko to render the 3D graphics. Here is a video showing some of the features:
According to its author, Rave is soon to be available for licensing (commercial use) and open source (non-commercial). Features:
- A* multilayer pathfinding
- fully customizable NPC control using json defined FSMs (API functions of AI can be called using reflection from json)
- quadtree spatial optimization
- NPC sight (raycasting)
- dynamic obstacle avoidance
- terrain support/awareness
- 3D mesh support/awareness
- bezier path smoothing
Minko 2 Collada Extension Available
We've just pushed the 2.0b branch for minko-collada on github, our Minko extension to load Collada files.
We've patched our Collada files loader to provide much faster parsing times. In our tests, some of the files now take up to 10 times less time to load. You can now load 100+MB *.DAE files containing 600 000 polygons and more, including animations.
Another important addition is that we now parse a lot more data about the materials. We are now able to load material values such as the reflectivity, shininess and more to make it easier for the artists to customize the rendering using their favorite CAO tool.
A small patch will soon will soon not only read this data but use it properly to match the requirements of the new version of the lighting engine (minko-lighting). This patch should be available with the 2.0b branch of minko-lighting, which should be released at the end of next week.
Still, it's very important to remember that material settings and edition are very different matters whether you consider real-time or pre-computed 3D rendering. Thus, Minko Studio and Minko ShaderLab will always be the best way to work on real-time materials:
In this video you see how in just 30 minutes we go from a simple 3D shape to a photo-realistic rendering using only Minko Studio. Using code only, this operation would take hours, if not days.
We're dedicated to make those tools user friendly for the artists in order to provide a smooth developer/designer workflow to target both mobile, web and desktop platforms. Minko Studio is currently being tested by multiple game developers around the world and we've received very positive feedback.
We've also fixed a lot of minor bugs. It was also updated to fit Minko 2 new APIs of course. If you have questions or suggestions, you can post in the comments or on Aerys Answers using the minko-collada tag.


Aerys