A Flash Developer Resource Site

Page 2 of 5 FirstFirst 12345 LastLast
Results 21 to 40 of 93

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

  1. #21
    FK founder & general loiterer Flashkit's Avatar
    Join Date
    Feb 2000
    Location
    Sydney
    Posts
    1,149
    Hey render,
    Im trying to make some 3d objects to sit in my rally game (very much like your demo top down car game you had on show and tell many eons ago)

    As such I just need a fast lite library. Im going to rip into yours most likely and have a crack, but I wanted to know if / where it supports perspective.

    Basically Im hoping to get the same effect you had with trees and overpasses in your GTA style engine for my lilracerz engine without having to resort to a heavy engine like away or papervision).

    Any pointers would be great mate....

    Many thanks

    Mark
    Regards Mark Fennell - Flash Kit Founder, general loiterer
    -------------------------------
    I Hate Zombies - iPhone Game | markfennell.com

  2. #22
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    just to make sure that we are talking about the same,- do you mean this ?:
    http://renderhjs.net/renderhjs/rende...t/race_engine/

    just recently I referred to that example again:
    http://board.flashkit.com/board/show...56&postcount=2

    I couldn't find the source code anymore (though it might be on a older backup cd-rom) - but from what I can remember it was a simple parallax effect meaning that you multiply the z-value to some extend to the x/y cooridantes of each vertex point.
    I prepared a illustration that explains what I got in mind back then

    just to make sure:
    in the image the point A becomes B, that means that in the illustration A is not yet transformed to perspective and B is the result.

    as for the z- depth sorting its the same as in the code of the first post- that you can sort soley on the centroids z- coordinate. Give it a spin and if you still are stuck contact me here again.


    I will send you a PM with a project somewhat close related to this that I am working on- something I can't yet unveil here

  3. #23
    FK founder & general loiterer Flashkit's Avatar
    Join Date
    Feb 2000
    Location
    Sydney
    Posts
    1,149
    that was the engine yes, and thats for the explanation, Ill see what I can knock together. Cheers
    Regards Mark Fennell - Flash Kit Founder, general loiterer
    -------------------------------
    I Hate Zombies - iPhone Game | markfennell.com

  4. #24
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    found a nice example with the same effect:

    (cursor keys = navigation)
    http://www.mattmaxwelldesign.com/mm3dengine/sample3.swf
    and
    http://www.mattmaxwelldesign.com/mm3dengine/sample4.swf

  5. #25
    Senior Member rachil0's Avatar
    Join Date
    Jul 2007
    Location
    Columbus, OH.
    Posts
    465
    Those are pretty cool demos (especially sample4). I think you could make a simple and solid engine from that. If you limit yourself to straight z-extrusions for the buildings, you only need to solve visibility/occlusion problems in 2D - easy to do with a bsp like doom did. The earth and building tops can be texture mapped affinely without perspective corrections, so you could make it decently detailed but still fast using just flash 9 functionality. (in F10 go ahead and texture the walls too).

  6. #26
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    and its also easy to code- no complex camera models, face clipping and alike. Just 2d scrolling and clipping.

  7. #27
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    Hey render, is this the same engine you mentioned in my own 3d engine post recently?

    You're starting to scare me with the capabilities in your engine so far...except that I assume it's still in isometric view, and not perspective? I guess that could explain the uselessness of triangles now!
    If this engine does indeed have perspective, then I am amazed at the texture mapping abilities!

    I'm really trying to get Flash CS4, and in turn will start making my 3d engine.

    Also, I share the same hate of all the other 3d engines out there, since, as soon as you ask a question about under the hood details, they simply ignore it, or become cocky as hell!
    It seems that the engines (mainly away3d) are more interested in making gazillion effects available to the user, instead of the actual realistic effectiveness of them in a game, or any real-time animation.

    It would be great to work with you if you're interested later on!
    (I've got a bunch of optimization ideas that could be really effective!)


    P.
    WIP-ZOMBIES

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

  8. #28
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    You're starting to scare me with the capabilities in your engine so far...except that I assume it's still in isometric view, and not perspective? I guess that could explain the uselessness of triangles now!
    the example from the first page is really primitive and not fast or optimized. I ditched perspective for the demo because it requires a little xtra math even more with a camera model- and I wanted to keep it simple.
    But the last suggestion from Flashkit might be a try - will give it a shot as soon as I have sa little spare time.

    on my daily internet research I found this:

    I think there is some potential regarding this central perspective apprach

    @ Pazil:
    post your ideas here,- it would be nice to have a thread with different 3d/ engine ideas/ approaches everyone can share.
    For exampe atm. I am breaking my brains about how to optimize using edge- pairs of vertexes or face pairs of vertexes to reduce the calculation or vertex points. Because atm. I am usually calculating some points several times depending on the faces.

    I also found this neardy artcile that describes how to create a 3d engine in excel
    http://www.gamasutra.com/view/featur...ionary_3d_.php

    lastly I found this nice picture illustrating very nice how horizontal raycasting or mode7 works:
    Last edited by renderhjs; 11-10-2008 at 05:55 PM.

  9. #29
    FK founder & general loiterer Flashkit's Avatar
    Join Date
    Feb 2000
    Location
    Sydney
    Posts
    1,149
    well I cant wait to see your result render as Im dying to use it myself
    Regards Mark Fennell - Flash Kit Founder, general loiterer
    -------------------------------
    I Hate Zombies - iPhone Game | markfennell.com

  10. #30
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    A little extra math for perspective?! For perspective, you need to change up the whole texture process, and start UV mapping (per pixel?...not sure)! Though, with Flash CS4, you get a whole bunch of built-in 3d functions, including uv mapping!

    Just a little thing that really annoys me is that perfect z-sorting can be solved by using bsp trees / portal rendering. False! Those are simply for optimizations, and doom did not use bsp trees (atleast not for that reason, it used them, as I said, simply for an optimization).

    About my ideas...I'm really sorry, and I know this is supposed to be an everyone helps sort of thread, but I want to keep my ideas under the covers until I can publicize a substantial engine. Please don't judge me, and think that I'm going where all the other engines have gone, but I plan to provide extensive background theory, bits and slices of code to go with examples. It's just that I don't want the current 3d engines stealing ideas.

    But, that said, I would gladly discuss some techniques I have in mind with you privately! As for everyone else, I will try to help with all the things I can, and I'll just tell you right now, that my ideas are nothing too special...just most people don't think too much about optimization (atleast not that in-depth)...


    For the central perspective approach, I think that it could be a really good optimization for certain games!

    I don't have time right now to get in depth with the things I wanted to discuss, but I will start posting some actual meat to my posts soon!


    P.
    WIP-ZOMBIES

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

  11. #31
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    For perspective, you need to change up the whole texture process, and start UV mapping (per pixel?...not sure)! Though, with Flash CS4, you get a whole bunch of built-in 3d functions, including uv mapping!
    no,- nothing like that, this demo:
    http://www.renderhjs.net/bbs/flashki...une/demo_r112/
    has perspective and it was done the same as my first post here in this thread.

    no need for rasterization, you can save resources by using the flash players transform matrix like I did in the example- so far its the fastest approach so for flash if you want to diplay 3d meshes/objects from 3d packages.
    here is a nice example that explains it very well how it works:
    http://www.sebleedelisle.com/?page_id=7
    you skew the faces, the more triangles you use the better the result in perspective.
    another nice link
    http://www.senocular.com/flash/tutor...exturemapping/


    kinda have the same atm. been working on a really nice engine but I cant yet post about it. But I already have some progress that extends my expierence on a new scale and improved it in several ways. Just this: its bigger, better and faster

  12. #32
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    Ah! So it's affine texture mapping? I now can see how that can work easily! Hell, I knew about it, but I didn't know it could work so well! This is making me immediately interested in my as2 engine again!

    I'll try to produce some classes very soon, and I'll upload them for everyone to download and stuff...

    I will try to get these texture mapping techniques in my engines, so I might finally be able to put out my first 3d game / anything else!


    P.
    WIP-ZOMBIES

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

  13. #33
    Senior Member rachil0's Avatar
    Join Date
    Jul 2007
    Location
    Columbus, OH.
    Posts
    465
    That screenshot is pretty cool Could be a good combination between a starfox-style rail zoomer and a 2D bullet hell shooter.

  14. #34
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    Hey

    Well...I must congratulate you , Render, for figuring out that getUVMatrix function! Before even looking at your code, I decided to give it a shot myself (I'm not a big fan of copying other people's work, which is also a reason I'm developing my own engine instead of using the premade ones...), and gave up after a while, but when I looked at your code, I had gotten fairly close, but I have no idea how you knew to do that invert function and such...
    Anyways, I'm no good with matrices, but I ended up copying your function...if that's ok?

    I'm trying to write the classes up, but I was wondering if you have any ideas for my problem:
    Basically, I want to start using material classes for the rendering process, so that it's easier to make new ways to render objects and such...my idea so far is to have the actual lineTo and filling function passed over to each material, so for example, if you were using a ColourMaterial, then it would take over the rendering function, and use beginFill(), whereas an AffineBitmapMaterial would use beginBitmapFill()...

    I'm going to try that, but it seems...not the right way to properly do it fast...?

    Anyways...Now that I think about it, I hope you're okay with me developing my own classes? I know this thing was more or less your idea, and if you have any special requests that I do/ not do, please tell me. I personally hate it when people take my ideas and put them up as their own...I hope I'm not doing the same?

    P.
    WIP-ZOMBIES

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

  15. #35
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    he he dont know all the math stuff myself,- at some point esspecially with the UV stuff I just did try and error- prepared examples from 3dsmax I could imagine and fixed it till it worked.
    I did however noticed that my UV function does not work great yet with rectangular texture maps- meaning that your texture has not equal width and height it flips the side somehow. I was about fixing that but so far there was no need, as each texture map I create always has equal width and height so I did not further investigate it.

    about materials:
    not my turf so far,- I am more into lowPoly style like seen on Nintendo DS, mobile and anime games- with full self illumination. Phong shading, smoothing groups ect. is not what got me interested so far.
    in any case you need a surface vector to calculate the highlights and shading, a interesting topic might be Phong shading:
    http://en.wikipedia.org/wiki/Phong_shading
    http://freespace.virgin.net/hugo.eli...s/x_polyp2.htm
    I assume that if you want to do it in AS3 you need somehow to solve it using gradients and or bitmapData manipulation,- but thats another topic.

    You seem to be fixed more on class- models and code structure- all I care usually is about readablilty and simplicity. I dont want to comment thus on that - just: the more you split stuff into seperate classes the more complex and alike like papervision.

    you can do whatever you want- the code I provided does not belong under any license - if you improve it I and others would be of course glad to have some additional or better usefull code snippets but its not a must.

    Atm. I am experimenting on some shading and specular effects on rounded surfaces- might post here about it if I have some progress to show.

  16. #36
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    I'm currently coding in as2
    I should get my hands on Flash CS4 very soon though, and I'm hoping to get tons of speed enhancements from using as3.0...

    I was just wondering about the UV matrix...I know that that only works for isometric view, but the engine I'm developing is a perspective one (I'm probably going to make it both), but I was just wondering if you're doing texture mapping for perspective? It probably doesn't matter too much for small faces / simply texture, but for large, detailed textures, it should have perspective texture mapping, and I was just wondering if you have found a fast way of doing that in as2.0?

    I'm not really the biggest fan of anime...I have my opinions about it...hehe...But anywho, about the materials. I wasn't really trying to get illumination yet, I was more concentrated on making it very easy to swap between texture maps and simple coloured surfaces...I think the way I'm going to do it now is attach a material to a plane, and then the renderer calls the planes render function, which will in turn use the Materials properties etc. to render itself!

    I really am fixed on classes, exactly because I prefer readability, and simplicity in complex things. I'd rather have about 20 lines of code to render a simple thing than 200+...if you know what I mean? While I'm writing the classes so far, I'm writing a descriptive paragraph at the top of each class, and describing the steps by comments so far, and also, most of the classes are simply a) for use by another class, or b) provides a base class for other classes to jump off of (I have a basic Material class, which is extended by any other specific materials. Same with the Plane class, it's never used directly, but extended by the Triangle class, and later, several other poly classes...)

    How do you plan to render rounded surfaces? That seems very interesting! I have some tests I plan to make soon...hopefully they'll have results!

    P.

    By the way...as you may have noticed, it looks as if I'm part of RevoGen Studio's, but actually....so far it's nothing...just me, and if you want to, I'm looking for other developers to join. It's nothing official, just more of a name to publish under, and also it's hard to find too many people that like to develop 3d, know a lot about it, and are not part of any of those major engine dev teams...which is why I'm trying to get you and a couple others together, so we can start making our own engine.
    I realize this is probably how the other big engines got started, and then they started getting protective about how they do things, but I was thinking that if we got people like you and me, we may be able to get a lot more people into developing 3d for Flash.
    Looking at your portfolio, I know you seem more interested on just solo projects...
    Anyways, just think about it I guess...
    WIP-ZOMBIES

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

  17. #37
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    again: most of all 3d flash engines have affine texture mapping,- its what flash has to offer right now. Subdivide alot and you wont see much of it anymore.
    Anything else is to processing intense even in AS3, and if you are stuck with AS2 its even more impossible to see results in acceptable framerates. In regards to that better switch to AS3 anyway- its like 10x+ faster to what you are doing right now and gives good 3d actually a chance.

    WIth FP 10 however you have perspective corrected texture mapping build in- if you really really need it (though most engines with FP 9 dont need it) in that case get your hands on AS3 FP10.

    My future is yet unwritten as I am still a student,- I will see my opportunities soon enough. I am working on a big scale project with other AS3 teams atm. developing a 3d engine, editor pipeline, world editor and visual designs for the project.
    If I find capeable people that I like then of course I like to work with them,- but nothing like just a 2 people team or so- that wouldn't make much difference.
    Last edited by renderhjs; 11-14-2008 at 12:40 AM.

  18. #38
    talk to the hand! Never_land:('s Avatar
    Join Date
    Nov 2007
    Location
    your mother's bedroom
    Posts
    490
    Man you are really giving this all for free,I wouldn't be able to do that. Impressive engine, thanks.
    I already saved it, I'll read it later, If my "artbased engine creator mind" can handle it.
    so far I haven't tested it, but it is probably better than alternativa wich isn't free at all.
    waiting to see some shading, bump,reflection, collision and lighting in your engine, and flash players that support gaming Nvidia cards.

  19. #39
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    its alot alot alot slower than alternativa because it has no optimizations at all- its just a possible beginning.
    Modify it, extend it, change things and then you might have a good engine but right now its merely a concept.

  20. #40
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    so I took another attempt, trying to reuse the first code and:
    - change to as3
    - reduce
    - optimize
    - change orthographic to central point perspective
    and because its now AS3 it runs sooo much faster

    here is a online swf @ 42 fps demo:
    http://www.renderhjs.net/bbs/flashki..._version_2.swf

    screenshot


    cs3 fla:
    http://www.renderhjs.net/bbs/flashki..._version_2.fla


    here is another image illustrating again how the central perspective works:



    sourceCode (timeline code, import classes and restructure it a bit and it will even fit in a single class)
    PHP Code:
    //actionscript harrier mesh export 
    var vtx:Array = new Array();//the vertex positions {x,y,z}'s 
    vtx = [{x:52,y:16,z:-4},{x:0,y:-19,z:-2},{x:35,y:32,z:-2},{x:35,y:-20,z:-2},{x:110,y:-25,z:-10},{x:105,y:-4,z:-10},{x:23,y:27,z:-7},{x:23,y:55,z:-12},{x:32,y:18,z:-26},{x:32,y:55,z:-26},{x:20,y:60,z:-26},{x:4,y:126,z:-15},{x:6,y:136,z:-26},{x:89,y:22,z:-15},{x:89,y:-34,z:-15},{x:98,y:-32,z:-26},{x:98,y:12,z:-26},{x:79,y:12,z:-26},{x:79,y:-32,z:-26},{x:0,y:-47,z:-7},{x:15,y:-49,z:-13},{x:22,y:-53,z:-26},{x:6,y:-136,z:-18},{x:0,y:-85,z:-10},{x:2,y:-113,z:-10},{x:63,y:-125,z:-25},{x:61,y:-112,z:-25},{x:9,y:90,z:-15},{x:15,y:106,z:-26},{x:0,y:34,z:-4},{x:12,y:60,z:-4},{x:8,y:74,z:-1},{x:18,y:-9,z:-14},{x:27,y:-10,z:-30},{x:0,y:60,z:4},{x:0,y:140,z:-26},{x:-35,y:-20,z:-2},{x:-35,y:32,z:-2},{x:0,y:38,z:-2},{x:-52,y:16,z:-4},{x:-110,y:-25,z:-10},{x:-105,y:-4,z:-10},{x:-23,y:55,z:-12},{x:-23,y:27,z:-7},{x:-32,y:18,z:-26},{x:-32,y:55,z:-26},{x:-20,y:60,z:-26},{x:-12,y:60,z:-4},{x:-15,y:106,z:-26},{x:-9,y:90,z:-15},{x:-4,y:126,z:-15},{x:-6,y:136,z:-26},{x:0,y:128,z:-15},{x:-89,y:22,z:-15},{x:-89,y:-34,z:-15},{x:-98,y:-32,z:-26},{x:-98,y:12,z:-26},{x:-79,y:12,z:-26},{x:-79,y:-32,z:-26},{x:-15,y:-49,z:-13},{x:0,y:-140,z:-15},{x:-6,y:-136,z:-18},{x:-2,y:-113,z:-10},{x:-63,y:-125,z:-25},{x:-61,y:-112,z:-25},{x:-22,y:-53,z:-26},{x:0,y:99,z:-12},{x:-8,y:74,z:-1},{x:0,y:87,z:0},{x:0,y:-9,z:-7},{x:-18,y:-9,z:-14},{x:-27,y:-10,z:-30},{x:0,y:-123,z:30},{x:0,y:-131,z:30},{x:9,y:90,z:-15},{x:0,y:99,z:-12},{x:0,y:34,z:-4},{x:12,y:60,z:-4},{x:-9,y:90,z:-15},{x:-12,y:60,z:-4}];
    var 
    fcs:Array = new Array();//the triangle faces and their vertex id's 
    fcs = [[3,2,38],[38,1,3],[0,3,4],[4,5,0],[7,6,8],[8,9,7],[7,9,10],[10,30,7],[10,28,27],[27,30,10],[12,35,52],[52,11,12],[13,14,15],[15,16,13],[14,13,17],[17,18,14],[20,19,60],[60,22,20],[23,24,25],[25,26,23],[11,52,66],[66,27,11],[28,12,11],[11,27,28],[27,66,68],[68,31,27],[30,29,6],[6,7,30],[69,19,20],[20,32,69],[20,21,33],[33,32,20],[24,23,72],[72,73,24],[30,31,34],[34,29,30],[36,1,38],[38,37,36],[39,41,40],[40,36,39],[42,45,44],[44,43,42],[42,47,46],[46,45,42],[46,47,49],[49,48,46],[51,50,52],[52,35,51],[53,56,55],[55,54,53],[54,58,57],[57,53,54],[59,61,60],[60,19,59],[23,64,63],[63,62,23],[50,49,66],[66,52,50],[48,49,50],[50,51,48],[49,67,68],[68,66,49],[47,42,43],[43,29,47],[69,70,59],[59,19,69],[59,70,71],[71,65,59],[62,73,72],[72,23,62],[47,29,34],[34,67,47],[3,0,2],[21,20,22],[30,27,31],[34,31,68],[36,37,39],[65,61,59],[47,67,49],[34,68,67],[78,79,77],[77,74,78],[77,79,76],[78,74,75]];
    var 
    tVtx:Array = new Array();//the texture vertex positions {x,y}'s 
    tVtx = [{x:0.543232,y:0.971973},{x:0.928999,y:0.971975},{x:0.938606,y:0.730914},{x:0.58145,y:0.730301},{x:0.973394,y:0.232302},{x:0.830266,y:0.262219},{x:0.689343,y:0.618487},{x:0.03224,y:0.0179053},{x:0.0427658,y:0.265735},{x:0.155986,y:0.25897},{x:0.1771,y:0.07012},{x:0.0937724,y:0.344807},{x:0.240765,y:0.297882},{x:0.250644,y:0.516723},{x:0.191134,y:0.643475},{x:0.337008,y:0.762054},{x:0.31295,y:0.747924},{x:0.273677,y:0.838889},{x:0.337009,y:0.868649},{x:0.969354,y:0.199225},{x:0.688933,y:0.199213},{x:0.627362,y:0.110146},{x:0.984541,y:0.110145},{x:0.688933,y:0.0228288},{x:0.969354,y:0.0228159},{x:0.367614,y:0.890776},{x:0.416228,y:0.871678},{x:0.479322,y:0.284941},{x:0.367631,y:0.270632},{x:0.0676327,y:0.54325},{x:0.0224356,y:0.607067},{x:0.112433,y:0.982561},{x:0.213288,y:0.856084},{x:0.337007,y:0.566789},{x:0.337006,y:0.461164},{x:0.279638,y:0.386058},{x:0.337006,y:0.120418},{x:0.501807,y:0.0170947},{x:0.36763,y:0.0138662},{x:0.621655,y:0.0363869},{x:0.573364,y:0.323514},{x:0.44281,y:0.983876},{x:0.466339,y:0.938112},{x:0.337006,y:0.29354},{x:0.543232,y:0.971973},{x:0.58145,y:0.730301},{x:0.938606,y:0.730914},{x:0.928999,y:0.971975},{x:0.973394,y:0.232302},{x:0.689343,y:0.618487},{x:0.830266,y:0.262219},{x:0.03224,y:0.0179053},{x:0.1771,y:0.07012},{x:0.155988,y:0.25897},{x:0.0427658,y:0.265735},{x:0.0937724,y:0.344807},{x:0.240767,y:0.297882},{x:0.250644,y:0.516723},{x:0.191134,y:0.643475},{x:0.337008,y:0.762054},{x:0.337009,y:0.868649},{x:0.273677,y:0.838889},{x:0.312947,y:0.747926},{x:0.969354,y:0.199225},{x:0.984541,y:0.110145},{x:0.627362,y:0.110146},{x:0.688933,y:0.199213},{x:0.688933,y:0.0228288},{x:0.969354,y:0.0228159},{x:0.367614,y:0.890776},{x:0.367631,y:0.270632},{x:0.479331,y:0.284942},{x:0.416228,y:0.871678},{x:0.0676327,y:0.54325},{x:0.213288,y:0.856084},{x:0.112433,y:0.982561},{x:0.0224356,y:0.607067},{x:0.337007,y:0.566789},{x:0.337006,y:0.461164},{x:0.279638,y:0.386058},{x:0.337006,y:0.120418},{x:0.36763,y:0.0138662},{x:0.501807,y:0.0170947},{x:0.621655,y:0.0363869},{x:0.573364,y:0.323514},{x:0.44281,y:0.983876},{x:0.466339,y:0.938112},{x:0.337006,y:0.29354},{x:0.609371,y:0.525416},{x:0.657645,y:0.571343},{x:0.65328,y:0.234636},{x:0.589112,y:0.371206},{x:0.704713,y:0.52418},{x:0.720967,y:0.369496}];
    var 
    tFcs:Array = new Array();//the texture faces and their texture vertex id's 
    tFcs = [[2,3,0],[0,1,2],[6,2,4],[4,5,6],[9,10,7],[7,8,9],[9,8,11],[11,12,9],[11,14,13],[13,12,11],[17,18,15],[15,16,17],[21,22,19],[19,20,21],[22,21,23],[23,24,22],[27,28,25],[25,26,27],[31,32,29],[29,30,31],[16,15,33],[33,13,16],[14,17,16],[16,13,14],[13,33,34],[34,35,13],[12,36,10],[10,9,12],[38,28,27],[27,37,38],[27,40,39],[39,37,27],[32,31,41],[41,42,32],[12,35,43],[43,36,12],[46,47,44],[44,45,46],[49,50,48],[48,46,49],[53,54,51],[51,52,53],[53,56,55],[55,54,53],[55,56,57],[57,58,55],[61,62,59],[59,60,61],[65,66,63],[63,64,65],[64,68,67],[67,65,64],[71,72,69],[69,70,71],[75,76,73],[73,74,75],[62,57,77],[77,59,62],[58,57,62],[62,61,58],[57,79,78],[78,77,57],[56,53,52],[52,80,56],[81,82,71],[71,70,81],[71,82,83],[83,84,71],[74,86,85],[85,75,74],[56,80,87],[87,79,56],[2,6,3],[40,27,26],[12,13,35],[43,35,34],[46,45,49],[84,72,71],[56,79,57],[87,78,79],[92,93,91],[91,88,92],[91,93,90],[92,88,89]];

    //Flashkit 3d engine kit part 2
    stage.quality="LOW";

    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};//the camera

    stage.addEventListener(Event.ENTER_FRAMErender);//onEnterFrame event


    function get2d(x:int,y:int,z:int) {//3d coordinates to 2d screen coordinates conversion 
        
    var d:int 200;
        var 
    dx,dy:int;
        
    dx cam.x;
        
    dy = -cam.y;
        
    x-=(dx*z/d)+cam.x;
        
    y-=(dy*z/d)-cam.y;
        return {
    x:x,y:- y,dis:z};
    }

    var 
    spr:Graphics mainSprite.graphics;
    function 
    render(e:Event):void {
        
    cam.= (stage.mouseXstage.stageWidth/2);
        
    cam.= (stage.mouseY stage.stageHeight/2);
        
        var 
    i,j:int 0;
        var 
    pt,vt:Object;

        var 
    fcs_render:Array = [];//order of the faces to be rendered 
        
    for (i=0i<fcs.lengthi++) {
            var 
    tri:Array = [];
            var 
    avg_x,avg_y,avg_z:int 0;//average centroids
            
    for (j=0j<3j++) {
                
    vt vtxfcs[i][j%3] ];
                
    tri.push(get2d(vt.xvt.yvt.z));
                
    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 zDepth:Number get2d(avg_xavg_yavg_z).dis;
                var 
    UVtris:Array = [];
                
    UVtris[0] = tVtxtFcs[i][0] ];
                
    UVtris[1] = tVtxtFcs[i][1] ];
                
    UVtris[2] = tVtxtFcs[i][2] ];
                
    fcs_render.push({tri:triuv:UVtrisd:zDepth});
            }
        }
        
    fcs_render.sortOn("d", Array.NUMERIC);//sort faces
        
    spr.clear();
        for (
    i=0i<fcs_render.lengthi++) {
            var 
    mtx:Matrix getUVmatrixfcs_render[i].uv fcs_render[i].tri ,bitmap);
            
    spr.beginBitmapFill(bitmap,mtx,true);

            
    pt fcs_render[i].tri[0];
            
    spr.moveTo(pt.x,pt.y);
            
    pt fcs_render[i].tri[1];
            
    spr.lineTo(pt.x,pt.y);
            
    pt fcs_render[i].tri[2];
            
    spr.lineTo(pt.x,pt.y);
            
    spr.endFill();
        }
    }
    function 
    getUVmatrix(uv:Array, pt:Array, tex:BitmapData):Matrix {
        var 
    a:Matrix = new Matrix();// 
        
    var b:Matrix = new 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;

    a little comment, though almost obvous:
    PHP Code:
    var bitmap:BitmapData = new Texture(0,0);//BitmapData texture from the library 
    is the texture in this demo,- its a image from the library that has a linkage defined with the class name "Texture",- for odd reasons AS3 requires you to pass 2 parameters to such a class for whatever reason, change this for your texture.


    I noticed that the export- script for 3dsmax has perhaps a little flaw as it does not invert the -y coordinate. Flash has a different axis direction for Y as all 3d packages - one could flip this y- coordinate each time so that it better fits thinking model from flash (top down instead down top)

    from the maxscript where it reads out the vertex coordinates:
    PHP Code:
    ...output+="\nvtx = [";
    for 
    1 to mesh.numverts do
    (
        
    getVert mesh v;
        
    = (p.as Integer) as String;
        
    = (p.as Integer) as String;
        
    = (p.as Integer) as String;
        
    output+="{x:"+x+",y:"+y+",z:"+z+"}";
        if (
    != mesh.numverts)then
            output
    +=",";
        else(
            
    output+="];";
        )
    )
    output+="... 
    simply change the y- line to:
    PHP Code:
    = (p.as Integer * -1) as String
    because of this difference I had to change a few things in the camera model (invert at some spots the y- coordinate) - it would be propably easier to understand it if the vertex coordinates where flash inverted to begin with


    some comments on the get2d function
    ..the one simulating the camera model and converting 3d- coordinates to 2d screen coordinates
    PHP Code:
    function get2d(x:int,y:int,z:int) {//3d coordinates to 2d screen coordinates conversion 
        
    var d:int 200;
        var 
    dx,dy:int;
        
    dx cam.x;
        
    dy = -cam.y;
        
    x-=(dx*z/d)+cam.x;
        
    y-=(dy*z/d)-cam.y;
        return {
    x:x,y:- y,dis:z};

    d is the distance of the camera from the surface 0 (Zero), good values are usually (in most engines btw.) 400 or 500) its often also referred to as DOF (depth of field)- if you make it smaler you get a fish- eye effect, if you increase this number say 1600 or greater you get almost a orthographic projection this then gets close to looking through a telescope.

    dx and dy are the delta X and delta Y values of the coordinate distance from the camera. The more the camera gets away the more you could say the object leaves the camera and the more it gets distorted in the view.

    when calculating the final screen x and y- coordinates you need to add a inverse camera offset so that basicly the object moves in counter direction of the camera.
    I noticed that some users here at FK often referred to this as a camera object- its basicly that.

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