Пример #1
0
Value*
wm3_mc_settarget_cf(Value** arg_list, int count)
{
	check_arg_count(wm3_mc_settarget, 3, count);
	type_check(arg_list[0], MAXModifier, _T("WM3_MC_SetTarget [Morpher Modifier] [Channel Index] [Node]"));
	type_check(arg_list[1], Integer, _T("WM3_MC_SetTarget [Morpher Modifier] [Channel Index] [Node]"));
	type_check(arg_list[2], MAXNode, _T("WM3_MC_SetTarget [Morpher Modifier] [Channel Index] [Node]"));

	ReferenceTarget* obj = arg_list[0]->to_modifier();	
	if( !check_ValidMorpher(obj,arg_list) ) return &false_value;

	int sel = arg_list[1]->to_int(); sel -= 1;
	if(sel>=100) sel = 99;
	if(sel<0) sel = 0;

	MorphR3 *mp = (MorphR3*)arg_list[0]->to_modifier();

	INode *node = NULL;	
	node = arg_list[2]->to_node(); 
	if (node == NULL) return &false_value;

	MaxMorphModifier maxMorpher(mp);
	MaxMorphChannel maxMorphChannel = maxMorpher.GetMorphChannel(sel);
	if (NULL != maxMorphChannel.GetMorphTarget()) return &false_value;
	
	if (maxMorphChannel.SetMorphTarget(node, MAXScript_time()))
	{
		return &true_value;
	}
	return &false_value;
}
Пример #2
0
Value*
wm3_mc_getamount_cf(Value** arg_list, int count)
{
	check_arg_count(wm3_mc_getamount, 2, count);
	type_check(arg_list[0], MAXModifier, _T("WM3_MC_GetValue [Morpher Modifier] [Channel Index]"));
	type_check(arg_list[1], Integer, _T("WM3_MC_GetValue [Morpher Modifier] [Channel Index]"));

	ReferenceTarget* obj = arg_list[0]->to_modifier();	
	if( !check_ValidMorpher(obj,arg_list) ) return &false_value;

	int sel = arg_list[1]->to_int(); sel -= 1;
	if(sel>=100) sel = 99;
	if(sel<0) sel = 0;

	MorphR3 *mp = (MorphR3*)arg_list[0]->to_modifier();
	MaxMorphModifier maxMorpher(mp);
	// The value of the channel - ie, its weighted percentage
	float tmpVal = maxMorpher.GetMorphChannel(sel).GetMorphWeight(MAXScript_time());

	return Float::intern(tmpVal);
}
Пример #3
0
Value*
wm3_mc_setamount_cf(Value** arg_list, int count)
{
	check_arg_count(wm3_mc_setamount, 3, count);
	type_check(arg_list[0], MAXModifier, _T("WM3_MC_SetValue [Morpher Modifier] [Channel Index] [Value]"));
	type_check(arg_list[1], Integer, _T("WM3_MC_SetValue [Morpher Modifier] [Channel Index] [Value]"));
	type_check(arg_list[2], Float, _T("WM3_MC_SetValue [Morpher Modifier] [Channel Index] [Value]"));

	ReferenceTarget* obj = arg_list[0]->to_modifier();	
	if( !check_ValidMorpher(obj,arg_list) ) return &false_value;

	int sel = arg_list[1]->to_int(); sel -= 1;
	if(sel>=100) sel = 99;
	if(sel<0) sel = 0;

	MorphR3 *mp = (MorphR3*)arg_list[0]->to_modifier();
	MaxMorphModifier maxMorpher(mp);
	bool res = maxMorpher.GetMorphChannel(sel).SetMorphWeight(MAXScript_time(), arg_list[2]->to_float());
	needs_redraw_set();

	return (res ? &true_value : &false_value);
}
Пример #4
0
BOOL
TrackMouseCallBack::point_on_obj(ViewExp& vpt, IPoint2 m, Point3& pt, Point3 &norm)
{
	if ( ! vpt.IsAlive() )
	{
		// why are we here
		DbgAssert(!_T("Invalid viewport!"));
		return FALSE;
	}

	// computes the normal ray at the point of intersection
	Ray ray, world_ray;
	float at, best_dist = 0.0f;
	TimeValue t = MAXScript_time();	
	Object *obj = NULL;
	Matrix3 obtm, iobtm;
	Point3 testNorm;

	BOOL found_hit = FALSE;
	
	vl->face_num_val = vl->face_bary = &undefined;
	hit_node = NULL;

	// Calculate a ray from the mouse point
	vpt.MapScreenToWorldRay(float(m.x), float(m.y), world_ray);

	for( int i=(nodeTab.Count()-1); i>=0; i-- ) {
		// Get the object from the node
		INode* node = nodeTab[i];
		ObjectState os = node->EvalWorldState(t);
		obj = os.obj;	

		// Back transform the ray into object space.
		obtm	= node->GetObjectTM(t);
		iobtm	= Inverse(obtm);
		ray.p   = iobtm * world_ray.p;
		ray.dir = VectorTransform(iobtm, world_ray.dir);
		
		// See if we hit the object
		if (obj->IsSubClassOf(triObjectClassID))
		{
			TriObject*  tobj = (TriObject*)obj;
			DWORD		fi;
			Point3		bary;
			if (tobj->mesh.IntersectRay(ray, at, testNorm, fi, bary)  &&
			   ((!found_hit) || (at<=best_dist)) )
			{
				// Calculate the hit point and transform everything back into world space.
				// record the face index and bary coord
				best_dist = at;
				pt = ray.p + ray.dir * at;
				pt = pt * obtm;
				norm = Normalize(VectorTransform(obtm, testNorm));
				vl->face_num_val = Integer::intern(fi + 1);
				vl->face_bary = new Point3Value(bary);
				hit_node = node;
				found_hit = TRUE;
			}
		}
		else if (obj->IntersectRay(t, ray, at, testNorm)  &&
				((!found_hit) || (at<=best_dist)) )
		{
			// Calculate the hit point and transform everything back into world space.
			best_dist = at;
			pt = ray.p + ray.dir * at;
			pt = pt * obtm;
			norm = Normalize(VectorTransform(obtm, testNorm));
			hit_node = node;
			found_hit = TRUE;
		}
	}
	if( found_hit ) return TRUE;

	// Failed to find a hit on any node, look at the Normal Align Vector for the first node
	if ((obj!=NULL) && obj->NormalAlignVector(t, pt, testNorm)) // See if a default NA vector is provided
	{
		pt   = pt * obtm;
		norm = Normalize(VectorTransform(obtm, testNorm));
		return TRUE;
	}
	else
		return FALSE;
}