ScriptSpot

Forum topic · General Scripting

Getting the pixel dimensions of an object

By Chris2307 · 2016-12-12

Description

Hi everyone,

Now I know the title doesn't make a great deal of sense - I'm aware that when you work in 3D, the pixel size of an object is largely unrelated.

However, I am working on a project where I need to swap two 3D objects with each other, whilst maintaining their "screen size". For example, if I had an object 10 metres away from the camera) and an object 30 metres away from the camera and I swapped these two objects, I would want the objects to maintain their original screen size.

I have some constants in this scenario: The camera position, camera orientation, camera FOV and object positions.

I have broken this down in to three steps that I can think of:

1. Calculate the on-screen bounding box for each object. (This is where I need help)
2. Pick two objects at random.
3. Scale the pair of objects based on the bounding box properties of each other. I am going to calculate the percentage difference between the two objects' on-screen bounding box and use this to scale them appropriately in 3D space.

Is this possible in MaxScript?

Comments (1)

.

miauu · 2016-12-13

Attached is the script, created by Enrico Gulloti. I can't find it in the net, so download it and use it to write your won script. The script works only with Editable Mesh and Editable Poly objects.

Attachments