Example #1
0
bool VJSObject::CallAsConstructor (const std::vector<VJSValue> *inValues, VJSObject *outCreatedObject, JS4D::ExceptionRef *outException)
{
	xbox_assert(outCreatedObject != NULL);

	if (!JSObjectIsConstructor(GetContextRef(), GetObjectRef()))

		return false;

	uLONG		argumentCount	= inValues == NULL || inValues->empty() ? 0 : (uLONG) inValues->size();
	JSValueRef	*values			= argumentCount == 0 ? NULL : new JSValueRef[argumentCount];

	if (values != NULL) {

		std::vector<VJSValue>::const_iterator	i;
		uLONG									j;

		for (i = inValues->begin(), j = 0; i != inValues->end(); i++, j++)

			values[j] = i->GetValueRef();
		

	}

	JS4D::ExceptionRef	exception;
	JS4D::ObjectRef		createdObject;
	
	exception = NULL;
	createdObject = JSObjectCallAsConstructor(GetContextRef(), GetObjectRef(), argumentCount, values, &exception);
		
	if (values != NULL)

		delete[] values;

	if (outException != NULL)

		*outException = exception;

	outCreatedObject->SetContext(fContext);
	if (exception != NULL || createdObject == NULL) {
		
		outCreatedObject->SetUndefined();
		return false;

	} else {

		outCreatedObject->SetObjectRef(createdObject);
		return true;

	}
}
plComponentBase *plMaxNodeBase::ConvertToComponent()
{
    if (IsComponent())
        return (plComponentBase*)GetObjectRef();

    return nil;
}
//// FindSkinModifier ///////////////////////////////////////////////////////
//  Given an INode, gets the ISkin object of that node, or nil if there is
//  none. Taken from the Max4 SDK, ISkin.h
ISkin* plMaxNodeBase::FindSkinModifier()
{
    int modStackIndex;

    // Get object from node. Abort if no object.
    Object *pObj = GetObjectRef();
    if( pObj == nil )
        return nil;

    // Is derived object ?
    while( pObj->SuperClassID() == GEN_DERIVOB_CLASS_ID )
    {
        IDerivedObject *pDerObj = (IDerivedObject *)pObj;

        // Iterate over all entries of the modifier stack.
        for( modStackIndex = 0; modStackIndex < pDerObj->NumModifiers(); modStackIndex++ )
        {
            // Get current modifier.
            Modifier *mod = pDerObj->GetModifier( modStackIndex );

            // Is this Skin ?
            if( mod->ClassID() == SKIN_CLASSID )
            {
                ISkin* skin = (ISkin*)mod->GetInterface(I_SKIN);
                if( skin->GetNumBones() > 0 )
                    return skin;
            }
        }
        pObj = pDerObj->GetObjRef();
    }

    // Not found.
    return nil;
}
hsBool plMaxNodeBase::IsExternComponent(Object *obj)
{
    if (!obj)
        obj = GetObjectRef();

    if (obj && obj->CanConvertToType(EXT_COMPONENT_CLASSID))
        return true;

    return false;
}
bool plMaxNodeBase::IsXRef()
{
    // Is this an XRef'd object?
    Object *obj = GetObjectRef();
    if (obj->SuperClassID() == SYSTEM_CLASS_ID && obj->ClassID() == XREFOBJ_CLASS_ID)
        return true;

    //
    // Is this part of an XRef'd scene?
    //
    // Walk up to our root node
    INode *root = GetParentNode();
    while (!root->IsRootNode())
        root = root->GetParentNode();
    // If our root isn't the main root, we're in an XRef'd scene.
    if (root != GetCOREInterface()->GetRootNode())
        return true;

    return false;
}
void UK2Node_PlayMovieScene::CreatePinForBoundObject( FMovieSceneBoundObject& BoundObject )
{
	const UEdGraphSchema_K2* K2Schema = GetDefault<UEdGraphSchema_K2>();

	// We use the GUID as the pin name as this uniquely identifies it
	const FString PinName = BoundObject.GetPossessableGuid().ToString( EGuidFormats::DigitsWithHyphens );

	// For the friendly name, we use the possessable name from the MovieScene asset that is associated with this node
	FText PinFriendlyName = FText::FromString(PinName);
	{
		UMovieScene* MovieScene = GetMovieScene();
		if( MovieScene != NULL )		// @todo sequencer: Need to refresh the PinFriendlyName if the MovieScene asset changes, or if the possessable slot is renamed within Sequencer
		{
			for( auto PossessableIndex = 0; PossessableIndex < MovieScene->GetPossessableCount(); ++PossessableIndex )
			{
				auto& Possessable = MovieScene->GetPossessable( PossessableIndex );
				if( Possessable.GetGuid() == BoundObject.GetPossessableGuid() )
				{
					// Found a name for this possessable
					PinFriendlyName = FText::FromString(Possessable.GetName());
					break;
				}
			}
		}
	}

	const FString PinSubCategory(TEXT(""));
	UObject* PinSubCategoryObject = AActor::StaticClass();
	const bool bIsArray = false;
	const bool bIsReference = false;
	UEdGraphPin* NewPin = CreatePin( EGPD_Input, K2Schema->PC_Object, PinSubCategory, PinSubCategoryObject, bIsArray, bIsReference, PinName );
	check( NewPin != NULL );

	// Set the friendly name for this pin
	NewPin->PinFriendlyName = PinFriendlyName;

	// Place a literal for the bound object and hook it up to the pin
	// @todo sequencer: Should we instead set the default on the pin to the object instead?
	const TArray< UObject* >& Objects = BoundObject.GetObjects();
	if( Objects.Num() > 0 )
	{
		for( auto ObjectIter( Objects.CreateConstIterator() ); ObjectIter; ++ObjectIter )
		{
			auto* Object = *ObjectIter;
			if( ensure( Object != NULL ) )
			{
				// Check to see if we have a literal for this object already
				UK2Node_Literal* LiteralNode = NULL;
				{
					TArray< UK2Node_Literal* > LiteralNodes;
					GetGraph()->GetNodesOfClass( LiteralNodes );
					for( auto NodeIt( LiteralNodes.CreateConstIterator() ); NodeIt; ++NodeIt )
					{
						const auto CurLiteralNode = *NodeIt;

						if( CurLiteralNode->GetObjectRef() == Object )
						{
							// Found one!
							LiteralNode = CurLiteralNode;
							break;
						}
					}
				}

				if( LiteralNode == NULL )
				{
					// No literal for this object yet, so we'll make one now.
					UK2Node_Literal* LiteralNodeTemplate = NewObject<UK2Node_Literal>();
					LiteralNodeTemplate->SetObjectRef( Object );

					// Figure out a decent place to stick the node
					// @todo sequencer: The placement of these is really unacceptable.  We should setup new logic specific for moviescene pin objects.
					const FVector2D NewNodePos = GetGraph()->GetGoodPlaceForNewNode();
					LiteralNode = FEdGraphSchemaAction_K2NewNode::SpawnNodeFromTemplate<UK2Node_Literal>(GetGraph(), LiteralNodeTemplate, NewNodePos);
				}

				// Hook up the object reference literal to our pin
				LiteralNode->GetValuePin()->MakeLinkTo( NewPin );
			}
		}
	}
}