Skip to content

Commit

Permalink
Merge pull request #7 from glm-nchaverou/up_createMaterials
Browse files Browse the repository at this point in the history
Create materials; use scene materials before .vrscene shaders; CMake file; create materials button; fixed cast warnings.
  • Loading branch information
vkoylazov committed Jan 5, 2016
2 parents c5f8bb6 + 3964014 commit d9c5674
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 44 deletions.
123 changes: 123 additions & 0 deletions CMakeLists.txt
@@ -0,0 +1,123 @@
cmake_minimum_required (VERSION 2.8.11)

############################################################
# BEGIN Declare various macros
############################################################
macro( list_files FOLDER_NAME FILE_EXTENSIONS )

set( SKIP_INCLUDE_DIR OFF )
if( ( ${ARGC} GREATER 2 ) AND ( NOT "${ARGV2}" STREQUAL "" ) )
set( DIRECTORY_REFERENCE "${ARGV2}/${FOLDER_NAME}" )
if( ( ${ARGC} GREATER 3 ) AND ( "${ARGV3}" STREQUAL "SKIP_INCLUDE_DIR" ) )
set( SKIP_INCLUDE_DIR ON )
endif()
else()
set( DIRECTORY_REFERENCE "${CMAKE_CURRENT_SOURCE_DIR}/${FOLDER_NAME}" )
endif()
if( EXISTS ${DIRECTORY_REFERENCE} )
if( NOT SKIP_INCLUDE_DIR )
include_directories( ${DIRECTORY_REFERENCE} )
endif()
if( "${FOLDER_NAME}" STREQUAL "." )
set( DIRECTORY_FILTER "Source Files" )
set( DIRECTORY_LABEL "ROOT" )
else()
set( DIRECTORY_FILTER "Source Files/${FOLDER_NAME}" )
string( REGEX REPLACE "/\\." "" DIRECTORY_FILTER ${DIRECTORY_FILTER} )
string( REGEX REPLACE "\\./" "" DIRECTORY_FILTER ${DIRECTORY_FILTER} )
string( REGEX REPLACE "/" "\\\\\\\\" DIRECTORY_FILTER ${DIRECTORY_FILTER} )
set( DIRECTORY_LABEL "${FOLDER_NAME}" )
string( REGEX REPLACE "/\\." "" DIRECTORY_LABEL ${DIRECTORY_LABEL} )
string( REGEX REPLACE "\\./" "" DIRECTORY_LABEL ${DIRECTORY_LABEL} )
string( REGEX REPLACE "/" "_" DIRECTORY_LABEL ${DIRECTORY_LABEL} )
string( TOUPPER "${DIRECTORY_LABEL}" DIRECTORY_LABEL )
endif()
foreach( file_ext ${FILE_EXTENSIONS} )
string( TOUPPER "${file_ext}" _FILE_EXT )
unset( LIST_FILES_${DIRECTORY_LABEL}_${_FILE_EXT} )
file( GLOB LIST_FILES_${DIRECTORY_LABEL}_${_FILE_EXT} ${DIRECTORY_REFERENCE}/*.${file_ext} )
list( APPEND LIST_FILES "${LIST_FILES_${DIRECTORY_LABEL}_${_FILE_EXT}}" )
list( APPEND LIST_FILES_${_FILE_EXT} "${LIST_FILES_${DIRECTORY_LABEL}_${_FILE_EXT}}" )
source_group( "${DIRECTORY_FILTER}" FILES ${LIST_FILES_${DIRECTORY_LABEL}_${_FILE_EXT}} )
# unset( LIST_FILES_${DIRECTORY_LABEL}_${_FILE_EXT} )
endforeach()
else()
endif()

endmacro()

############################################################
# END Declare various macros
############################################################


############################################################
# BEGIN Project
############################################################
project (vraygolaem)

# Add dependencies
set( 3DSMAXSDK_ROOTDIR "3dsMaxSDK Root Dir" CACHE PATH "3dsMaxSDK Root directory" )
set( 3DSMAXSDK_VERSION 2014 CACHE INT "3dsMaxSDK Version" )
set( VRAYFOR3DSMAX_ROOTDIR "VRay Root Dir" CACHE PATH "VRay Root directory" )

set( 3DSMAXSDK_INCDIR "${3DSMAXSDK_ROOTDIR}/include" )
set( 3DSMAXSDK_LIBDIR "${3DSMAXSDK_ROOTDIR}/lib/x64/Release" )
set( VRAYFOR3DSMAX_INCDIR "${VRAYFOR3DSMAX_ROOTDIR}/include" )
set( VRAYFOR3DSMAX_LIBDIR "${VRAYFOR3DSMAX_ROOTDIR}/lib/x64" )
if( 3DSMAXSDK_VERSION EQUAL 2014 )
set( VRAYFOR3DSMAX_LIBDIRVC "vc101")
else()
set( VRAYFOR3DSMAX_LIBDIRVC "vc11")
endif()

list(APPEND 3DSMAXSDK_LIBS "${3DSMAXSDK_LIBDIR}/assetmanagement.lib")
list(APPEND 3DSMAXSDK_LIBS "${3DSMAXSDK_LIBDIR}/bmm.lib")
list(APPEND 3DSMAXSDK_LIBS "${3DSMAXSDK_LIBDIR}/core.lib")
list(APPEND 3DSMAXSDK_LIBS "${3DSMAXSDK_LIBDIR}/maxutil.lib")
list(APPEND 3DSMAXSDK_LIBS "${3DSMAXSDK_LIBDIR}/geom.lib")
list(APPEND 3DSMAXSDK_LIBS "${3DSMAXSDK_LIBDIR}/gfx.lib")
list(APPEND 3DSMAXSDK_LIBS "${3DSMAXSDK_LIBDIR}/mesh.lib")
list(APPEND 3DSMAXSDK_LIBS "${3DSMAXSDK_LIBDIR}/maxscrpt.lib")
list(APPEND 3DSMAXSDK_LIBS "${3DSMAXSDK_LIBDIR}/manipsys.lib")
list(APPEND 3DSMAXSDK_LIBS "${3DSMAXSDK_LIBDIR}/paramblk2.lib")
list(APPEND 3DSMAXSDK_LIBS "${3DSMAXSDK_LIBDIR}/MNMath.lib")

list(APPEND VRAYFOR3DSMAX_LIBS "${VRAYFOR3DSMAX_LIBDIR}/vray${3DSMAXSDK_VERSION}.lib")
list(APPEND VRAYFOR3DSMAX_LIBS "${VRAYFOR3DSMAX_LIBDIR}/vrender${3DSMAXSDK_VERSION}.lib")
list(APPEND VRAYFOR3DSMAX_LIBS "${VRAYFOR3DSMAX_LIBDIR}/zlib_s.lib")
list(APPEND VRAYFOR3DSMAX_LIBS "${VRAYFOR3DSMAX_LIBDIR}/tiff_s.lib")
list(APPEND VRAYFOR3DSMAX_LIBS "${VRAYFOR3DSMAX_LIBDIR}/${VRAYFOR3DSMAX_LIBDIRVC}/plugman_s.lib")
list(APPEND VRAYFOR3DSMAX_LIBS "${VRAYFOR3DSMAX_LIBDIR}/${VRAYFOR3DSMAX_LIBDIRVC}/vutils_s.lib")
list(APPEND VRAYFOR3DSMAX_LIBS "${VRAYFOR3DSMAX_LIBDIR}/${VRAYFOR3DSMAX_LIBDIRVC}/meshes_s.lib")
list(APPEND VRAYFOR3DSMAX_LIBS "${VRAYFOR3DSMAX_LIBDIR}/${VRAYFOR3DSMAX_LIBDIRVC}/libmmd.lib")
list(APPEND VRAYFOR3DSMAX_LIBS "${VRAYFOR3DSMAX_LIBDIR}/${VRAYFOR3DSMAX_LIBDIRVC}/libirc.lib")
list(APPEND VRAYFOR3DSMAX_LIBS "${VRAYFOR3DSMAX_LIBDIR}/${VRAYFOR3DSMAX_LIBDIRVC}/svml_dispmd.lib")
list(APPEND VRAYFOR3DSMAX_LIBS "${VRAYFOR3DSMAX_LIBDIR}/${VRAYFOR3DSMAX_LIBDIRVC}/libdecimal.lib")

#MESSAGE(${3DSMAXSDK_INCDIR})

# List Files
list_files( "." "h;cpp;c;def;rc" )

# Create a library
set( VRAYGOLAEMLIB "vraygolaem${3DSMAXSDK_VERSION}" )
add_library( ${VRAYGOLAEMLIB} SHARED ${LIST_FILES} )

# Include
include_directories( ${3DSMAXSDK_INCDIR} )
include_directories( ${VRAYFOR3DSMAX_INCDIR} )

# Link
target_link_libraries( ${VRAYGOLAEMLIB} "comctl32.lib")
target_link_libraries( ${VRAYGOLAEMLIB} "${3DSMAXSDK_LIBS}" )
target_link_libraries( ${VRAYGOLAEMLIB} "${VRAYFOR3DSMAX_LIBS}" )

# todo extension dlo

# Flags
add_definitions(-DUNICODE -D_UNICODE)

############################################################
# END Project
############################################################
Binary file modified resource.h
Binary file not shown.
File renamed without changes.
93 changes: 51 additions & 42 deletions vraygolaem.cpp
Expand Up @@ -138,6 +138,15 @@ class VRayGolaemDlgProc: public ParamMap2UserDlgProc {

static VRayGolaemDlgProc vrayGolaemDlgProc;

// Find the node that references this Golaem object. If the Golaem object is instanced,
// it is not defined which node is returned.
INode *getNode(VRayGolaem *golaem) {
ULONG handle=0;
golaem->NotifyDependents(FOREVER, (PartID)&handle, REFMSG_GET_NODE_HANDLE);
INode *node=GetCOREInterface()->GetINodeByHandle(handle);
return node;
}

//************************************************************
// Parameter block
//************************************************************
Expand All @@ -160,10 +169,6 @@ static ParamBlockDesc2 param_blk(params, STR_DLGTITLE, 0, &vrayGolaemClassDesc,
p_assetTypeID, MaxSDK::AssetManagement::AssetType::kExternalLink,
#endif
PB_END,
pb_use_node_attributes, _T("use_node_attributes"), TYPE_BOOL, P_RESET_DEFAULT, 0,
p_default, TRUE,
p_ui, TYPE_SINGLECHEKBOX, ED_USERNODEATTRIBUTES,
PB_END,

// display attributes
pb_enable_display, _T("enable_display"), TYPE_BOOL, P_RESET_DEFAULT, 0,
Expand Down Expand Up @@ -233,6 +238,7 @@ static ParamBlockDesc2 param_blk(params, STR_DLGTITLE, 0, &vrayGolaemClassDesc,
PB_END,

// not used anymore but kept for retrocomp
pb_use_node_attributes, _T(""), TYPE_BOOL, 0, 0, PB_END,
pb_motion_blur_enable, _T(""), TYPE_BOOL, 0, 0, PB_END,
pb_motion_blur_start, _T(""), TYPE_FLOAT, 0, 0, PB_END,
pb_motion_blur_window_size, _T(""), TYPE_FLOAT, 0, 0, PB_END,
Expand Down Expand Up @@ -499,6 +505,22 @@ INT_PTR VRayGolaemDlgProc::DlgProc(TimeValue t, IParamMap2 *map, HWND hWnd, UINT
if (ctrlID==BN_SHADERSBROWSE && vrayGolaem) {
chooseFileName(pblock, pb_shaders_file, _T("Choose shaders .vrscene file"));
}
if (ctrlID==BN_MATERIALSCREATE && vrayGolaem) {
// call post creation python script
INode* node=getNode(vrayGolaem);
if (node == NULL)
{
CStr logMessage = CStr("VRayGolaem: This object is an 3ds Max instance and is not supported. Please create a copy.");
mprintf(logMessage.ToBSTR());
return FALSE;
}

GET_MBCS(node->GetName(), nodeName);
CStr sourceCmd = CStr("python.ExecuteFile \"vraygolaem.py\"");
ExecuteMAXScriptScript(sourceCmd.ToBSTR());
CStr callbackCmd = CStr("python.Execute \"glmVRayGolaemPostCreationCallback('") + CStr(nodeName) + CStr("')\"");
ExecuteMAXScriptScript(callbackCmd.ToBSTR());
}
}
break;
}
Expand Down Expand Up @@ -672,7 +694,7 @@ void VRayGolaem::drawEntities(GraphicsWindow *gw, const Matrix3& transform, Time
int maxDisplayedEntity = _simulationData[iData]->_entityCount * displayPercent / 100;
for (size_t iEntity=0, entityCount = maxDisplayedEntity; iEntity<entityCount; ++iEntity)
{
int entityId = _simulationData[iData]->_entityIds[iEntity];
int64_t entityId = _simulationData[iData]->_entityIds[iEntity];
if (entityId == -1) continue;

unsigned int entityType = _simulationData[iData]->_entityTypes[iEntity];
Expand Down Expand Up @@ -798,15 +820,6 @@ const tchar* getVRayPluginPath()
return s;
}

// Find the node that references this Golaem object. If the Golaem object is instanced,
// it is not defined which node is returned.
INode *getNode(VRayGolaem *golaem) {
ULONG handle=0;
golaem->NotifyDependents(FOREVER, (PartID)&handle, REFMSG_GET_NODE_HANDLE);
INode *node=GetCOREInterface()->GetINodeByHandle(handle);
return node;
}

//------------------------------------------------------------
// updateVRayParams
//------------------------------------------------------------
Expand Down Expand Up @@ -835,8 +848,7 @@ void VRayGolaem::updateVRayParams(TimeValue t)
GET_MBCS(shadersName_wstr, shadersName_mbcs);
_shadersFile=shadersName_mbcs;
}
_useNodeAttributes = pblock2->GetInt(pb_use_node_attributes, t) == 1;


// cache attributes
const TCHAR *crowdFields_wstr=pblock2->GetStr(pb_crowd_fields, t);
if (!crowdFields_wstr) _crowdFields="";
Expand Down Expand Up @@ -1023,41 +1035,41 @@ void VRayGolaem::renderBegin(TimeValue t, VR::VRayCore *_vray)

// Creates the crowd .vrscene file on the fly if required
VR::CharString vrSceneFileToLoad(_vrsceneFile);
if (_useNodeAttributes)
CStr outputDir(getenv (_tempVRSceneFileDir));
if (outputDir!=NULL)
{
CStr outputDir(getenv (_tempVRSceneFileDir));
if (outputDir!=NULL)
MaxSDK::Array<CStr> crowdFields;
splitStr(_crowdFields, ';', crowdFields);
if (outputDir.Length() != 0 && _cacheName.Length() != 0 && crowdFields.length() != 0)
{
MaxSDK::Array<CStr> crowdFields;
splitStr(_crowdFields, ';', crowdFields);
if (outputDir.Length() != 0 && _cacheName.Length() != 0 && crowdFields.length() != 0)
CStr outputPathStr(outputDir + "/" + _cacheName + "." + crowdFields[0] + ".vrscene");
VR::CharString vrSceneExportPath(outputPathStr); // TODO
if (!writeCrowdVRScene(vrSceneExportPath))
{
CStr outputPathStr(outputDir + "/" + _cacheName + "." + crowdFields[0] + ".vrscene");
VR::CharString vrSceneExportPath(outputPathStr); // TODO
if (!writeCrowdVRScene(vrSceneExportPath))
{
sdata.progress->warning("VRayGolaem: Error writing .vrscene file \"%s\"", vrSceneExportPath.ptr());
}
else
{
sdata.progress->info("VRayGolaem: Writing .vrscene file \"%s\"", vrSceneExportPath.ptr());
vrSceneFileToLoad = vrSceneExportPath;
}
sdata.progress->warning("VRayGolaem: Error writing .vrscene file \"%s\"", vrSceneExportPath.ptr());
}
else
else
{
sdata.progress->warning("VRayGolaem: Node attributes invalid (CrowdFields, Cache Name or Cache Dir is empty)");
sdata.progress->info("VRayGolaem: Writing .vrscene file \"%s\"", vrSceneExportPath.ptr());
vrSceneFileToLoad = vrSceneExportPath;
}
}
else
{
sdata.progress->warning("VRayGolaem: Error finding environment variable for .vrscene output \"%s\"", _tempVRSceneFileDir);
sdata.progress->warning("VRayGolaem: Node attributes invalid (CrowdFields, Cache Name or Cache Dir is empty)");
}
}
else
{
sdata.progress->warning("VRayGolaem: Error finding environment variable for .vrscene output \"%s\"", _tempVRSceneFileDir);
}

// Load the .vrscene into the plugin manager
_vrayScene=new VR::VRayScene(golaemPlugman);

// Create wrapper plugins for all 3ds Max materials in the scene, so that the Golaem plugin can use them, if needed
createMaterials(vray);

if (vrSceneFileToLoad.empty()) {
sdata.progress->warning("VRayGolaem: No .vrscene file specified");
} else {
Expand All @@ -1082,9 +1094,6 @@ void VRayGolaem::renderBegin(TimeValue t, VR::VRayCore *_vray)
}
}

// Create wrapper plugins for all 3ds Max materials in the scene, so that the Golaem plugin can use them, if needed
createMaterials(vray);

callRenderBegin(vray);
}

Expand Down Expand Up @@ -1640,7 +1649,7 @@ inline void drawSphere(GraphicsWindow *gw, const Point3 &pos, float radius, int
gw->startSegments();
for (int i=0; i<nsegs; i++)
{
float a=2.0f*pi*float(i+1)/float(nsegs);
float a=2.0f*(float)pi*float(i+1)/float(nsegs);
float u1=radius*cosf(a);
float v1=radius*sinf(a);

Expand Down Expand Up @@ -1686,12 +1695,12 @@ inline void drawText(GraphicsWindow *gw, const MCHAR* text, const Point3& pos)

inline Matrix3 golaemToMax()
{
return RotateXMatrix(pi/2);
return RotateXMatrix((float)pi/2);
}

inline Matrix3 maxToGolaem()
{
return RotateXMatrix(-pi/2);
return RotateXMatrix(-(float)pi/2);
}

// V-Ray materials expect rc.rayresult.sd to derive from VR::ShadeData, but this is not true for
Expand Down
3 changes: 1 addition & 2 deletions vraygolaem.h
Expand Up @@ -44,7 +44,7 @@
enum {
pb_file,
pb_shaders_file,
pb_use_node_attributes,
pb_use_node_attributes, // Not used anymore but kept for retrocomp
// display
pb_enable_display,
pb_display_percent,
Expand Down Expand Up @@ -164,7 +164,6 @@ class VRayGolaem: public GeomObject, public VR::VRenderObject, public VR::VRayPl
VR::VRayScene *_vrayScene; //!< The loaded .vrscene file
VR::CharString _vrsceneFile; //!<
VR::CharString _shadersFile; //!<
bool _useNodeAttributes; // if true, uses the attributes below to generate the vrscene, else use the loaded vrscene

// Cache attributes
CStr _crowdFields;
Expand Down
29 changes: 29 additions & 0 deletions vraygolaem.py
@@ -0,0 +1,29 @@
# /***************************************************************************
# * *
# * Copyright (C) Golaem S.A. - All Rights Reserved. *
# * *
# ***************************************************************************/

import MaxPlus

# Function called when a VRayGolaem node is created
def glmVRayGolaemPostCreationCallback(proxyName):
# get node
node = MaxPlus.INode.GetINodeByName(proxyName)
defaultMatName = node.BaseObject.ParameterBlock.default_material.GetValue()
if not defaultMatName:
defaultMatName = "crowdProxyDefaultShader"

# create VRayMtl (used as default)
mat = MaxPlus.Factory.CreateMaterial(MaxPlus.Class_ID(0x37bf3f2f, 0x7034695c))
mat.Diffuse = MaxPlus.Color(1, 0.47, 0)
mat.SetName(MaxPlus.WStr(defaultMatName + "@"))

# create multi material
mmat = MaxPlus.Factory.CreateDefaultMultiMtl()
mmat.SetName(MaxPlus.WStr(proxyName + "Mtl"))
mmat.SetSubMtl(0, mat)

# apply multi material to node
node.Material = mmat
print ("VRayGolaem: " + proxyName + "Mtl MultiMaterial has been successfully assigned to " + proxyName )
Binary file modified vraygolaem.rc
Binary file not shown.

0 comments on commit d9c5674

Please sign in to comment.