Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 2 [3]
  ignore  |  Print  
  Announcing: joglutils project  (Read 52087 times)
0 Members and 1 Guest are viewing this topic.
Offline Z-Knight

Senior Member


Medals: 1



« Reply #60 - Posted 2008-05-27 19:21:12 »

rogersgb, I have a small update to the computeNormals() function for 3DS in MaxLoader.java (originally this was in Loader3DS.java). 

Since I've not used the "new" code as of yet I didn't feel comfortable commiting this via subversion so I would appreciate if you could try it out and update it yourself.  The "new" code seems to match the "old" code except that the Vec3 is now Vec4, and "object.verts" is now "object.vertices"

Basically I ran a profiler on the joglutils project (old one) and I noticed that computeNormals() was a huge bottleneck and so I started looking at the code and realized that it has way too much nested looping that is causing the long computation times.  Initially the code loops over the objects and then each face of the object and calculates the normal for each face.  It then loops over the vertices of each object and for each vertex it loops over all of the faces and tries to find the face who has a vertex that matches the current vertex and then it uses the face normal to add to the vertex normal...and then it normalizes the normal.   Well, the looping over each face for every vertex is horrible because the loop never terminates early because it has to loop through all of the faces to find if any has a matching vertex.  Also, it calculates a 'shared' counter that is used to divide the normal summation for each vertex normal but this is pretty much useless because we normalize the vertex normal anyway so dividing it by some value does nothing....it just adds an unnecessary calculation.

I rewrote the code to the following:
   Loop through each object
       - initialize the normal vector in each object

   Loop through each object
       - Loop through each face of the object
            - calculate face normal
            - add face normal to each of the 3 vertex normals of the face

   Loop through each object
       - Loop through each vertex of the object
            - normalize the vertex normal

It may seem like there are three loops and this is worse but in fact this is much much faster and gives the correct results (or at least it seems to).  And when I say it is much faster, on a model of 500,000 vertices the calculation was 30 times faster than before....I don't think the model size matters but I'm just giving you an example. 

Here is the code that I believe works for the "new" code (MaxLoader.java)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
    private void computeNormals(Model model)
    {
        Vec4 vVector1 = new Vec4();
        Vec4 vVector2 = new Vec4();
        Vec4 vPoly[] = new Vec4[3];
        int numObjs = model.getNumberOfMeshes();

        // Initialize the normals vectors for each vertex of each object
       for (int index=0; index<numObjs; index++) {
            Mesh object = model.getMesh(index);

            object.normals = new Vec4[object.numOfVerts];
           
            for (int i=0; i<object.numOfVerts; i++) {
                object.normals[i] = new Vec4(0.0f, 0.0f, 0.0f);
            }
        }
       
        // Calculate the normal for each face and add this normal value to each
       // vertex of the face
       for (int index=0; index<numObjs; index++) {
            Mesh object = model.getMesh(index);

            for (int i=0; i<object.numOfFaces; i++) {
                vPoly[0] = new Vec4(object.vertices[object.faces[i].vertIndex[0]]);
                vPoly[1] = new Vec4(object.vertices[object.faces[i].vertIndex[1]]);
                vPoly[2] = new Vec4(object.vertices[object.faces[i].vertIndex[2]]);
   
                vVector1 = vPoly[1];
                vVector2 = vPoly[2];
                vVector1.x -= vPoly[0].x;
                vVector1.y -= vPoly[0].y;
                vVector1.z -= vPoly[0].z;
                vVector2.x -= vPoly[0].x;
                vVector2.y -= vPoly[0].y;
                vVector2.z -= vPoly[0].z;
               
                Vec4 tempVect = new Vec4( vVector1.y*vVector2.z - vVector1.z*vVector2.y,
                                          vVector1.z*vVector2.x - vVector1.x*vVector2.z,
                                          vVector1.x*vVector2.y - vVector1.y*vVector2.x );        
               
                for (int j=0; j<3; j++) {
                    int vertex = object.faces[i].vertIndex[j];

                    object.normals[vertex].x += tempVect.x;
                    object.normals[vertex].y += tempVect.y;
                    object.normals[vertex].z += tempVect.z;
                }
            }
        }
       
        // Normalize the normal vector of each vertex of every object  
       for (int index=0; index<numObjs; index++) {
            Mesh object = model.getMesh(index);
           
            for (int i=0; i<object.numOfVerts; i++) {
                // Normalize
               float mag = (float)Math.sqrt(object.normals[i].x*object.normals[i].x +
                                             object.normals[i].y*object.normals[i].y +
                                             object.normals[i].z*object.normals[i].z);
               
                // dividing by the negative of the magnitude to get the opposite
               // vector...not exactly sure why this is done to be honest but it works.
               object.normals[i].x /= -mag;
                object.normals[i].y /= -mag;
                object.normals[i].z /= -mag;
            }
        }
    }


Here is the code that works for the "old" code (Loader3DS.java) that I am currently using:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
    private void computeNormals(Model3DS model)
    {
        Vec3 vVector1 = new Vec3();
        Vec3 vVector2 = new Vec3();
        Vec3 vPoly[] = new Vec3[3];
        int numObjs = model.getNumberOfObjects();

        // Initialize the normals vectors for each vertex of each object
       for (int index=0; index<numObjs; index++) {
            Obj object = model.getObject(index);

            object.normals = new Vec3[object.numOfVerts];
           
            for (int i=0; i<object.numOfVerts; i++) {
                object.normals[i] = new Vec3(0.0f, 0.0f, 0.0f);
            }
        }
       
        // Calculate the normal for each face and add this normal value to each
       // vertex of the face
       for (int index=0; index<numObjs; index++) {
            Obj object = model.getObject(index);

            for (int i=0; i<object.numOfFaces; i++) {
                vPoly[0] = new Vec3(object.verts[object.faces[i].vertIndex[0]]);
                vPoly[1] = new Vec3(object.verts[object.faces[i].vertIndex[1]]);
                vPoly[2] = new Vec3(object.verts[object.faces[i].vertIndex[2]]);
   
                vVector1 = vPoly[1];
                vVector2 = vPoly[2];
                vVector1.x -= vPoly[0].x;
                vVector1.y -= vPoly[0].y;
                vVector1.z -= vPoly[0].z;
                vVector2.x -= vPoly[0].x;
                vVector2.y -= vPoly[0].y;
                vVector2.z -= vPoly[0].z;
               
                Vec3 tempVect = new Vec3( vVector1.y*vVector2.z - vVector1.z*vVector2.y,
                                          vVector1.z*vVector2.x - vVector1.x*vVector2.z,
                                          vVector1.x*vVector2.y - vVector1.y*vVector2.x );        
               
                for (int j=0; j<3; j++) {
                    int vertex = object.faces[i].vertIndex[j];

                    object.normals[vertex].x += tempVect.x;
                    object.normals[vertex].y += tempVect.y;
                    object.normals[vertex].z += tempVect.z;
                }
            }
        }
       
        // Normalize the normal vector of each vertex of every object  
       for (int index=0; index<numObjs; index++) {
            Obj object = model.getObject(index);
           
            for (int i=0; i<object.numOfVerts; i++) {
                // Normalize
               float mag = (float)Math.sqrt(object.normals[i].x*object.normals[i].x +
                                             object.normals[i].y*object.normals[i].y +
                                             object.normals[i].z*object.normals[i].z);
               
                // dividing by the negative of the magnitude to get the opposite
               // vector...not exactly sure why this is done to be honest.
               object.normals[i].x /= -mag;
                object.normals[i].y /= -mag;
                object.normals[i].z /= -mag;
            }
        }
    }


Offline rodgersgb

Senior Newbie





« Reply #61 - Posted 2008-05-27 20:10:43 »

Sure, I will try it out.

Thanks.

By the way, I'm working on a small scale scenegraph that supports LOD. This should tremendously help out the model rendering.

-greg
Offline Z-Knight

Senior Member


Medals: 1



« Reply #62 - Posted 2008-05-27 20:25:57 »

Sure, I will try it out.

Thanks.

By the way, I'm working on a small scale scenegraph that supports LOD. This should tremendously help out the model rendering.

-greg

cool...that's actually something I need to implement in my work and I've not even started so I can't wait to use what you come up with.

I'm currently trying to implement VBO rendering as an option though I'm not sure how much it will help me since I'm using GLJPanel() and the GL context is destroyed on resize/init() and so I lose the VBOs that are created.  Right now the direct draw rendering is what I'm using until I come learn how to do context sharing, etc.  Though the VBO rendering might help for the versions of the code that use the GLCanvas() so it might not be a total waste.  I have VBOs drawing the faces thus far, but I need to figure out how to get the normals in there and then the textures.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline rodgersgb

Senior Newbie





« Reply #63 - Posted 2008-05-27 20:40:35 »

cool...that's actually something I need to implement in my work and I've not even started so I can't wait to use what you come up with.

I'm currently trying to implement VBO rendering as an option though I'm not sure how much it will help me since I'm using GLJPanel() and the GL context is destroyed on resize/init() and so I lose the VBOs that are created.  Right now the direct draw rendering is what I'm using until I come learn how to do context sharing, etc.  Though the VBO rendering might help for the versions of the code that use the GLCanvas() so it might not be a total waste.  I have VBOs drawing the faces thus far, but I need to figure out how to get the normals in there and then the textures.

I have the same problem with textures and display lists on a GLJPanel. I store them in hash tables when they are created. If they need re-initialized due to context destruction I just grab them back out of the hash table. That implementation works for a heavyweight canvas as well.
Offline Z-Knight

Senior Member


Medals: 1



« Reply #64 - Posted 2008-05-30 19:08:46 »

I finally was able to get VBOs to work in my version of the JOGLUTILS (old code) and so I'll be sending you an update here in the next few days.

I've basically written out the steps I used for the VBO code in this post http://www.java-gaming.org/topics/vbo-example-with-vertices-normals-textures-colors/18710/view.html.

Currently I have it working for a GLCanvas and I need to add code that recreates the buffers following a re-init() in GLJPanel cases....once I get that figured out I'll post the update here or I might actually try to edit the subversion code itself.

EDIT: I downloaded the latest version of the joglutils loaders and so I'll try to make the changes directly and either I'll send you the modified files, create a patch and attach the files, or try to see if I can commit to subversion.   I'll even add the computeNormals() code that I submitted before and I noticed that the test viewer doesn't have the best lighting setup because it washes out the models so I'll try to make it like the viewer I wrote (just gonna tweak the lighting parameters).
Offline crazyrrrussian

Senior Newbie





« Reply #65 - Posted 2008-06-24 01:55:36 »

Hello.  I made simple Scene Tree system that allows to relate nodes spacially and treat them as a tree.  It's pretty basic but useful for attaching objects to each other.  I also made OBJ format reader, although it is buggy right now, and does not support full OBJ format.  It pretty much can parse the output of light wave's OBJ exporter and create a Node that can be used in the rest of my Scene tree.

here is link to old version of my source code: http://code.google.com/p/cs456-team-badabing/source/browse/trunk/src/edu/ohiou/cs456_badabing/sceneapi/basic/ANode.java

and here are corresponding Javadocs - http://giga2.cs.ohiou.edu/~neiman/spsa/edu/ohiou/cs456_badabing/sceneapi/basic/package-summary.html

All of the scene stuff is located in *.basic package.  everything else is for my old CS class.  I will probably upload new source code soon to a different place.

I am definitely looking to checking out your guy's stuff though, thank you in advance!
Offline crazyrrrussian

Senior Newbie





« Reply #66 - Posted 2008-06-24 03:26:19 »

is there a chance of the source code for this becoming available?

EDIT: nm, i figured it out.  dev.java.net is pretty cool!
Offline Z-Knight

Senior Member


Medals: 1



« Reply #67 - Posted 2008-06-25 16:36:25 »

Hello.  I made simple Scene Tree system that allows to relate nodes spacially and treat them as a tree.  It's pretty basic but useful for attaching objects to each other.  I also made OBJ format reader, although it is buggy right now, and does not support full OBJ format.  It pretty much can parse the output of light wave's OBJ exporter and create a Node that can be used in the rest of my Scene tree.

here is link to old version of my source code: http://code.google.com/p/cs456-team-badabing/source/browse/trunk/src/edu/ohiou/cs456_badabing/sceneapi/basic/ANode.java

and here are corresponding Javadocs - http://giga2.cs.ohiou.edu/~neiman/spsa/edu/ohiou/cs456_badabing/sceneapi/basic/package-summary.html

All of the scene stuff is located in *.basic package.  everything else is for my old CS class.  I will probably upload new source code soon to a different place.

I am definitely looking to checking out your guy's stuff though, thank you in advance!

If you get a chance, I would download the latest joglutils loader (not in the original branch but the new stuff) and try to add your OBJ loader and/or add to the one that has been started there.  I've not looked at it myself yet so I don't know how much is complete but it might be of interest to you.

Thanks for the contribution and keep it coming.
Offline bpeck

Senior Newbie





« Reply #68 - Posted 2008-07-21 05:16:38 »

Would you guys be interested in a Frame Buffer Object class? It covers all the basic stuff like color and depth attachments, but it has some neat features like support for multiple color attachments (a nice feature for those doing GPGPU stuff), and you can designate either a texture or render buffer as the attachment type.
Offline Z-Knight

Senior Member


Medals: 1



« Reply #69 - Posted 2008-07-21 16:54:39 »

Would you guys be interested in a Frame Buffer Object class? It covers all the basic stuff like color and depth attachments, but it has some neat features like support for multiple color attachments (a nice feature for those doing GPGPU stuff), and you can designate either a texture or render buffer as the attachment type.

heck yeah, I think any improvements would be welcome.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline bpeck

Senior Newbie





« Reply #70 - Posted 2008-07-24 22:46:11 »

I submitted the code to dev@games.java.net, let me know if it is of any use

thanks,
Ben Peck
Offline Glex

Senior Newbie





« Reply #71 - Posted 2009-02-01 19:07:25 »

is the project still alive?
Offline rsantina

Junior Member





« Reply #72 - Posted 2009-02-10 15:24:49 »

is the project still alive?

Hello,

is this project still alive and if so where can i find the latest build.. iwould like to give some of the features a test run ..

Thanks
Offline Z-Knight

Senior Member


Medals: 1



« Reply #73 - Posted 2009-02-10 19:51:44 »

Yes, the project is alive.  I personally have updates that I've planning on making but I've not had the free time to do them.  In particular, I want to add updates in these areas of the 3DS Model Loader:
         - Include VBO loading/rendering option
         - Include Serialization of model files for faster reading/processing
         - Improve the example viewer code to have more functionality and better lighting

I don't have a timetable of the update because I need to first convert my code to the new structure that was created in the last update.

here is the main project site:   https://joglutils.dev.java.net/  The files are available via SVN or you can download individual files from the Documents and Files section.

For some reason the dev sites are not accessible right now...figures the timing!

Offline GameCodingNinja

Senior Newbie





« Reply #74 - Posted 2009-07-09 21:42:50 »

This all sounds very exciting! I'm hoping some day I'll be able to load a model with bone animations and be able call the animations from my code. As far as 3D programming goes, bones and shaders are the two things I haven't been able to wrap my brain around.
Offline Z-Knight

Senior Member


Medals: 1



« Reply #75 - Posted 2009-07-31 17:44:46 »

WHY have my developer roles been revoked on this project?HuhHuhHuhHuhHuhHuhHuhHuh!
Offline Z-Knight

Senior Member


Medals: 1



« Reply #76 - Posted 2009-08-07 16:51:59 »

wow, nice...really, you have NO answer for me?  See if people are going to be willing to waste their time contributing in the future.
Offline rodgersgb

Senior Newbie





« Reply #77 - Posted 2009-08-19 02:54:20 »

WHY have my developer roles been revoked on this project?HuhHuhHuhHuhHuhHuhHuhHuh!

So have mine.  Cry
Offline bienator

Senior Member




OutOfCoffeeException


« Reply #78 - Posted 2009-08-19 23:43:50 »

i think all jogl projects have been closed on java.net as they moved them to kenai...
http://kenai.com/projects/jogl

Offline Z-Knight

Senior Member


Medals: 1



« Reply #79 - Posted 2009-08-21 16:43:33 »

good to know...thanks.   I wish that was sort of included in any emails, I'm simply not able to follows news from every darn website.
Offline jdp

Senior Newbie




NEWT is beautiful


« Reply #80 - Posted 2009-11-26 01:41:03 »

hi,
when i build jogl-utils from github it can't find vecmath.. in my copy i repacked jogl-utils/make/lib/jogl-demos-util.jar with vecmath to get it to build.
best,
john

Offline gouessej
« Reply #81 - Posted 2009-11-27 23:16:44 »

hi,
when i build jogl-utils from github it can't find vecmath.. in my copy i repacked jogl-utils/make/lib/jogl-demos-util.jar with vecmath to get it to build.
best,
john

Thanks.

Offline gouessej
« Reply #82 - Posted 2012-11-20 08:55:23 »

i think all jogl projects have been closed on java.net as they moved them to kenai...
http://kenai.com/projects/jogl
JOGL has been moved here.

Online ra4king

JGO Kernel


Medals: 342
Projects: 2
Exp: 5 years


I'm the King!


« Reply #83 - Posted 2012-11-20 09:42:36 »

WTF this is almost 3 years old!

Offline gouessej
« Reply #84 - Posted 2012-11-20 10:36:45 »

This thread is now non-sticky in order to focus less attention on outdated information.

Pages: 1 2 [3]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (25 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (43 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!