A Flash Developer Resource Site

Page 4 of 5 FirstFirst 12345 LastLast
Results 61 to 80 of 93

Thread: [AS2/3][Flash8+] 3d engine kit

  1. #61
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    Those shadows are pretty incredible!
    Also I like that ffilmation example, it looks pretty good the way they did the lighting, and I especially like the way it generates 2 shadows for the 2 lights. It really gives a nice feel to it!

    But I have one question. For your ideas up there, does the shadow need to be texture mapped onto the ground? I can see that slowing things down quite a bit...

    I had a question about your animated texture...Is all you're doing shifting the uv points every frame? I will probably try to implement this into my engine, with simple tools like x and y increment, and row/column height, so that it automates most of the process (You no doubt have already thought of this).

    (My thoughts on both of your ideas, I think that the second one would not only look better, but also work faster...

    P.
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  2. #62
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    testing... (in progress)
    http://renderhjs.net/bbs/flashkit/3d..._version_3.swf

    Quote Originally Posted by Pazil
    But I have one question. For your ideas up there, does the shadow need to be texture mapped onto the ground? I can see that slowing things down quite a bit...
    not for flashkits needs,- he can simply attach (addChild) those shadows below his 3d objects.
    My 2 ideas were anyway only for top down view stuff- side views and alike would not work so nice with this.

    Quote Originally Posted by Pazil
    I had a question about your animated texture...Is all you're doing shifting the uv points every frame? I will probably try to implement this into my engine, with simple tools like x and y increment, and row/column height, so that it automates most of the process (You no doubt have already thought of this).
    I have a custom class that has a spriteSheet bitmapData and a output BitmapData. The output bmpData is of course smaler as it represents 1 cell. As soon as I switch frames it copy pastes pixels from the spriteSheet bitmapData into the bitmapData.
    CopyPixels is very fast in AS3 so it does not hurt a bit. I assume that there are several way for this- altering the UV data would be another one - and propably just as fast.

  3. #63
    FK founder & general loiterer Flashkit's Avatar
    Join Date
    Feb 2000
    Location
    Sydney
    Posts
    1,149
    oooo, very nice.

    Now I can only assume that you must have exams on render... such exquisite procrastination...
    Regards Mark Fennell - Flash Kit Founder, general loiterer
    -------------------------------
    I Hate Zombies - iPhone Game | markfennell.com

  4. #64
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    That seems very promising!

    Just a think I noticed in that cowboy example...the shadow should be flipped before projecting (I think you're doing that in you're current engine?), since the shadow is facing the wrong way it should be.

    I (as usual) have a random question about AS3...how much faster is it working with a byteArray than a conventional one? Could you easily work with a byteArray that's over 360,000 items long, and go through every element atleast 2-10 times? Or would a Shader be better, though I haven't found a lot of info on how the Shader class works...

    Otherwise, for the shadows, I think the cowboy example's shadows are perfectly fine...
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  5. #65
    Junior Member
    Join Date
    Nov 2008
    Posts
    14

    Need help

    Quote Originally Posted by renderhjs
    the function getUVmatrix(uv:Array, pt:Array, tex:BitmapData)
    is the function that gives you the transformation Matrix you need in order to skew, rotate and translate the texture the way it should from UV-map to translated screen triangles.
    PHP Code:
    function getUVmatrix(uv:Array, pt:Array, tex:BitmapData) {
        var 
    a:Matrix = new Matrix();//
        
    var b:Matrix = new Matrix();
        
    a.tx uv[0].xtex.width;
        
    a.ty uv[0].ytex.height;
        
    a.= ( uv[1].uv[0].) ;
        
    a.= ( uv[1].uv[0].) ;
        
    a.= ( uv[2].uv[0].) ;
        
    a.= ( uv[2].uv[0].) ;
        
    b.tx pt[0].x;
        
    b.ty pt[0].y;
        
    b.= ( pt[1].pt[0].) / tex.width;
        
    b.= ( pt[1].pt[0].) / tex.width;
        
    b.= ( pt[2].pt[0].) / tex.height;
        
    b.= ( pt[2].pt[0].) / tex.height;
        
    a.invert();
        
    a.concat(b);
        return 
    a;

    Great thanks for your tutorial. Would you so kind to explian more detailed the matrix operations above? I have isomnia trying to understand how its work.

  6. #66
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    I'm not too sure about exactly how it works, and there's still a few bugs with it.

    In fact, I don't even think that Render knows exactly how it works
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  7. #67
    Funkalicious TOdorus's Avatar
    Join Date
    Nov 2006
    Location
    Nijmegen, Netherlands
    Posts
    697
    Quote Originally Posted by Pazil
    In fact, I don't even think that Render knows exactly how it works
    Blasphemer! Blasphemer!

  8. #68
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    @shaman4d: I can prepare some illustrations that might help understanding what is going on there better.
    As Pazil pointed out its not yet perfect because it fails at non square textures but I understand roughly so far what I did.

    but before I start on that I wanted to post a smal update of the same engine in as3 and a little bit simplified + optimized mainly for myself because I will be at a different computer the next days for replies. It should run 4x,6x or even 10x times faster as AS2 and older. The engine now is roughly 58 lines of code

    (timeline CS3+ AS3 code)
    PHP Code:
    var mainSprite:Sprite = new Sprite();addChild(mainSprite);
    mainSprite.stage.width/2;mainSprite.stage.height/2;
    var 
    bitmap:BitmapData = new Texture(0,0);//BitmapData texture from the library

    var cam:Object = {x:stage.stageWidth/2,y:stage.stageHeight/2,w:160,h:120,d:200};//the camera
    var spr:Graphics mainSprite.graphics;
    var 
    a:Matrix = new Matrix();
    var 
    b:Matrix = new Matrix();

    function 
    get2d(pt:Object) {//3d coordinates to 2d screen coordinates conversion 
        
    var x:int=pt.x+((cam.pt.x)*pt.z/cam.d);//
        
    var y:int=pt.y+((-cam.pt.y)*pt.z/cam.d);//
        
    return {x:x,y:- y,dis:pt.z};
    }
    function 
    render():void {
        var 
    i,j:int 0;
        var 
    pt,vt:Object;
        var 
    tri:Array;//triangle array
        
        
    var faces:Array = [];//order of the faces to be rendered 
        
    for (i=0i<fcs.lengthi++) {//loop through all existing faces
            
    tri = [];//triangle vertex array
            
    var avg:Object = {x:0,y:0,z:0};//average centroid
            
    for (j=0j<3j++) {
                
    vt vtxfcs[i][j] ];
                
    tri.push(get2d(vt));
                
    avg.x+=vt.x;avg.y+=vt.y;avg.z+=vt.z;
            }
            if (  (
    tri[1].x-tri[0].x) * (tri[2].y-tri[0].y) < (tri[2].x-tri[0].x) * (tri[1].y-tri[0].y) ) {//Backface culling 
                
    var uvTri:Array = [tVtxtFcs[i][0] ],tVtxtFcs[i][1] ],tVtxtFcs[i][2] ] ];
                
    faces.push({tri:triuv:uvTridget2d(avg).dis });
            }
        }
        
    faces.sortOn("d", Array.NUMERIC);//sort faces
        
    spr.clear();
        for (
    i=0i<faces.lengthi++) {//loop through the faces to be rendered
            
    tri faces[i].tri;
            var 
    mtx:Matrix getUVmatrixfaces[i].uv tri ,bitmap);
            
    spr.beginBitmapFill(bitmap,mtx);
            
    spr.moveTo(tri[0].x,tri[0].y);
            
    spr.lineTo(tri[1].x,tri[1].y);
            
    spr.lineTo(tri[2].x,tri[2].y);
            
    spr.endFill();
        }
    }
    function 
    getUVmatrix(uv:Array, pt:Array, tex:BitmapData):Matrix {
        var 
    w:int=tex.width;var h:int=tex.height;
        
        
    a.tx uv[0].xw;a.ty uv[0].yh;
        
    a.= ( uv[1].uv[0].) ;
        
    a.= ( uv[1].uv[0].) ;
        
    a.= ( uv[2].uv[0].) ;
        
    a.= ( uv[2].uv[0].) ;

        
    b.tx pt[0].x;b.ty pt[0].y;
        
    b.= ( pt[1].pt[0].) / w;
        
    b.= ( pt[1].pt[0].) / w;
        
    b.= ( pt[2].pt[0].) / h;
        
    b.= ( pt[2].pt[0].) / h;

        
    a.invert();
        
    a.concat(b);
        return 
    a;

    and a enterFrame event controling the engine:
    PHP Code:
    stage.quality="LOW";
    function 
    update(e:Event):void{
        
    cam.= (stage.mouseXstage.stageWidth/2);
        
    cam.= (stage.mouseY stage.stageHeight/2);
        
    render();
    }
    stage.addEventListener(Event.ENTER_FRAMEupdate);//onEnterFrame even 
    Last edited by renderhjs; 12-07-2008 at 06:31 PM.

  9. #69
    Senior Member bomesar's Avatar
    Join Date
    Nov 2006
    Location
    Croatia
    Posts
    136
    Quote Originally Posted by renderhjs
    It should run 4x,6x or even 10x times faster as AS2 and older.
    Is AS2 available as well?
    "Kreativa Studio - Izrada Flash Stranica"

    LATEST: Flash - Mareda Potrčko HTML - Mikrofonija New Layout Design - Tony Robbins || SOCIAL: on Twitter on Facebook on Kontain

  10. #70
    Developer dVyper's Avatar
    Join Date
    Oct 2008
    Location
    UK
    Posts
    168
    You should have placed an entry in that 25 lines contest that Bit-101 setup - you seem to be good in writing powerful stuff in such little code.

  11. #71
    Junior Member
    Join Date
    Nov 2008
    Posts
    14
    @renderhjs thanx for your answer! Im waiting for your explanations!

  12. #72
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    @bomesar: look at first post,- it should be AS1 which is for most people here equal to AS2. The speed improvements however are literally within the AS3 language- so switching sometime will give you alot more speed.

  13. #73
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    Finally...I'm finished basic classes for a 3d engine in as2, but with no importers. I'm just fixing up a few basic rotation functions for an entire object or shape. Also, it doesn't include lighting (which I think if you're writing in as2, it's not that important).
    An importer might be a later project, or I might just write up a simple model editor for flash...

    Anywho, I'm really sorry for all the delays/empty promises, but right now I'm just preparing a simple example for people.

    (I simply solved the "material" issue by allowing people to pass either a colour number or a bitmapData for the material parameter for each shape.)

    (Also, the reason for the big, huge, delay, is that I got carried away with writing classes last time, and it started becoming a big huge mumble jumble, so I decided to restart. This time the classes are simpler but effective, and there's only 6 of them (Render3d.as, Object3d.as, Shape3d.as, Camera3d.as, Point3d.as, and Scene3d.as).)

    All in all, I'm going to have them posted by the next post! That's a promise! And an importer will come sooner or later for the .X3D format (XML).
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  14. #74
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    didn't you had already a own thread for your engine? sorry again but I have the feeling that that would be rather fitting within your thread. The reason why I scrapped classes and alike to begin with in the first post and till now in this thread is because I want to give other people something that is:
    - transparent
    - readable
    - simple
    - basic
    and not like the all the other engines and yours (including my personal others). Anyone that knows how to modify or extend the code I provided can come up with custom classes (like: uv, texture, shader, morphing, model loading, camera, animation, sprite3d, ...).
    So I would rather keep things here stripped down to 1 set of code with no split up into classes and alike - that makes things only more complicated for the ones who want to learn and experiment - so just functions pleaes

  15. #75
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    Sorry...I was going to post the new classes in a separate thread anyways!

    I know that as soon as classes are mentioned, then it all seems to get super complex, but I think that if you had a look at my classes, you'd see how basic they are, plus with comments, it becomes fairly understandable...

    But yes, I will post to another thread soon, and no, I did not already have one...since...well, I restarted my engine as mentioned ^^^

    If there are any functions I come up with...I'll give this thread a shout!

    P.
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  16. #76
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    Quote Originally Posted by renderhjs
    @shaman4d: I can prepare some illustrations that might help understanding what is going on there better.
    As Pazil pointed out its not yet perfect because it fails at non square textures but I understand roughly so far what I did.
    here is the illustration,- i think it does a good job. It could be even fixed now (the non- square issue)

  17. #77
    Junior Member
    Join Date
    Nov 2008
    Posts
    14
    renderhjs — THANKS A LOT! Its so clear and simple!

  18. #78
    Junior Member
    Join Date
    Aug 2007
    Posts
    17
    There are a couple of people on every AS forum I belong to whose posts I watch for and you are one of those on this board. Glad I saw this post, I was not disappointed.

    I look forward to cutting through the grease and seeing how this stuff really works.

  19. #79
    Flash Genie letschillout's Avatar
    Join Date
    Feb 2007
    Location
    31.52949, 74.347272
    Posts
    146
    gr8 work!!!
    Charag - 3D, Flash Games, Animations,
    Website Development & More...


  20. #80
    Senior Member The Helmsman's Avatar
    Join Date
    Aug 2005
    Location
    _root
    Posts
    450
    Thank you for this post, renderhjs.

    You can change the thread name to "Gentle introduction to 3D through the prism of AS3 and Flash 8+".

    I think most of people here on FK have no basic knowledge (including me) on how 3D engine works (for me it's like a miracle) and most of us to lazy to get a big, fat book to get answers. Now we have a brief, short and to the point description on basics with a working code sample.

    I bookmarked this page and planning to study it carefully later.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center