Model Position Randomizing

Hello! Can someone tell me what are the positions of the “models/environment.egg.pz” model? I mean, I want to randomly show a model on the screen, but I don’t know what coordinates to give to the random.randint method.

I think that you can get the relevant values–or at least a good starting-point–via PView. If you load the environment model in PView, you can print out the bounding-volume by pressing “shift-B”.

If you want the size of only part of the environment (such as the bit that includes the bamboo), then you can activate node-highlighting by pressing “H”, then select the relevant part using the arrow-keys, and finally once again print out the bounding-volume by pressing “shift-B”.

(Note that this prints the volume out to the console, so I recommend running PView from the console/terminal in order to see this.)

In order to list commands available within PView, you can press “?” while PView is running, which should result in help-text being overlaid on the screen.

In this case, if I’m reading this correctly, the radius of the full environment seems to be ~904 units, while the radius of the bamboo-strewn area seems to be ~295 units. The centre of the bounding volume seems to be at approximately (21, -124, -5.7).

You can also use this plug-in to import the model into Blender and read out the positions there.

1 Like

What does this stand for? bsphere, c (32.428 -124.476 -5.69269), r 903.769

I could do that, but I don’t have Blender on this PC. It is on my other one.

I’m inferring, but I imagine that it means as follows:

bsphere = bounding-sphere. I.e. the object being printed is a bounding-sphere.

c (32.428 -124.476 -5.69269) = centre of said sphere at position (32.428 -124.476 -5.69269)

r 903.769 = radius of said sphere is 903.769

So basically, the function should be:

import random
xpos = random.randint(32.428 - 903.769, 32.428 + 903.769)
ypos = random.randint(-124.476 - 903.769, -124.476 + 903.769)
zpos = 0 # So it stays on the ground

I tried it, but I need the arguments to be of type int not float

Then simply remove the numerals after the decimal points.

I think you are looking for random.uniform, not random.randint. The latter only works on integers, as the name suggests.

1 Like