// RiExamplesPlugin.cpp : Implementation of CRiExamplesPlugin

#include "stdafx.h"
#include "RiExamplesPlugin.h"
#include "RpExamplesPlugin.h"
#include "RcHelloWorldCmd.h"
#include "RcParameterPassing.h"
#include "RcTopologyExample.h"
#include "RcMaterialModifyExample.h"
#include "RcPhysShotCmd.h"
#include "RcCameraTransformExample.h"

STDMETHODIMP CRiExamplesPlugin::get_Name(BSTR* pVal)
{
	CComBSTR szName = L"ExamplesPlugin";
	*pVal = szName.Detach();
	return S_OK;
};

STDMETHODIMP CRiExamplesPlugin::HelloWorld()
{
	//create hello world command
	CComPtr<IRsCommand> spCmd;
	HRESULT hr = CRpExamplesPlugin::CreateCommand(DEF_GUIDNAME_PTR(IRcHelloWorldCmd), &spCmd);
	if (FAILED(hr))
		return hr;

	//execute it
	return CRpExamplesPlugin::ExecuteCommand(spCmd);
}

STDMETHODIMP CRiExamplesPlugin::ParameterPassing(float fFlt, BSTR szStr)
{
	//create hello world command
	CComPtr<IRsCommand> spCmd;
	HRESULT hr = CRpExamplesPlugin::CreateCommand(DEF_GUIDNAME_PTR(IRcParameterPassing), &spCmd);
	if (FAILED(hr))
		return hr;

	//pass input parameter using command node connector
	CComQIPtr<IRsNode> spNode = spCmd;
	spNode->SetValue(CON_PP_FLOAT_PARAM, CComVariant(fFlt));
	spNode->SetValue(CON_PP_STRING_PARAM, CComVariant(szStr));

	//execute it
	return CRpExamplesPlugin::ExecuteCommand(spCmd);

};

STDMETHODIMP CRiExamplesPlugin::TopologyExample()
{
	//create hello world command
	CComPtr<IRsCommand> spCmd;
	HRESULT hr = CRpExamplesPlugin::CreateCommand(DEF_GUIDNAME_PTR(IRcTopologyExample), &spCmd);
	if (FAILED(hr))
		return hr;

	//execute it
	return CRpExamplesPlugin::ExecuteCommand(spCmd);
}

STDMETHODIMP CRiExamplesPlugin::MaterialModifyExample(BSTR szSelection)
{
	//create hello world command
	CComPtr<IRsCommand> spCmd;
	HRESULT hr = CRpExamplesPlugin::CreateCommand(DEF_GUIDNAME_PTR(IRcMaterialModifyExample), &spCmd);
	if (FAILED(hr))
		return hr;

	//pass input parameter using command node connector
	CComQIPtr<IRsNode> spNode = spCmd;
	spNode->SetValue(CON_MME_SELECTION, CComVariant(szSelection));

	//execute it
	return CRpExamplesPlugin::ExecuteCommand(spCmd);
}

STDMETHODIMP CRiExamplesPlugin::Shot(float fPower, VARIANT vPosition)
{
	//create shot command
	CComPtr<IRsCommand> spCmd;
	HRESULT hr = CRpExamplesPlugin::CreateCommand(DEF_GUIDNAME_PTR(IRcPhysShotCmd), &spCmd);
	if (FAILED(hr))
		return hr;

	//pass input parameter using command node connector
	CComQIPtr<IRsNode> spNode = spCmd;
	spNode->SetValue(CON_SHOT_POWER, CComVariant(fPower));
	spNode->SetValue(CON_SHOT_CENTER, vPosition);
	//execute it
	return CRpExamplesPlugin::ExecuteCommand(spCmd);
}

STDMETHODIMP CRiExamplesPlugin::CameraTransformExample()
{
	CComPtr<IRsCommand> spCmd;
	HRESULT hr = CRpExamplesPlugin::CreateCommand(DEF_GUIDNAME_PTR(IRcCameraTransformExample), &spCmd);
	if (FAILED(hr))
		return hr;

	return CRpExamplesPlugin::ExecuteCommand(spCmd);
}