mcjClosestVertex For DS 4.5+




Introduction


For DS 4.5+ only

this script may eventually be made more user friendly

select an object in the scene

run the script

the script will go through up to 2000 of the selected object's facets 
and find which of those facet's vertices is closest to the camera
then the script will create a null node named mcjMarker
at that position



History




July 11 2014 2:22 pm release 
July 11 2014 5:52 pm removed debugging code which was called up to 8000 times!



Installation



The zip package is found at the bottom of this page


unzip it in your daz content folder, typically 


C:\Program Files\DAZ\Studio\content\ 

or


C:\Users\YOURUSERNAME\Documents\DAZ 3D\Studio\My Library



once installed, it will appear in your content library, under 



studio\Scripts\mcasual


or


My Library\Scripts\mcasual




source code
// DAZ Studio version 4.6.2.117 filetype DAZ Script
var pos = new DzVec3();

var minD = 1000000.0; //initialize the minimizer

var vmgr = MainWindow.getViewportMgr();
var vport = vmgr.getActiveViewport().get3DViewport();
var cam = vport.getCamera();
var camPos = cam.getWSPos()

heshootshescores()

function heshootshescores()
{
	var target = Scene.getPrimarySelection();
	if( !target )
	{
		return;
	}
	var bone;
	var facegroup = 0

	if( target.inherits( "DzBone" ) )
	{
		bone = target;
		target = target.getSkeleton();
		facegroup = 1
	}
	var obj = target.getObject()
	if( !obj )
	{
		return;
	}
	var msh = obj.getCachedGeom();
	if( facegroup )
	{
		facegroup = msh.findFaceGroup( bone.name );
		if( !facegroup )
		{
			//the bone has no faces so no facegroup
			return;
		}
	}
	var numPolys;
	if( facegroup )
	{
		numPolys = facegroup.count();
	}
	else
	{
		numPolys = msh.getNumFacets();
	}
	var step = 1;
	if( numPolys > 2000 )
	{
		step = numPolys / 2000;
		step = Math.round( step );
	}
	for( i = 0; i < numPolys; i += step )
	{
		if( facegroup )
		{
			ii = facegroup.getIndex( i );
			f = msh.getFacet( ii );
		}
		else
		{
			f = msh.getFacet( i );
		}		
		closest( msh, f.vertIdx1 )
		closest( msh, f.vertIdx2 )
		closest( msh, f.vertIdx3 )
		if( f.vertIdx4 >= 0 )
		{
			closest( msh, f.vertIdx4 )
		}
	}
	debug( pos.x + " " + pos.y + " " + pos.z );
	var marker = Scene.findNode( "mcjMarker" );
	if( !marker )
	{
		marker = new DzNode();
		marker.name = "mcjMarker";
		Scene.addNode( marker );
	}
	marker.setWSPos( pos );
}

function closest( msh, idx )
{
	var v = msh.getVertex( idx );
	var d = v.subtract( camPos ).length();
	if( d < minD )
	{
		minD = d;
		pos.x = v.x;
		pos.y = v.y;
		pos.z = v.z;
	} 
}


// Copyright (c) 2014 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files ( mcjClosestVertex ), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.


ċ
mcjClosestVertex.zip
(19k)
mCasual Jacques,
Jul 11, 2014, 2:52 PM
Comments