/*
This example creates point locators at random surface locations,
and positions a Null at each of these point locators.
*/
NewScene( null, false );
var root = Application.ActiveSceneRoot;
var SphereGeom = root.AddGeometry("Sphere", "NurbsSurface").ActivePrimitive.Geometry;
var NbPtLocators = 50;
var SubSurfaceArray = new Array(NbPtLocators);
var UVArray = new Array(NbPtLocators*2);
for(i = 0; i < NbPtLocators; i++)
{
SubSurfaceArray[i] = 0;
UVArray[i*2] = Math.random();
UVArray[i*2+1] = Math.random();
}
var PointLocatorsFromRandomUVs = SphereGeom.ConstructPointLocators(SubSurfaceArray, UVArray);
CreateNullsAtPointLocations(SphereGeom, PointLocatorsFromRandomUVs);
function CreateNullsAtPointLocations( InGeom, InPointLocators )
{
var SpherePositions = InGeom.EvaluatePositions(InPointLocators).toArray();
var SphereNormals = InGeom.EvaluateNormals(InPointLocators).toArray();
var TempVector = XSIMath.CreateVector3();
var TempRotation = XSIMath.CreateRotation();
for (i = 0; i < SpherePositions.length; i+=3)
{
var NullObj = root.AddNull();
TempVector.Set(SpherePositions[i], SpherePositions[i+1], SpherePositions[i+2]);
NullObj.LocalTranslation = TempVector;
TempVector.Set(SphereNormals[i], SphereNormals[i+1], SphereNormals[i+2]);
TempRotation.SetFromXYZAxes( TempVector, TempVector, TempVector );
NullObj.LocalRotation = TempRotation;
}
} |