Author Topic: Question: Models, lighting, and more.  (Read 12885 times)

Offline Raven

  • int
  • **
  • Posts: 62
    • View Profile
    • http://www.vortex.is/raven
Question: Models, lighting, and more.
« on: October 28, 2005, 02:13:04 pm »
Firstly, I'd like to say that jPCT is awesome.
In only the two days I've been experimenting with the examples, I've been able to create a humanoid character in the FPSdemo capable of moving around and being "shot", as well as making the weapon fire projectiles. I love working with this engine. Thank you for creating it.

However, I have a few questions, mostly due to my inexperience with 3D.

1. I've been playing around with loading various 3ds models. After realizing that objects must be merged, everything works great except that with complex models everything slows *extremely* down when I look at them. Even down to 2FPS in worst cases. This can hardly be due to processing power since I'm running a 2x2.5ghz 64bit powermac with 2GBRAM.

- So what am I doing wrong? (I load the models the same way as the levels are loaded in the FPS demo).


2. Regarding levels in the FPSdemo. How is the playerPosition originally calculated, as well as the lighting? I understand that the level is a 3DS model, but can you figure out a position for the player/lights while you're in a 3D Editor somehow? Or will you have to 'guess' the position after you load it into jPCT?

I'm wondering what the best way would be for me manage this. There's also the question of object placement: Figuring out where to place objects like "Healthpacks" for example.

3. Can objects emit light? For example, could I create a Flashlight object?

I noticed some really cool lighting effects in Paradroidz where the player seems to emit red light.

4. I still haven't been able to try object animations; I don't know yet how to animate 3D and I can't find any md2 files -- does anyone know where I can find an example MD2 file to test animation?

5. Just for interests sake: You can have more than once instances of a camera, right? Would it be possible to project the input of one camera to an object in game? An example of the usage: 'Security' cameras placed in a map can be viewed by the player on Monitor Objects?


There'll probably be more questions later, but thanks in advance.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Question: Models, lighting, and more.
« Reply #1 on: October 28, 2005, 02:51:54 pm »
Quote from: "Raven"
1. I've been playing around with loading various 3ds models. After realizing that objects must be merged, everything works great except that with complex models everything slows *extremely* down when I look at them. Even down to 2FPS in worst cases. This can hardly be due to processing power since I'm running a 2x2.5ghz 64bit powermac with 2GBRAM.

- So what am I doing wrong? (I load the models the same way as the levels are loaded in the FPS demo).

I think that the models you are using are simply too complex for the engine to handle. jPCT is not a "polygon pusher" due to the way it works internally. For real time 3D graphics, you should opt for low poly models, not for these great looking, but huge things that can be found on most free model sites. How many polygons do the models have that are causing the problems? You may also set Config.glVertexArrays to true (or download jPCT 1.08 which does this by default). It may help a little, but as said: Use lower poly models for real time stuff.

Quote from: "Raven"

2. Regarding levels in the FPSdemo. How is the playerPosition originally calculated, as well as the lighting?

I assigned a key to Camera.getPosition(), walked through the level, pressed that key where i wanted to add a lightsource and wrote down the position...

Quote from: "Raven"

3. Can objects emit light? For example, could I create a Flashlight object?
In Paradroidz, the Player-instance includes a light that moves with the player (i.e. i'm setting it's position to the player's one). So no, Object3D can't emit light, but you can move the lights so that it looks like that.


Quote from: "Raven"

4. I still haven't been able to try object animations; I don't know yet how to animate 3D and I can't find any md2 files -- does anyone know where I can find an example MD2 file to test animation?

Have a look at http://www.planetquake.com. They once had a nice collection of MD2s. MD2s are Quake2 models. I hope they are still offering it. If not, let me know. I can send you some models for testing purposes.
Edit: The site seems to be gone...what a pity! I'll upload some md2-files to http://www.jpct.net/download/md2 for you...

Quote from: "Raven"

5. Just for interests sake: You can have more than once instances of a camera, right? Would it be possible to project the input of one camera to an object in game? An example of the usage: 'Security' cameras placed in a map can be viewed by the player on Monitor Objects?
To a degree, but only by using a strange combination of hardware and software rendering which includes texture uploading and stuff. That's because jPCT doesn't support "render to texture". Basically, you would have to render the monitor image using the software renderer in a different FrameBuffer, copy that into a texture and render the scene with that texture using the hardware renderer. Could be a little slow depending on how often you are planning to update the monitor's image.

Offline Raven

  • int
  • **
  • Posts: 62
    • View Profile
    • http://www.vortex.is/raven
Thanks and More problems....
« Reply #2 on: October 28, 2005, 05:34:43 pm »
Thanks a lot for a quick and good response! The camera fly-through solution is great.

Also thanks for the MD2's!
 :D
I'd actually found a package containing some md2's, but the more the merrier.

I've been trying to load an animation from an MD2 object, but alas, no luck. I followed the instructions I found in a topic named "Loading animation from a md2 file" here on the board. But it seems that no matter what I do I always end up with a nullpointer exception.

How do I know the index and sequence numbers?
I can view the animations through a 3D editor, but I can't find any sort of numbering. Here's the code I use to load:

Code: [Select]

Object3D demon=Loader.loadMD2("md2/demon.md2", 0.3f);
TextureManager.getInstance().addTexture("myTexture", new Texture("md2/ql6.jpg"));
demon.setTexture("myTexture");
demon.setCenter(SimpleVector.ORIGIN);
demon.translate(800, -120, -480);
demon.build();
theWorld.addObject(demon);


And here's the code for the mainWhileLoop:

Code: [Select]
 
float anim = 0f;
demon.animate(anim, 1);
      if (anim>1) {
         anim=0;
      } else {
         anim+=0.1f;
      }


Here's the error:

Code: [Select]

Exception in thread "main" java.lang.NullPointerException
        at JPCTDemo.gameLoop(JPCTDemo.java:838)
        at JPCTDemo.<init>(JPCTDemo.java:510)
        at JPCTDemo.main(JPCTDemo.java:184)


For reference, here's the loading part of the MD2 file:

Code: [Select]

Loading file md2/demon.md2
File md2/demon.md2 loaded...32540 bytes
Magic number: 844121161
Version: 8
Skin width: 256
Skin height: 256
Frame size: 1120
Number of skins: 1
Number of Vertices: 270
Number of Texture coordinates: 210
Number of triangles: 488
Number of GL-commands: 2508
Number of Frames: 14
Reading Texture coordinates...
Done!
Reading polygonal data...
Done!
Reading keyframes...
Done!
Coverting MD2-format into jPCT-format...
Processing: pigstand...
Processing: pigwalk...
Processing: pigpain...
Processing: pigbite...
Done!


Am I supposed to be able to identify sequence/index numbers from this?

It seems to identify the animations like "stand", "walk", etc.. For a later feature, it would be great to be simply able to call Object.Animate("Walk"); or something of the sort.

But to sum up: Can't play animations of MD2 files, nullpointer error prevents it. Completely clueless of how to figure out index and sequence numbers.

Sincerely,
-Raven

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Question: Models, lighting, and more.
« Reply #3 on: October 28, 2005, 06:04:54 pm »
The nullpointer is in your code, as the stacktrace indicates. Judging from the two code snippets, i would say that either you are doing the loading in the gameLoop()-method (unlikely...) or that there are two "demons". One global and one local in the method that loads the animation and the global one isn't initialized, just the local one!?

Index always goes from 0 to 1. 0 is first key frame, 1 the last. The sequence numbers start at 1 (with 0 being the whole animation) and match to the sequences printed out while loading, i.e. in your example:

pigstand=1
pigwalk=2
...

Have a look at the Animation-class for more information on animations. There's also a method to get the sequence count from an Animation.
You may get the Animation of an Object3D by calling Object3D.getAnimationSequence(); (silly name, i should deprecate it and replace it with getAnimation();...anyway...)

Offline Raven

  • int
  • **
  • Posts: 62
    • View Profile
    • http://www.vortex.is/raven
Gratitude
« Reply #4 on: October 28, 2005, 07:18:15 pm »
Oh man, there were two demons -- the global one not initialized  :oops:

Thanks Egon, your explanation for the sequence and index really helped out too. Everything works perfectly now  :D

Well. Back to coding then.
Later.

-Raven

Offline Raven

  • int
  • **
  • Posts: 62
    • View Profile
    • http://www.vortex.is/raven
Re: Question: Models, lighting, and more.
« Reply #5 on: October 29, 2005, 01:13:07 am »
Quote from: "EgonOlsen"


Quote from: "Raven"

3. Can objects emit light? For example, could I create a Flashlight object?


In Paradroidz, the Player-instance includes a light that moves with the player (i.e. i'm setting it's position to the player's one). So no, Object3D can't emit light, but you can move the lights so that it looks like that.



This is great, I've implemented this solution and it works fine. However, I'm wondering if there is a way to make the light one-directional? I can't find any documentation on that, so I guess not. In that case, is the simplest solution to position the lightsource inside a hollow cylinder object? Or would the light shine through that cylinder?

-R

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Question: Models, lighting, and more.
« Reply #6 on: October 29, 2005, 10:59:05 am »
Quote from: "Raven"
However, I'm wondering if there is a way to make the light one-directional? I can't find any documentation on that, so I guess not. In that case, is the simplest solution to position the lightsource inside a hollow cylinder object? Or would the light shine through that cylinder?
No, directional lighting is not possible with standard vertex lighting, which is what jPCT is using. There's no way to let other objects block the light either. jPCT is following OpenGL's specs when it comes to lighting.
For a spotlight, it may be possible to fake it by using a transparent object als light cone, but i'm not sure how good that will look...maybe not too good... :wink:

Offline Raven

  • int
  • **
  • Posts: 62
    • View Profile
    • http://www.vortex.is/raven
Re: Question: Models, lighting, and more.
« Reply #7 on: October 30, 2005, 02:46:28 am »
Quote from: "EgonOlsen"
No, directional lighting is not possible with standard vertex lighting, which is what jPCT is using. There's no way to let other objects block the light either. jPCT is following OpenGL's specs when it comes to lighting.
For a spotlight, it may be possible to fake it by using a transparent object als light cone, but i'm not sure how good that will look...maybe not too good... :wink:


Ach. That sucks. Well. I guess I'll try using a transparent object to begin with. Thanks for the tip :)

-Raven

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Question: Models, lighting, and more.
« Reply #8 on: October 30, 2005, 06:51:20 am »
Hey raven, would you mind give your mac as a gift, my birthday was on tuesday!!!!!!!!!!!

You are making good stuff in low time, ery doog for you, hope to hear about your project soon!
Nada por ahora

Offline Raven

  • int
  • **
  • Posts: 62
    • View Profile
    • http://www.vortex.is/raven
Question: Models, lighting, and more.
« Reply #9 on: October 30, 2005, 11:28:58 pm »
Some people buy cars... I bought my masculine G5.  :D
But here have this... eh... arrow thingy:  :arrow:
Happy birthday!

Thanks for the compliments and interest!
I'll be posting progress soon enough I hope.

Offline Raven

  • int
  • **
  • Posts: 62
    • View Profile
    • http://www.vortex.is/raven
Lighted object in an unlit environment
« Reply #10 on: November 05, 2005, 01:38:10 am »
Hey all again.

I'm trying to get an object to stay "clear/lit" in an unlit environment.

I was hoping to get it working by setting the object's lighting to NO_LIGHTS while keeping the texture in bright colors, but alas, no worky.

Is there any way to get this effect?

Relevant to this question, is: Is it possible to control the range of a lightsource? In other words, how far a Light reaches?

EDIT: One more question. Given that there are X many objects currently Z-near the camera (or currently in the camera's field of vision) , is there any way to get a list of those objects?

-Raven

Offline rolz

  • float
  • ****
  • Posts: 280
  • Technocrat
    • View Profile
Question: Models, lighting, and more.
« Reply #11 on: November 05, 2005, 09:19:05 am »
Quote

I'm trying to get an object to stay "clear/lit" in an unlit environment.

I was hoping to get it working by setting the object's lighting to NO_LIGHTS while keeping the texture in bright colors, but alas, no worky.


maybe setting additional color will help
Code: [Select]

object.setLighting(Object3D.LIGHTING_NO_LIGHTS);
object.setAdditionalColor(yourBrightColor);


Quote

Relevant to this question, is: Is it possible to control the range of a lightsource? In other words, how far a Light reaches?


Try playing with following parameters for lighting.

Config.lightDiscardDistance
Config.linearDiv
Config.lightMul

you may adjust lighting intensity for a datasource with world.setLightIntensity();
Regards,
Andrei

Offline Raven

  • int
  • **
  • Posts: 62
    • View Profile
    • http://www.vortex.is/raven
Question: Models, lighting, and more.
« Reply #12 on: November 06, 2005, 12:06:15 am »
:D

The additional color did the trick. Thanks a lot Rolz/Andrei!

The Config switches are good to know about too, but I wanted to adjust a specific light and not just the whole scene. Thanks though, I won't be needing to use that option since additional color worked so well.

How about the my third question regarding object lists? Any method that returns an array of Object3D's within a given distance from, for example, a camera?


-Hrafn "Raven" Thórisson

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Question: Models, lighting, and more.
« Reply #13 on: November 06, 2005, 12:37:05 pm »
Quote from: "Raven"

How about the my third question regarding object lists? Any method that returns an array of Object3D's within a given distance from, for example, a camera?
No, you have to do this yourself. It's easy. Just iterate through the objects of a world, get their transformed center and calculate the distance from the camera's position (i.e. subtract the camera's position and get the length...can both be done by using the appropriate methods in SimpleVector) to each of them.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Question: Models, lighting, and more.
« Reply #14 on: November 06, 2005, 01:22:07 pm »
Quote from: "Raven"
I'm wondering what the best way would be for me manage this. There's also the question of object placement: Figuring out where to place objects like "Healthpacks" for example.


possibly not best way, but i find this very handy:
i either:
* place dummy objects to mark those positions and save them in a seperate file (like lights.3ds) and then use the center of those objects to place lights
* again place dummy objects but save thier positions with max script (faster loading time and less space)

Code: [Select]
r a f t