mcjCollider plugin

DS3 PC 32/64bit

Are you using Daz Studio 4.5 or 4.9 ?

then go away!

kidding kidding

mcjCollider for Daz Studio 4.6 or greater is over there

https://sites.google.com/site/mcasualsdazscripts2/mcjcolliderds45

mcjCollider is a plugin for Daz Studio 3 , it was tested on Daz Studio v 3.0.1.144

version history

NEWS

Oct 30th 2012

resists to conversion of collided objects to subdivision surfaces and to deletion of collided objects

the identity of the collided face is displayed as the label of the channel named "hit"

Feb 2nd 2011 7:22pm

added the 64 bit version of the plugin: mcjCollider64bit.dll

( i cant test it but will report on users results)

Feb 12, 2010 2:15 AM

initial release

Feb 12, 2010 4:15 AM

the collider now only moves forth, making it easier to do a series of collisions

but is the collider starts exactly on a surface it stays put

Feb 12, 2010 4:25 AM

the collider doesn't get stuck when it lies exactly on the wall

making it possible to do a series of collisions

i'll show you right now

Introduction

You point a ray at objects in a daz scene and this plugin computes the collision point

and the bounce angle.

Although this plugin can be used "by hand" to achieve interesting effects, it is intended to be

used by scripts. in the image below, a Daz Script used a collider 256 times in a row.

In the future i may write a script that animates a dynamic dress.

Installation

the plugin, mcjCollider.dll can be found in the attachments at the bottom of this page

this file should be plced in your daz studio plugins folder

typically it's

C:\Program Files\DAZ 3D\DAZStudio3\plugins

there's also mcjColliderReadme.zip containing a copy of the document you are reading presently

you could unzip it in a folder like

C:/Program Files/DAZ 3D/DAZStudio3/docs

Usage

mcjCollider can be used on any solid object in the scene but not on objects that were converted to subD

select the objects that will be the target of the collider

example: we select the cylinder and the floor-cube ( use the CTRL key for multiple selections )

once properly installed you will find mcjCollider in the "Create" menu

now that the mcjCollider is created in the scene

it will remember the list of selected objects, so you

can deselect them if you want.

in the Scene tab, select the mcjCollider

position it so that it points toward the objects

go in the parameters tab and modify the "Ray length" property

tweaking this property activates the collider

within a fraction of a second or a few seconds

the collider should jump to the collision point with the solids

the collider will also be oriented as if it had bounced on the surface

Note for Daz Script Programmers:

the collider can be activated through a script

by calling the "activated" slot of the node

example

node = Scene.getPrimarySelection()
node.activated();

in the attachments below in the

i added a daz script named "jumperDS3"

you select 2 nodes in a scene

example, i select the mcjCollider and a ball

launch jumperDS3

select which node is the destination node

example: i chose mcjCollider as the destination

click on the OK button

and the ball will jump to the location of the collider

using this script and a Collider you could, for example, save some time at making a car follow an uneven road

for the more adventurous, here's the script i used to create the draping effect

this script is included in the attachments under the name bigpingpong.dsa

this script expects to find a 256-balls figure in the scene

you can get this figure in the attachments below under the name 256ballsfigure.zip

this should be unzipped in your daz content folder, typically

C:\Program Files\DAZ\Studio\content

once installed it will appear in your library in Content/figures/mcasual

place your collider at the proper angle to "throw the balls on the floor and cylinder

the wall of balls will be located at Z = -100

select the mcjCollider

launch the script

on my PC it takes only 1 second to make the millions of computations !

at frame 30 the script builds a wall of balls

and at frame 90 all the balls arrive at their collision point

// DAZ Studio version 3.0 filetype DAZ Script
node = Scene.getPrimarySelection();
z = -100
Scene.setFrame( 30 );
for( x = 0; x < 16; x++ )
for( y = 0; y < 16; y++ )
{
i = y * 16 + x;
ballnode = Scene.findNode( "ball" + i );
ballnode.setWSPos(
DzVec3(
( x / 16 ) * 200 - 100,
( y / 16 ) * 200,
z
)
);
}
Scene.setFrame( 90 );
basepos = node.getWSPos();
baserot = node.getWSRot();
for( x = 0; x < 16; x++ )
for( y = 0; y < 16; y++ )
{
i = y * 16 + x;
ballnode = Scene.findNode( "ball" + i );
pos = ballnode.getWSPos();
node.setWSPos( pos );
node.activated();
//processEvents();
pos = node.getWSPos()
ballnode.setWSPos( pos );
node.setWSPos( basepos );
node.setWSRot( baserot );
}

another test, done with the 4:25am version

node = Scene.getPrimarySelection();
ball = Scene.findNode( "ball" );
fr = 0;
pos = node.getWSPos();
for( i = 0; i < 30; i++ )
{
Scene.setFrame( fr );
ball.setWSPos( pos );
node.activated();
nupos = node.getWSPos();
dist = nupos.subtract( pos );
d = dist.length();
pos = nupos;
fr += d / 10;
}

the script is in the attachments as pingpong.dsa

the ball which must be in the scene is also in the attachments as ball.obj

the box was 4x4x4 meters

the box was selected upon creation of the mcjCollider

the ball was scaled 600%

FPS was set at 10

the mcjCollider must be selected when you launch the script

i used the free script setInterpolation

http://sites.google.com/site/mcasualsdazscripts/setinterpolation-for-ds2-3

to linearize the animation keyframes

without this the ball was moving along curves and it made no sense

New in October 2012's version

A parameter/channel named "report" was added to the mcjCollider node

its label displays the identity of the face that got the collision

for example:

if the collision occured on a figure bone, we would have something like

so, the first part of the label is the skeleton name, or "none" if it's not a bone

the second part is the bone or object name

the 3rd part is the type of face hit

    • 0 : Triangle
    • 1 : Quad
    • 2 : Polygon

the 4th part is the face number

here's script code that will create a Morph channel to move the collided face

it's a solution for poke-through fixing !

this script can be downloaded in the attachments section under the name

mcjLittleScriptToFixPokeThroughUsingMcjCollider.dsa

// DAZ Studio version 3.1 filetype DAZ Script

doit();

function doit()

{

var collider = Scene.findNodeByLabel( "mcjCollider" );

var str = collider.findProperty( "report" ).getLabel();

strs = str.split("\t");

if( strs.length < 4 )

{

return;

}

var skelname = strs[0];

var nodename = strs[1];

var facetype = Number( strs[2] );

var faceno = Number( strs[3] );

if( skelname != "none" )

{

skel = Scene.findNode( skelname );

node = skel.findBone( nodename );

}

else

{

node = Scene.findNode( nodename );

}

obj = node.getObject();

geom = obj.getCurrentShape().getGeometry();

var vertIndexes = new Array();

switch( facetype )

{

case 0:

var face = geom.getTri( faceno );

vertIndexes.push( face.edge1.vertIndex );

vertIndexes.push( face.edge2.vertIndex );

vertIndexes.push( face.edge3.vertIndex );

break;

case 1:

var face = geom.getQuad( faceno );

vertIndexes.push( face.edge1.vertIndex );

vertIndexes.push( face.edge2.vertIndex );

vertIndexes.push( face.edge3.vertIndex );

vertIndexes.push( face.edge4.vertIndex );

break;

case 2:

var face = geom.getPoly( faceno);

var n = face.edges.length;

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

{

vertIndexes.push( face.edges[i].vertIndex );

}

break;

}

makeMorph( obj, geom, faceno, vertIndexes )

}

function makeMorph( obj, geom, faceno, vertIndexes )

{

var morphDeltas = new DzMorphDeltas();

var n = vertIndexes.length;

var v1 = geom.getVertex( vertIndexes[0] );

var v2 = geom.getVertex( vertIndexes[1] );

var v3 = geom.getVertex( vertIndexes[2] );

v12 = v2.subtract( v1 );

v13 = v3.subtract( v1 );

v12.normalize();

v13.normalize();

var norm = v12.cross( v13 );

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

{

morphDeltas.addDelta( vertIndexes[i], norm.x, norm.y, norm.z );

}

var morphname = "face" + faceno;

var modifier = obj.findModifier( morphname );

if( !modifier )

{

modifier = new DzMorph( morphDeltas );

modifier.setLabel( morphname );

modifier.setName( morphname );

obj.addModifier( modifier );

}

else

{

modifier.setDeltas( morphDeltas );

modifier.getValueChannel().setHidden( false );

}

}