Debugging a Model

tl;dr: I’ve got a model that doesn’t render when it’s loaded, I don’t get any errors, and I’m trying to figure out how to debug it.

I’ve got code that converts from a CAD model format directly to an egg format string, and loads that into a NodePath. This is a snippet that approximates what I’m doing (there’s more support code that would bloat the post):

result = Builder.build_model(script_path=self.model_file_path)
egg = EggData()
success = egg.read(StringStream(str.encode(result["model"])))
pn = loadEggData(egg)
self.model_container.append(NodePath(loadEggData(egg)))
self.model_container[-1].reparentTo(render)
self.model_container[-1].setColor(1, 0.5, 0, 1)

The Builder.build_model code tesselates the CAD model and gives back edges, indexes, and normals. It does not currently do UVs. It works fine with a box and a cylinder, but I’ve got a swept shape that has a taper that does not render in the view. Success is True from egg.read, and I don’t get any errors that I can see in the console. Here’s what the shape is supposed to look like:

There are multiple places things could have gone wrong in the conversion process. My code that does the CAD tessellation/conversion is still pretty naive at this point.

So I guess I have two questions:

  1. How should I got about debugging the egg model?
  2. Is the lack of inclusion of the UV data causing the problem?

Well, my first question is: where is your camera placed?

By default, the camera is at 0, 0, 0, and facing down the y-axis, if I recall correctly. As a result, if it hasn’t been moved, it looks like it would be positioned directly under the model, and thus might not “see” it.

Otherwise, you might perhaps write out your generated model as a “bam” file and attempt to load that into PView (and then press “c” to centre the model in the window); that might tell you whether you’re generating a valid model.

1 Like

Thanks for the reply.

By default, the camera is at 0, 0, 0, and facing down the y-axis, if I recall correctly.

I have the camera in the same position as when the cube and cylinder are visible, and the cone is similar in scale. I also have mouse controls and a DirectButton to bring the model into view. I could be missing something, but it just really doesn’t seem to be visible.

Otherwise, you might perhaps write out your generated model as a “bam” file and attempt to load that into PView (and then press “c” to centre the model in the window); that might tell you whether you’re generating a valid model.

Thanks for the tip. I’ll give that a try and see if it gives me any insight.

1 Like

Things you can check to see whether there is anything there:

self.model_container[-1].analyze()
self.model_container[-1].ls()
1 Like

The model now shows up. What ended up happening was that my CAD model (which is generated by a script) had an error in it that wasn’t being reported. Then while adding code to help me debug, I made a mistake. These lines:

pn = loadEggData(egg)
self.model_container.append(NodePath(loadEggData(egg)))

Should have been:

pn = loadEggData(egg)
self.model_container.append(NodePath(pm))

The display of the model works as expected now. Thank you both for the help. I expect I’ll use analyze and ls on models in the future. Those are nice to have available.

1 Like