A Flash Developer Resource Site

Page 1 of 6 12345 ... LastLast
Results 1 to 20 of 108

Thread: [as3][3d] little 3d texturing demo

  1. #1
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756

    [as3][3d] little 3d texturing demo


    online demo

    older demo from earlier today:
    older demo


    what I have so far
    - backface culling
    - fast affine texture mapping without seams
    - dynamicly loaded meshes and textures
    - alpha opacity on textures (can be turned off)

    apart from that list losts of other things have to be done from now on, but I am already happy that I cam this far.

    This demo (intended as one) is a preparation for my next semester here at my university wich will be for once a flash game
    I wanted to know If I could write a fast 3d engine and since the results are way beyond what I expected at first I´ll propably stick with it then.

    The game is supposed to be an adventure and a big chunk of what it will be about are colors (this topic was already given from my professor). I will be doing this project together with another friend of me who will do 3d modeling and designing stuff.
    For the engine I plan a vey simple point and click expierence with pathfinding around obstacles- point and shoot ability with projectile weapons. Smal loading times are important for wich I already wrote a custom binary 3d format. Besides those another goal is to find a good workflow between 3dsmax and Flash on the modeling, rendering and asset placement part.

  2. #2
    Senior Member ihoss.com's Avatar
    Join Date
    Oct 2004
    Location
    Norway
    Posts
    581
    There is a depthsorting problem here. Look at the gun when you rotate the model. It moves behind the guy when it should move in front. It could be that you aren't hiding objects with negative depth (ie, behind the camera) or you arent using swapdepth propperly. Apart from that its very cool.

  3. #3
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    no sorting at all right now- that´s what I am digging into soon. THe current effect only relies on backface culling wich hides the faces wich are not faced towards the camera- but a sorting needs to be added.

  4. #4
    Senior Member ihoss.com's Avatar
    Join Date
    Oct 2004
    Location
    Norway
    Posts
    581
    Whats your algorithm for backface culling? Do you calculate it before or after you calculate the position of the triangle?

    For sorting I allways wanted to calculate the order of the faces and then render them in that order the next time. This would be pretty efficient if you used a binary tree or something to sort the faces. But it would not leave a perfect result every frame though.

  5. #5
    Senior Member
    Join Date
    Nov 2003
    Location
    Las Vegas
    Posts
    770
    Very nice! Works smooth on my old 533mhz test box too!

    One bug I noticed besides the gun's depth is the ends of the hands. If you rotate till looking from the side, then rotate till you are looking straight down the arm, the end of the hands gets culled.

    Can't wait to see what you do with this!

  6. #6
    Senior Member bomesar's Avatar
    Join Date
    Nov 2006
    Location
    Croatia
    Posts
    136
    Excellent I must say. Tell me, if this is a small demo, what the big one looks like?
    Could you possibly add an FPS counter? I'm interested in performance on different configurations.

  7. #7
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    Quote Originally Posted by JerryScript
    Very nice! Works smooth on my old 533mhz test box too!
    One bug I noticed besides the gun's depth is the ends of the hands.
    I have at home one 700 Mhz computer it´s acceptable but not the best. I still believe that I can tweak here and there.
    Regarding the hands- for now it is intended as I was expermenting with low poly tricks using less triangles resulting into something you wouldn´t expect with such a few.
    The head however still has to much


    Quote Originally Posted by ihoss.com
    Whats your algorithm for backface culling? Do you calculate it before or after you calculate the position of the triangle?
    nothing complex for now- I´ve read into some tutorials regarding that and while most suggest by doing it via calculating the face normal and compare it with the camera normal I found something way easier for me (perhaps even less CPU intense).
    Since the meshes I write with 3dsmax always have clockwise Triangle points (A,B,C) this simplified condition works as well:
    PHP Code:
    for (var i:int=0;i<faces.length;i++){

        var 
    A:Object getScreenPts(faces[i].a);
        var 
    B:Object getScreenPts(faces[i].b);
        var 
    C:Object getScreenPts(faces[i].c);
        if (  (
    B.x-A.x)*(C.y-A.y) < (C.x-A.x)*(B.y-A.y)  ){//backface culling
            
    texture.drawTri(sprite,i,[A,B,C]);//draw the triangle into the sprite as face i with A,B,C
        
    }
    }] 
    Quote Originally Posted by bomesar
    Excellent I must say. Tell me, if this is a small demo, what the big one looks like?
    well for what is certain some propper scene management so that I can load multiple meshes with several textures into 1 active scene.
    I am working already somewhat on vertex animation inside maxscript so that it exports certain keyframes as snapshot from the vertexes wich moved meanwhile.

    Quote Originally Posted by bomesar
    Could you possibly add an FPS counter? I'm interested in performance on different configurations.
    will do that,- need to know soon myself where I improved or made it slower- also on what total polycount I can count on in the end.

  8. #8
    hippie hater Cimmerian's Avatar
    Join Date
    Oct 2006
    Location
    over there
    Posts
    599
    Code:
    for (var i:int=0;i<faces.length;i++){ 
    
        var A:Object = getScreenPts(faces[i].a); 
        var B:Object = getScreenPts(faces[i].b); 
        var C:Object = getScreenPts(faces[i].c); 
        if (  (B.x-A.x)*(C.y-A.y) < (C.x-A.x)*(B.y-A.y)  ){//backface culling 
            texture.drawTri(sprite,i,[A,B,C]);//draw the triangle into the sprite as face i with A,B,C 
        } 
    }]
    Thats nice, but what if you had many triangles looking to the camera and some of them are in front of the others?

  9. #9
    Senior Member ihoss.com's Avatar
    Join Date
    Oct 2004
    Location
    Norway
    Posts
    581
    That algorithm only deals with faces looking away from the camera (backface culling), not faces that are hidden (clipping). I don't think any flash engine does clipping yet.

    I thought some more about depth sorting (without swapDepths) and I'm pretty certain it can be done with a binary heap. That way the total time it takes to sort the faces is n*log(n), which is pretty good.

  10. #10
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    swapDepths isn´t an option anyway (not in AS3) since I need to sort my faces within the array- and render that array out.
    I thought about some zBuffering alike methods where I mark the areas that are already drawn and compare new triangles that are covered by that area if they are behind or infront of it and either ignore them or render them.

    For now I am thinking just for a simple z-depth sorting towards the camera and render the triangles in that order- but until that I need to fix a little bit my camera model so that it returns depth values.
    Last edited by renderhjs; 03-02-2008 at 10:07 AM.

  11. #11
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    927
    why any of these were not good for you?
    who is this? a word of friendly advice: FFS stop using AS2

  12. #12
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    Quote Originally Posted by realMakc
    why any of these were not good for you?
    I didn´t even botherd to look at their code because:
    - to complex to understand at first and bloated with function I dont need
    - most of them are universal packages and they try to do anything (phng shading, normal mapping, bump mapping,...) 90% of those features are things I dont want for my project- they are more oriented to the masses who use it and dont know all the math behind it.
    - trying to understand it myself instead of depending on a framework/ package. That way I might be able to port knowledge gained here to other projects with perhaps other technologies. This happend already many times in my past
    - add special features for wich I need more expierence and be able to understand everything I have so far.

    you might think yet another 3d engine (which is indeed hyped lately) but my interest is primary research. I wrote for this already some interesting Max -> Flash and visa versa scripts wich is something I think seperates me at least from the others.
    Anyway explaining myself shouldn´t be the discussion here

  13. #13
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    update:

    demo 4
    - faster
    - z-depth sorting
    - fps counter

  14. #14
    Senior Member ihoss.com's Avatar
    Join Date
    Oct 2004
    Location
    Norway
    Posts
    581
    The cubes ran at 39 fps, but the guy ran at about 20.

    I agree with render, understanding how the engine works is a good reason to make one yourself.

  15. #15
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    gotta say, awesome stuff, ran really smooth for me, 40's

    lather yourself up with soap - soap arcade

  16. #16
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    thx malee

    something I played with today:

    will be added in the next demo (an with fixed textures, the UV is a mess)
    - added a xml menu so I can easier add/ update test models

  17. #17
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    update:

    demo 5
    - again faster (+10 fps here)
    - file menu with a little selection
    - target FPS optimal face count- this is to measure at some point the target poly count for a scene to run at 24 fps (perhaps I´ll drop it then even at 20 fps wich is acceptable for an adventure game I think)

    (and propper UV´s now for link + a render to texture version with baked lights from mental Ray)

  18. #18
    Senior Member bomesar's Avatar
    Join Date
    Nov 2006
    Location
    Croatia
    Posts
    136
    My God this is outstanding. Runs better here but with major FPS drop (like 15-20 FPS less) when zoomed in.

  19. #19
    Now tell me whos watchin...... samvillian's Avatar
    Join Date
    Feb 2007
    Location
    Where do you live?
    Posts
    539
    very good, the cube gets around 59 fps. the zelda from 39(zoom out) to 28(zoomed in). very nice.

  20. #20
    Senior Member rachil0's Avatar
    Join Date
    Jul 2007
    Location
    Columbus, OH.
    Posts
    465
    Totally cool demo! Hadn't seen that little green guy in a few years, glad to see he's working on some new projects

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