dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [AS3][3d] custom binary 3d format for AS3

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

    [AS3][3d] custom binary 3d format for AS3

    in short
    Binary file format between 3dsmax and Flash AS3 to eleminate parsing times and dramaticly decrease loading times

    Demo (for the ones who lazy bones)

    (left buttons to load 3d files [yes they are not compiled arrays but external files]- the UV map is displayed in the upper right corner)
    online demo


    so I was playing again with maxscript and discovered how to write binary files directly out of 3dsmax to my harddrive.

    (3dsmax mascript interface I wrote to write the binary files)
    And of course the next logical step for me was to read the binary files with AS3- and I got it working.
    Since then I started writing a simplified 3d format wich I can load into AS3 really fast. The format is intended to be smal and simple stuctured (easy to read in AS3- not much re- sorting in new arrays) and should hold the following:
    - vertex positions
    - face(triangle) vertex idŽs
    - uv-map vertex positions (x,y)
    - uv-map face uv-vertex idŽs
    - texture map URL string (e.g enemyX.png)
    and yes it should only hold 1 object, the engine later should then load multiple 3d object files to compose them into 1 scene. And just in case you havenŽt noticed before Binary files are very smal.

    For a comparison regarding the filesize I saved the 3dsmax default teapod with 4 Segments

    (the one in the demo at the top of this post has only 3) in various formats:

    Code:
    *.3d		my format, just hit the "write file"
    18.2 KB
    
    *.obj 	alias wavefront Object file: triangles + uv coordinates 6 digits (default)
    66.7 KB
    
    *.3ds 	3d studio export format: preserve UV checked
    31.5 KB
    
    *.ASE 	ASCI scene export: mesh defenition, 4 decimals. Used in the past (perhaps still now) for UT engines
    396 KB
    
    *.DXF 	Autocad exchange format (not sure if that thingy even supports UV data)
    368 KB
    so why is my file so smal?
    Most of the other formats save additional data like filename, material,... I tried to exclude as much as possible but I think alot is still stored as additional data. Also some of the file formats are stored as ASCI data wich means that a single Number is stored as a string wich results as a biger file and just like XML they are intended to be easily readable for the human eye so they contain alot of structural elements like returns, operator signs, ect.


    As for my file I have to admit that I cheated a little bit:

    - no floating values for the vertex coordinates (so no digits) instead only Short values (2^16 = range of 65536 or inAS3 = -32768 to 32767, a floating value goes beyond that). But for the engine I am aiming for this is perfect as I dont need tiny details to be zoomed into with big scales.

    - the UV coordinates (x,y) are within a limited range wich can be defined in a variable like 512- so all floating values are interpreted into mapsize ranges. I did this because 99% of the UV vertex coordinates are values above 0 and below 1 so you get a lot of values such as 0.3546111231 wich would become then for example 182 (out of 512), that way I dont have to store them as floating values.

    the advantages?
    - smal loading times
    - no parsing of string or xml objects,- just load the ByteArray in AS3 and directly access the values
    - flexible workflow with maxscript,- no need for standard procedures like file>export>filetype>options>hit Save, instead create a custom interface for additional options or reduced ones, select object and hit "write".

    disadvantages
    - not readable in text editors (such as notepad)
    - AS3 required
    - needs a tool that writes the binary (e.g 3dsmax with maxscript, php, compiled EXE tool,..)


    in near future I plan to write another thread about the how to do behind this,- I already made a table for myself with the byte write and reading functions in comparison with maxscript and AS3- and their range, limits,ect. It might be usefull for anyone else who wants to start with something similar to this.
    When I started again learning AS3 (3rd time) I did not find any resources on reading (not writing in a variable) ByteArray data except some source code of the sandy project- and only because google suggested me it. Even the Adobe CS3 help says "advanced stuff" and doesnŽt come with much explaination and examples, neither does colin moockŽs essential AS 3.0. So more stuff about byteArray wouldnŽt hurt

  2. #2
    When you know are. Son of Bryce's Avatar
    Join Date
    Aug 2002
    Location
    Los Angeles
    Posts
    839
    Is it possible to use these 3d objects with the open-source 3d engines out there? Such as Papervision and the like.

  3. #3
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    if you rewrite some of their loading classes,- but for now this is rather a personal development.
    IŽll have to see within the updacomming months if the requirements I defined work out in the very end: meaning that IŽll have to see if the advantages of not using floating values will pay of in the end.
    But if I put the structure online anyone with enough knowledge can code writer and reader classes for any engine and perhaps also other 3d packages.

    IŽll still have to write a loader in maxscript to generate the meshes back out of the binary files- and to be able to change little things in them.

  4. #4
    Senior Member
    Join Date
    Nov 2003
    Location
    Las Vegas
    Posts
    770
    Nice work!

    With the multiple viewports available using the Great White branch of PV3D, I could see this developed into a basic 3d modeling app in Flash. Utilizing your read/write capabilities, models could be created and exported from a swf file and imported into 3dsmax etc.

  5. #5
    Flash "Devigner"
    Join Date
    Oct 2008
    Location
    ottawa
    Posts
    2
    renderhjs, I know you've heard it many times but your work is breathtaking

    I am very impressed how you were able to get file sizes even smaller with your custom .3d binary file format. Myself, I just was able to port the papervision 3dsparser to load the mesh with a simple 3d engine created (not by myself) named nd3d (which is smaller overhead size than Papervision)...I am trying to go small because my project is a 3d hourglass preloader and I cannot have the user wait for the preloader! (a preloader for a preloader...imagine that

    may I kindly ask if there are any tutorials or source available for your .3d format? every kb I can shave would help even though .3ds is small too. I would then try to port it to get it to go...the parsing wouldn't be too much different than .3ds would it cause they are both binary...

    looking forward

  6. #6
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    hey Wurlock
    have a look at my recent tutorial getting into a own 3d engine:
    http://board.flashkit.com/board/show...73#post4103573

    I provided there already a maxscript that generates you 4 Actionscript arrays for the vertex, face, textureVertexes and texture Face informations.

    It might (not sure though) be a tiny bit bigger because all values propably will get stored as floating (Number) values instead of short/ integer values - but on the other hand your would otherwise need the binary file parsing function which would case xtra bytes on the flash movie again.

    The maxscript is:
    PHP Code:
    --flashkit mesh exporter
    --2008 renderhjs.net


    function export_object obj=(
        try(
            
            --or 
    classof obj == Editable_mesh
            
    if (  superclassof obj == GeometryClass then(
            
                
                
    local mesh         =     snapshotasmesh obj;--create a snapshot mesh
                
    --local num_verts =    mesh.numverts; --get the number of vertices
                local num_faces 
    mesh.numfaces;
                
    local num_tverts mesh.numTVerts;
                
    local output "";
                
                
    output+="//actionscript mesh export";
                
    output+="\nvar vtx:Array = new Array();//the vertex positions {x,y,z}'s";
                
    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+="\n\nvar fcs:Array = new Array();//the triangle faces and their vertex id's";
                
    output+="\nfcs = [";
                for 
    1 to mesh.numfaces do
                (
                    
    getFace mesh f;
                    
    = (p.as Integer -1) as String;
                    
    = (p.as Integer -1) as String;
                    
    = (p.as Integer -1) as String;
                    
                    
    output+="["+x+","+y+","+z+"]";
                    if (
    != mesh.numfaces)then
                        output
    +=",";
                    else(
                        
    output+="];";
                    )
                )
                --
                
    output+="\n\nvar tVtx:Array = new Array();//the texture vertex positions {x,y}'s";
                
    output+="\ntVtx = [";

                for 
    1 to mesh.numTVerts do
                (
                    
    GetTVert mesh v;
                    
    = (p.x) as String;
                    
    = (-p.y+1) as String;

                    
    output+="{x:"+x+",y:"+y+"}";
                    if (
    != mesh.numTVerts)then
                        output
    +=",";
                    else(
                        
    output+="];";
                    )
                )
                
                --
                
    output+="\n\nvar tFcs:Array = new Array();//the texture faces and their texture vertex id's";
                
    output+="\ntFcs = [";

                for 
    1 to mesh.numfaces do
                (
                    
    GetTVFace mesh f;
                    
    = (p.as Integer -1) as String;
                    
    = (p.as Integer -1) as String;
                    
    = (p.as Integer -1) as String;
                    
                    
    output+="["+x+","+y+","+z+"]";
                    if (
    != mesh.numfaces)then
                        output
    +=",";
                    else(
                        
    output+="];";
                    )
                )
                --
                --
    rollout_export.txt_output.text output;

                
    delete mesh;
                
                return 
    output;
            )else(
                return 
    "object type not supported,\ntry a poly or mesh";
            )

        )catch();
    )

    rollout rollout_export "export Objects to Actionscript" width:223 height:274
    (
        
    button btn_export "export" pos:[166,4width:51 height:28
        editText txt_output 
    "" pos:[3,35width:214 height:230
        label txt_info 
    "select a mesh or poly object and then hit the button" pos:[10,5width:155 height:28
        
        
        on btn_export pressed 
    do(
            
            
    local output export_object selection[1];--first object of the selection
            txt_output
    .text output;
        )

    )
    --
    initiate the rollout and floater in the interface
    try (-- 
    close existing rolloutFloater
        closeRolloutFloater floater_flashkit

    ) catch ()
    floater_flashkit newRolloutFloater "Flashkit 3d tutorial" 240 310
    addrollout rollout_export floater_flashkit

    a guide for using the maxscripts can be found here:
    http://board.flashkit.com/board/showthread.php?t=757034

  7. #7
    formerly hooligan2001 :) .hooligan's Avatar
    Join Date
    Mar 2008
    Posts
    405
    Wow render you should really turn all this info you have made into a blog. I would love to sit down and try get my head through it all.

  8. #8
    Flash "Devigner"
    Join Date
    Oct 2008
    Location
    ottawa
    Posts
    2
    hi RenderHJS...thanks for the info and I will certainly take a look at that now that I have gotten a preliminary 3ds parser to go with nd3d as I think going smaller with your format is the next progressive step.

    Perhaps you can take a look, I mention your format in my blog article here
    http://www.magicpictures.ca/blog/35-flash.html

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