Hi all.
I’ve been trying to make my own distanceLod, as the existing one did not meet my needs. (needed the LOD to wait for low threaded creation of the correct level before trying to display it. )
I subclassed LOD, and added a switch, then added objects to it when they were available. That worked, but, no objects came to the world. After many tries and guesses, i came to (shame on me) decompile LOD and DistanceLOD in order to get a clue on how they work.
To my surprise, i saw that:
VirtualUniverse.mc.addToTransformFreeList(transform3d);
It seems that it is the step that displays the correct level, and of course, i can’t access it, as VirtualUniverse has no “mc” reference it wants to share with me.
That MC is a private class called MasterControl, that i can’t access, of course.
So, it seems that, unless you are sun, you can’t make your LOD to behave correctly. Adding switches and setting objects, as the interface is done, seems of no use, because those things are only done for storage, and no part of the base class use them for displaying. (shame on them)
Are there tricks ? If not, i think i’ll add my switch at the parent group of the LOD, during construction, but that would lead to eventual problems, and i guess that it’s why they took that route. Any other ideas?
Ogre has an LOD implementation under the LGPL you could learn from. Maybe that will help you write your own.
Well, i already wrote my own. I actually have an implementation that generates different levels when needed, asynchronously. That works well, for the moment.
My only problem is to use the given mechanisms to add my objects to the scenegraph. The major point is that LOD does not implement the mechanisms to show the correct object in the scenegraph, and that the only implementation does it using “weird means”. Actually, LOD is a container, nothing more. Except handling a Vector of switches and minimal Behavior methods, nothing to expect from there.
Thus, i’m wondering what i can do with that.
Will i use the tools i’ve been given, or will i have to reinvent the wheel? Problem is that i would need to have a behavior abd a switch. That means two objects to add, handle and synchronize. Maybe i will subclass Group and silently add a switch and a behavior behind it. … well…
Okay. i’ve changed my lod. i now stopped extending LOD, and instead extended TransformGroup. When constructing, i silently add a behavior and a switch to the instance, and handle them through the TG. My objects are now displayed. (yeehaaa)
I feel like filling a RFE, as LOD should include a method to indicate the position of the switch to display as the current level…
Something like setDisplayedLevel( Switch sw, int pos ).
What do you think ?
By the way, am i the only one around that ever tried to make a custom lod?
isn’t there something called a SwitchGroup that does that exact thing (allow you to pick one of several BranchGroups)? I’m not very familiar with the LOD classes, so maybe it does some other nice things for you too that the SwitchGroup (or whatever it’s called) doesn’t.
yes, cestainly. It’s Switch. But switch allows you to select one branch, and only that. you still need the logic to select the branch depending on the behavior of your lod selection method. And, there, the keyzord is behavior… i should say Behavior.
LOD , at least as sun uses it in DistanceLOD, is both of them. It is a Behavior that can add an object to the world, directly. You only have one object in your scene, and it handles all itself.
In my implenentatiion, that now works perfectly, my lod consists of a subclass of TransformGroup,. At construct time, it adds a Switch and a Behavior to itself. i now have three objects instead of one. By the way, the reason i needed to create my own lod was that i needed to generate and add only the levels that were to be displayed, based on the user’s changing position. Lod levels are generated asynchrnously by a background thread, giving the system a near realtime (opposed to online) capability… As far as my investigations took me, that was not possible with sun’s DistanceLOD,
Worst now: to add an object to my Switch, as it is part of the live scenegraph, i need to add it to a BranchGroup. That makes two objects for each level. On the opposite, Sun’s DistanceLOD does not have this problem.
So, using my system, a four level LOD consists of : a TransformGroup, a Behavior, a Switch, four BranchGroups, four Nodes ( at least, depends on the content of the level) and Sun’s is a DistanceLOD, a Switch, and four Nodes (at least, for the same reasons). Moreover, my method is less neat, because the scenegraph is greatly complicated.
But, as the specs do not specify a method in LOD to select the level of the Switch to be showm, it turns out that LOD is of NO use for most of us.
My guess is that what is done in DistanceLOD to add the object to the scenegraph could be done in a ;ethod of LOD. We could then call it at the end of processStimulus, and the world would be better.
Unless i’m wrong and took the wrong way in my investigations, that 's bad for the spec, and the RFE is coming.