Game Development Community

LOD using separate files - model goes invisible (T3D)

by Keith G Wood · in Technical Issues · 05/24/2011 (12:21 am) · 11 replies

I am trying to follow the example in the help file (under TSShapeConstructor Class Reference, about 25% down - sub title "Example 5: LOD using separate file").

In my case rather than searching the directory for files with the same base name, I am explicitly constructing the (one) filename. Part of the reason for doing this is I had conflict of texture file names if I put both in the same directory. (I'm using Google Sketchup, which always seems to name textures "untitled..."). I've put in lots of "error" so I can see what is happening via the console. The code is given below.

Now if I comment out the last line - i.e. I dont make the call to addMesh() - then the model displays as before. The information logged to the console suggests the %fullPath is correct.

The second model (the one added by addMesh) is geometrically identical to the principal model - but I've made it bright magenta - my thinking was it would be very easy to see the change in use of model LOD as it changed colour. (Once the functionality is there, then I can work on producing the real different LOD models).

Unfortunately, with the addMesh executed, the model is invisible, regardless of the players distance. The return value from addMesh is "1" - suggesting that something has happened "successfully" (just not what I was expecting).

If I move the player towards the model, it appears that some of the collision is working (not all) - I can walk through some of the (now invisible) walls, but not all of them. Also it seems to try & render something when I am close - but this is little more than the occasional black "blob" (& is sufficiently vague I can't tie it in my mind to the actual gemometry of the object).

The model is equally invisible if I look in the world editor, and (unfortunately) the shape editor dialogs seem quite different to those described in the html documentation, so I'm baffled there.

I assume there is some very basic "gotcha" that I'm falling into - but it's not obvious to me from this side of the problem - any suggestions anyone?

singleton TSShapeConstructor(Chalet002Kmz)
{
   baseShape = "./Chalet002.kmz";
   matNamePrefix = "chalet0";
   loadLights = "0";
};

function Chalet002Kmz::onLoad( %this )
{
   %objName = %this.getObjectName(0);
   error(%objName);
   %fullPath = filePath(%this.baseShape) @ "/L256/chalet.cached.dts";
   error(%fullPath);
   %fullPath = makeRelativePath(%fullPath, getMainDotCSDir());
   error(%fullPath);
   error(%this.addMesh(%objName SPC 256, %fullPath, %objName SPC 2));
}

#1
05/24/2011 (6:00 am)
There's a bug in 1.1beta3. There's a bugfix for this - well a hack, in the Private T3D forums. linky

This is fixed in Preview (and there's a bugfix for another related issue there)
#2
05/24/2011 (10:44 am)
I've tried following the fixes for both beta 3 & preview. The beta 3 fixes seem to make no difference to my symptoms.

In preview I can see the default model OK at a distance, but when I get close enough for the higher detail model to cut in only small parts get rendered (as it happens, a window frame, and nothing else - I have no idea what is special about the window frame).

I seem to be stuck again - not sure where to take this.

[edit]
I've just tried going back to beta 2 - this has no model rendered at a distnace, but just the window frames close up (a sort of hybrid of what I've seen on beta 3 & preview). I'll now try applying the beta 3 fixes to beta 2 & see what difference that makes

[edit]
Played around a bit more, so here's a summary of where I'm at (in what follows, "secondary model" is the one added with addMesh).

Beta 2 & preview (with the fix) display the secondary model the same (but wrong). Beta 2 never displays the primary model, preview always displays (completely correctly) the primary model.

So - preview has fixed the non-rendering of the primary model. But there is still an issue with the secondary model.

If I display the primary model without doing an addMesh for the secondary, it displays fine in both beta2 & preview. If I display the secondary model on its own, it also displays fine in both beta2 & preview.

In all cases, I have created the models in Google Sketchup and exported as kmz. The primary & secondary models are stored in different directory locations with different base file names & different material prefixes. Visible mesh collision is being used.

Test 1: same geometry, secondary model all magenta - secondary model displays at correct distance, but only one window frame is rendered (magenta). Only this visible geometry collides.

Test 2: identical (full correct detail) models. Same results as test 1, except the window frame shows with correct textures.

Test 3: primary model, remove all detail except floor. Secondary model shows at correct distance, but only the roof (too high to determine if it collides correctly - but I would guess it does).

Test 4: primary model, remove all original detail, add new detail which is effectively "underground" & hence never visible. Secondary model shows at correct distance, but only the floor.

I could play with further edits to the models - but there doesn't seem to be any obvious pattern to what is going on - other than to say the geometry of the primary model clearly influences what parts of the secondary model actually get rendered. If I was to hazard a guess I would say there may be aspects of the secondary model which happen to have identical handles to aspects of the primary model, and hence get incorrectly identified as part of the primary model & so omitted - but that is pure speculation. (I base this guess on the fact that so much of what Sketchup puts into a kmz file uses the same default names over & over).

I have also tried changing the collision to none - this doesn't seem to impact the rendering issues.

Is this a known issue? Should I raise a bug report against T3D preview? Any suggestions for anything else to try?

[edit]

I've now raised this as a bug as it doesn't seem to be logged elsewhere and certainly appears to be wrong.
#3
05/26/2011 (8:43 am)
Keith, don't know if this can fit into your desidered pipeline but in my case when using sketchup I get LODs working using the appropriate node structure...

Some simple steps...
- Model a cube
- Select all his geometries and group it
- Duplicate this group 3 times
- Now select first group and give it a color
- Repeat this for every group
- Now convert each group into a component and name each, for example "cube_32", "cube_64" and "cube_128"
- Export as .DAE
- Import into T3D using the shape editor and select to use the trailing number...

It should work, let me know if you have any problem.

Cheers :-)

P.S. the key here is that groups or component are exported into the .DAE as named meshes, usually I prefer to use components...
This should also solve the problem of texture naming of sketchup... Anyway to have a better control of it sometimes I use an XML editor ("XML notepad " from microsoft could be sufficient)to modify the reference to the texture filename and then rename the texture files according to my modifications to the .DAE... it's a little pain, I know... Sketchup texturing could/SHOULD be improved a lot!
#4
05/26/2011 (10:43 am)
Hi Giorgio,

Thanks for the info, given it a try, but...

I'm still doing something wrong. Here is what I'm doing absolutely step by step (I found Sketchup components, etc. rather convoluted - so I wonder if I'm getting it wrong early on?)

Steps numbered, so you can tell me which numbered step I fell over at! (Hopefully it is obvious).

1) I made a cube 4m x 4m x 4m.

2) Selected the whole cube, then menu: Edit -> Make Group

3) Duplicated 3 times (I separated these so I could see all four easily).

4) Painted all four cubes different colours (I chose blue, green, red, yellow - should be obvious to see the difference).

OK - here is where I got a bit confused....

5) Select a group, then menu: Edit -> Solid Group -> Make Component

6) Select again (now a component?) Edit -> Solid Component -> Edit Component.

7) Select again: Edit -> Make Component - this brings up a dialog where I can enter a name (the only way I could find to enter a name). So I chose cube_2, cube_32, cube_64, cube_128 for the four cubes (repeating steps 5, 6, 7 for each cube).

8) Move each of the cubes to same location so they all occupy the same physical space.

9) Export as cube.dae.

10) Into world editor. Scene Tree -> Library Tag -> Meshes Tag -> navigate to cube.dae -> double click

11) Brings up dialog: Set LOD = TrailingNumber (leave 2 next to it?); Materials Prefix = "cube"; everything else default - press OK

I can now see a bounding box surounding an invisible cube.

In the console it reports:

Object mesh "Group_1" has no matching detail ("detail-1" has been added automatically).

(Repeats "Group_n" 4 times: 1, 2, 3, 4). No mention of cube or 2, 32, 64, 128.

A cube.cs and cube.cached.dts have been created in the same directory as cube.dae.

That's it. I have tried with beta 3 & preview, doesn't seem to make any difference. I'm sure I'm being daft somewhere, but I can't work out where at the moment. Any pointers greatly appreciated.
#5
05/28/2011 (4:14 am)
I've played with this some more. I thought I had the cube example working, but then I tried to repeat it & I couldn't. It seems random whether names I allocated in SketchUp make it into Torque. If I try anything other than a cube Torque seems to either crash or the geometry gets corrupted.

I've tried downgrading to Sketchup 7 (from 8) - it seems different, but not really better or worse.

I'm at the end of my tether here. I'm going to take a break otherwise the monitor will get thrown out of the window.

If anybody could just give a precise step-by-detailed-step of how to get this working I'd really appreciate it. At moment I'm so near but so far.

I really need to get this working as I have a bucket-full of detailed models I don't want to have to recreate in a different tool (or have to learn a new tool for that matter). As long as I only have a single model, Sketchup models work fine - it is adding the LOD that is completely frustrating me.
#6
05/30/2011 (2:45 pm)
Hi Keith, I made a pair of screencast showing the simplest way to do that last evening but I had some problem publishing it... It was very late so I deferred the posting to this evening...

It take some time before they will be available on youtube, so for the moment... here they are :-)

Let me know if you have some problem...

[EDIT:] youtube videos...


#7
06/01/2011 (11:59 pm)
I have this sort of working, except I have to be much too close to the model before it changes to the higher detail model. When I tried to use the shape editor, it crashed.

SO I'm still missing something
#8
06/02/2011 (2:21 am)
The numbers you append to the name of group decide at which size of the object on screen it switch from the previous level of detail...

Cube256 will show only when the objects has a size on screen of at least 256px...

So to switch at alower size try naming them cube2, cube16, cube 32 ... try different values and decide which is the best... remember that when using the slider to manual switch you can see the actual size of the object so you can determine which size to try...
#9
06/02/2011 (10:52 am)
I understand the appended numbers & I've got this working with simple models. However, as I move to more complex/realistic models, I can't get it to work properly.

However, I have an alternate way to do it which is working, so I'll use that. Thanks for your efforts though, I appreciate it.
#10
09/07/2011 (12:10 pm)
Keith, would you please let us know your alternative method? I am having the same problem and have found a few references here that indicate you have a fix, but no posting of the fix.

Thank you! It would save us a great deal of frustration. :)
#11
09/07/2011 (11:10 pm)
Yes - sorry - I am generating a document describing the whole process, but I have been rather unwell the last couple of months & have only recently got back into things.

I intend to post the method once it is properly written up.

In the meantime, if anyone wants the incomplete rough notes, contact me direct on: genius@the-wood-family.org.uk