Promethe’s Blog Web, RIAs and chocolate spaghettis…

24Dec/086

Display Half Life 3D models with Flash 10

UPDATE: you can find a newer version on the DirectFlex Blog.

It's been a while since the last post. But I'm back and I decided to release the first DirectFlex demo ever :D

This demo is quite simple and features a 3D model extracted from the famous Half Life 1 add on Counter-Strike 1.6. The model is made of "only" 740 polygons, which is not much compared to what DirectFlex can do. Still, being able to display Half Life 1 models inside of Flash with a decent framerate brings hope for future developments. Anyway it is a good proof that DirectFlex is (way) faster than any other Flash 3D "engine" out there... but hey! live demo first and then technical stuff... (Flash 10 required!)


First Person Shooter Camera

This demo features one of the camera classes provided by DirectFlex: FPSCamera. This camera mimics the behavior of a any "classic" doom-like FPS game. Simple use the arrows/AWSD to walk forward/backward/strafe. You can also use the mouse to look around. Nothing fancy except the camera class itself which is really lightweight and easy to overload: I actually created a GhostCamera class based on the FPSCamera class by just adding 2 lines of code... All the camera classes are based on the same AbstractCamera class which makes it possible and really easy to switch from one camera type to another in real time in your application. I will release another demo to show how simple the code actually is.

3DS Loader

A good opportunity to show the 3DS loader in action. Loading and parsing are obviously really fast. The 3DS file is embed inside the SWF file which of course makes it even faster. The 3DS loader was built using this documentation.

Texture Mapping

The texture I used is the original one. I just resized it to make the final SWF file lighter. Nothing crazy about it except that it looks perfectly fine without cutting down the framerate.

Embed Assets

The texture and the 3D model files are embed inside the final SWF file. The mesh and texture class provided by DirectFlex can load such embed assets natively. It is very useful when you just want to redistribute your application without taking care of deploying the assets on a web server and dealing with security issues.

Real Time Lighting

As you can see, the back of the model is completely black. It does not mean that the texture is actually black :D Each polygon is skinned then lighted using a "fake" Phong algorithm. It is a very first draw and a lot of thinking has to be done to make it actually user friendly. Still, because the light and the model are not moving the "real time" part is not really obvious here... I'll try to make it more fancy in the next demo.

About performances

The framerate counter indicates 20-25 frames per second. The application does not force the framerate so the Flash Player runs it at the default framerate (which is supposed to be 24 frames per second). Then, a 20 to 25 frames per second framerate is actually as smooth as it is supposed to be :D It runs perfectly on my Atom 1.6Ghz processor so I guess any decent computer should run it without any performance issue of any kind.

Known issues

The mouse is not handled properly and its sensitivity will depend on the framerate of the application. If your framerate is to high, looking around might be tricky. I know how to fix that but I'm just to lazy to do it for this first demo :P

Z-sorting is not (yet) functional and some glitches might appear. I chose the 3D model carefully so that no major visual defects would occur.

Clipping and frustrum culling are not fully implemented. Major artifacts might appear when the model is rendered is the "back" of the camera.

What's next ?

A MD5 (Doom 3 models) loader is on its way and I will certainly try to load Half Life 2 models too. I am currently working with Alchemy v0.5a to build a fast C++ implementation of BSP trees to implement an efficient and reliable z-sorting algorithm. I will definitely post about Alchemy and my whole C/C++ to AS3 work. I will also release a very cool heightmap demo soon, with some source code to show how user friendly DirectFlex actually is. Other cool demos will follow... Finally, the official DirectFlex blog will be launched soon!

Do not hesitate to post any ideas and comments about how smooth the demo runs on your computer for example.

Comments (6) Trackbacks (1)
  1. Waaah…
    GG comme on dit.
    Ca promet de belles applications reelles… :)

    See you.

  2. Looks very promising. You might want to use arrowkeys to spin the model rather than walk around it, it took a while to get around to the back!
    Is there any plans for a public beta?

  3. The camera is supposed to feel just like a classic doom-like camera. Anyway I admit that with only one model on the screen it does not feel quite the same :D

    There will be a public beta, and the software should be free to use for non commercial projects. I will certainly post about this later.

    I think I will post another demo very soon. Maybe today or tomorrow :D

  4. Hi!

    This is something what I was looking for after Adobe f10 release. Dealing with native functions in right way instead keeping old kind of thinking. But as I understood you even goes step forward and playing on very low level of flash player? How did you achieve that, overwriting core functionality or.. ?

    Another question is why DirectX not OpenGL :) Flash trying to be cross platform from years and I guess more developers from Linux and OSX can’t say that DirectX way is the best way ;) .

    Anyway it is well done. It seems like if everyone saying it’s not possible to do, always you can find somebody who can do that :) .
    However is not graphic support acceleration still but who knows, maybe you can open minds Adobe core developers on new possibilities to put in flash player…

    Good Job dude, can’t wait for beta release.
    Devu

  5. First things first, thank you very much for your comment and your interesting questions! :D

    I’m not using any “tricks”… I am just using Flash 10 native math and drawing methods and try to make it as fast as possible.

    When I talk about DirectX, it does not mean DirectFlex actually uses DirectX (I think you got that point) but that it “feels” like DirectX when you use it. It is just a very general feeling. In the end, DirectX and OpenGL are very much alike… and I think it is easier to go from DirectX to OpenGL than the opposite. The more I work on DirectFlex, the more I take liberties toward DirectX and its formalism. In the end, I only keep the big concepts such as the Device, VertexBuffer/IndexBuffer objects and key methods (Device.drawPrimitives), etc…

    Why DirectX over OpenGL? First because OpenGL is not object oriented, and DirectX is. Second, I used both and I prefer DirectX because to me it feels cleaner and a lot closer to the 3D maths and logic that lays underneath the API itself.

    DirectX is also a good example for other various reasons and I will post about that in details soon :D

  6. Not so good for professional 3D but looks OK. I hope it will be improved in the early future.


Leave a comment