Page 1 of 1

Enable or disable an object at a specified distance

Posted: 20.02.2019, 11:21
by Art Blos
It is necessary that the object was visible only from a distance of several kilometers. And vice versa, so that it is invisible at close, but only at long distance. Scripts are capable of this?

Posted: 20.02.2019, 14:30
by selden
Yes.

You could write a ScriptedOrbit for the object. It could calculate the distance from the observer to the object and call setvisible(true) or setvisible (false).

Posted: 20.02.2019, 15:33
by Art Blos
selden wrote:You could write a ScriptedOrbit for the object. It could calculate the distance from the observer to the object and call setvisible(true) or setvisible (false).
You, as always, give me hope for the realization of my ideas. :smile:

Can you make a script in which object №1 disappears when approaching 10 kilometers, and then object №2 appears?

Posted: 21.02.2019, 18:57
by selden
http://www.classe.cornell.edu/~seb/celestia/files/replace_obj.zip (10 KB expands to 27 KB)
is an addon which demonstrates how to use a ScriptedOrbit to replace one object by a second. It uses setvisible() to control which of the two object can be seen, depending on the distance from the observer's viewpoint to the first object.

The attachments below show what is seen depending on if the observer is more or less than 10km from an object

Posted: 21.02.2019, 21:12
by Art Blos
Thank you! I will sort this out. :smile:

Posted: 26.02.2019, 10:02
by Art Blos
selden, A big request to respond to my personal message regarding this topic. :biggrin:

Posted: 26.02.2019, 15:53
by selden
replace_obj_v2 is now available:
https://www.classe.cornell.edu/~seb/celestia/files/replace_obj_v2.zip (11 KB expands to 27 KB).

You should delete replace_obj before installing v2.

v2 adds an example of replacing Mars by a cube. No modifications to Celestia's own definition of Mars are required.

Below are screengrabs to show what Mars looks like at different distances.

Posted: 26.02.2019, 16:54
by Art Blos
Fine! Thanks again!

Posted: 27.02.2019, 14:37
by selden
You're very welcome.

Posted: 02.03.2019, 23:42
by Lafuente_Astronomy
Well, is it possible to apply the same code to stars?

I'm asking that because in another post: viewtopic.php?f=23&t=17931 , I asked if it's possible to make a code in which stars only appear within 10 million light years from the user's location, meaning that as the user moves around Celestia's simulated universe, stars would get enabled and disabled on the way.

Posted: 03.03.2019, 04:52
by selden
Unfortunately, the various tricks one can think of to expand the distance at which Stars can be drawn need to be implemented within the C++ source code of Celestia. That distance is limited by the size of the numbers being used in Celestia's internal databases. For example, writing the C++ code to support changing the center of the coordinate system to another location in space would require some substantial research, code writing and testing.

All my code does is change the visibility of an existing Object. It doesn't affect the distance limitations.

Also, the features that I used (ScriptedOrbit and Visibility) are available only for SSC (Stellar System Catalog) objects: non-radiating objects which orbit around a star. Celestia does not currently support the use of either ScriptedOrbit or Visibility in STC (STar Catalog) or DSC (Deep Space Catalog) files. I believe it should be possible to extend STC catalog functionality to support ScriptedOrbit, but not DSC.

In principle, once Visibility is implemented for STC and DSC objects, one should be able to do something similar to what I did (turn an object off or on) by using a CELX script, but that still would be working within the distance limitations imposed by the calculations that Celestia uses to position objects in space. Objects which are within Celestia's maximum distance could be made to disappear or appear, but doing that doesn't change the maximum possible drawing distance.

Posted: 03.03.2019, 12:13
by Lafuente_Astronomy
selden wrote:nfortunately, the various tricks one can think of to expand the distance at which Stars can be drawn need to be implemented within the C++ source code of Celestia. That distance is limited by the size of the numbers being used in Celestia's internal databases. For example, writing the C++ code to support changing the center of the coordinate system to another location in space would require some substantial research, code writing and testing.

All my code does is change the visibility of an existing Object. It doesn't affect the distance limitations.

Also, the features that I used (ScriptedOrbit and Visibility) are available only for SSC (Stellar System Catalog) objects: non-radiating objects which orbit around a star. Celestia does not currently support the use of either ScriptedOrbit or Visibility in STC (STar Catalog) or DSC (Deep Space Catalog) files. I believe it should be possible to extend STC catalog functionality to support ScriptedOrbit, but not DSC.

In principle, once Visibility is implemented for STC and DSC objects, one should be able to do something similar to what I did (turn an object off or on) by using a CELX script, but that still would be working within the distance limitations imposed by the calculations that Celestia uses to position objects in space. Objects which are within Celestia's maximum distance could be made to disappear or appear, but doing that doesn't change the maximum possible drawing distance.

Sorry if it's a late reply

Ahhhh. It may take some time, or a long time but I know that eventually you and anyone working on Celestia will get there. Keep up the good work.