livedisplays

You can add a custom control ( property) to any node

for example i'll add a String property to the currently selected node

var node = Scene.getPrimarySelection()

var prop = new DzStringProperty( "Status", true )

node.addProperty( prop );

prop.setValue( "Earth-Moon: " + 384400 + " km" );

if we know the object to which we added the String property is labeled "Earth"

we can change the value of the String using

var node = Scene.findNodeByLabel( "Earth" )

if( node )

{

var prop = node.findProperty( "Status" );

if( prop )

{

var x = Math.cos( 45 * Math.PI / 180 ) * 406700

var y = Math.sin( 45 * Math.PI / 180 ) * 384400

var d = Math.sqrt( x * x + y * y );

prop.setValue( "Earth-Moon: " + d + " km" );

}

}

We can know the position of a node using getWSPos()

var Earth = Scene.findNodeByLabel( "Earth" )

if( Earth)

{

var prop = Earth.findProperty( "Status" );

if( prop )

{

var Moon = Scene.findNodeByLabel( "Moon" );

var posMoon = Moon.getWSPos();

var posEarth = Earth.getWSPos();

var vecEarthMoon = posEarth.subtract( posMoon );

var dEarthMoon = vecEarthMoon.length()

var scale = 10; //( 1Km = 1mm )

prop.setValue( "Earth-Moon: " + ( dEarthMoon * scale ) + " km" );

}

}

if we know the index of a specific vertex in an object's mesh, we can know its position using getVertex()

var idxVertex = 10

var Earth = Scene.findNodeByLabel( "Earth" );

var Moon = Scene.findNodeByLabel( "Moon" );

var status = Earth.findProperty( "Status" );

var posMoon = Moon.getObject().getCachedGeom().getVertex( idxVertex );

status.setValue( "Moon Base: " + posMoon.x + " " + posMoon.y + " " + posMoon.z )

here's code to determine the vertex-index of the vertex which is the closest to ... in this case ... the Earth node

var Earth = Scene.findNodeByLabel( "Earth" );

var Moon = Scene.findNodeByLabel( "Moon" );

var cachedGeo = Moon.getObject().getCachedGeom();

var posEarth = Earth.getWSPos();

var min = 1000000000;

var n = cachedGeo.getNumVertices();

var idxBestOne = -1

for( var i = 0; i < n; i++ )

{

var p = cachedGeo.getVertex( i );

var d = p.subtract( posEarth ).length()

if( d < min )

{

min = d;

idxBestOne = i;

}

}

var status = Earth.findProperty( "Status" );

status.setValue( "nearest vertex index : " + idxBestOne );

Using script callbacks to get a live display

we can tell Daz Studio to execute a script each time a specific event happens

in our case the event will be : when the Moon changes location

this script, which we will call the callbackInstaller script expects the "live" script to be in the same disk folder as itself

the "live" script will be named displayCallBack.dsa

displayCallbackInstaller.dsa

var scriptPath = getScriptFileName()

var path = DzFileInfo( scriptPath ).path()

var callbackprefix = "displayCallBack";

var callbackfilename = callbackprefix + ".dsa";

var sScript = path + "/" + callbackfilename;

var oCallBackMgr = App.getCallBackMgr();

var oCallBack = oCallBackMgr.createCallBack( callbackprefix, sScript, false );

var Moon = Scene.findNodeByLabel( "Moon" );

oCallBack.setConnection( Moon, "transformChanged()" );

MessageBox.information( sScript, "CallBack \"" + callbackprefix + "\" installed", "&OK" );

and our live script looks like

displayCallBack.dsa

var Earth = Scene.findNodeByLabel( "Earth" )

if( Earth)

{

var prop = Earth.findProperty( "Status" );

if( prop )

{

var Moon = Scene.findNodeByLabel( "Moon" );

var posMoon = Moon.getWSPos();

var posEarth = Earth.getWSPos();

var vecEarthMoon = posEarth.subtract( posMoon );

var dEarthMoon = vecEarthMoon.length()

var scale = 10; //( 1Km = 1mm )

prop.setValue( "Earth-Moon: " + ( dEarthMoon * scale ) + " km" );

}

}

This was tested and it works !

Though possibly, the String/Display should be installed on the Moon

wait wait !

There's also the Daz Studio status line !

in this case the message will be displayed 1000 milliseconds

so here's an alternate displayCallBack.dsa

var Earth = Scene.findNodeByLabel( "Earth" )

if( Earth)

{

var Moon = Scene.findNodeByLabel( "Moon" );

var posMoon = Moon.getWSPos();

var posEarth = Earth.getWSPos();

var vecEarthMoon = posEarth.subtract( posMoon );

var dEarthMoon = vecEarthMoon.length()

var scale = 10; //( 1Km = 1mm )

MainWindow.displayPrompt( "Earth-Moon: " + ( dEarthMoon * scale ) + " km", 1000 );

}