thanks Luis ; i create this code to add infinite plane to maxwell scenes with default material ; it's not big thing but can help and maybe someone make the script better
Code: Select all################################################################
# add infinite plane to mxs file.
################################################################
from pymaxwell import *
import os
# plane size and name & input mxs name $ input, output scene folder
val = 500
planeName = 'Infinite Plane'
scene_name = 'new' #name of scene in input folder
inputFolder = 'c:/'+'intest' #change drive letter and folder name
outputFolder = 'c:/'+'outtest' #change drive letter and folder name
################################################################
def createInfinitePlane(outFolder,outMxs):
scene = Cmaxwell(mwcallback);
name = planeName;
nVertices = 4;
nNormals = 4;
nTriangles = 2;
nPositionsPerVertex = 1;
object = scene.createMesh(name,nVertices,nNormals,nTriangles,nPositionsPerVertex);
# Vertices
v1 = Cvector(-val,0,-val);
v2 = Cvector(-val,0,val);
v3 = Cvector(val,0,-val);
v4 = Cvector(val,0,val);
ok = object.setVertex(0,0,v1);
ok |= object.setVertex(1,0,v2);
ok |= object.setVertex(2,0,v3);
ok |= object.setVertex(3,0,v4);
# Normals
n1 = Cvector(0,10,0);
n2 = Cvector(0,10,0);
n3 = Cvector(0,10,0);
n4 = Cvector(0,10,0);
ok = object.setNormal(0,0,n1);
ok |= object.setNormal(1,0,n2);
ok |= object.setNormal(2,0,n3);
ok |= object.setNormal(3,0,n4);
# Triangles
# Triangle 0 using vertices and normals 0, 1 and 2
ok = object.setTriangle(0,0,1,2,0,1,2);
# Triangle 1 using vertices and normals 2, 1 and 3
ok |= object.setTriangle(1,2,1,3,2,1,3);
# Save scene
outPath = outFolder+'/'+outMxs
ok = scene.writeMXS(outPath);
#plane = Cmaxwell(mwcallback)
#ok2 = plane.readMXS(inMxs2)
if __name__ == "__main__":
outFolder = 'C:/tmp'
outMxs = 'tmp_infinite_plane.mxs'
createInfinitePlane(outFolder,outMxs);
################################################################
def add_inf_plane_to_scene(inMxs1,inMxs2,outFolder,outMxs,newM):
# Read MXSs
scene = Cmaxwell(mwcallback)
ok1 = scene.readMXS(inMxs1)
plane = Cmaxwell(mwcallback)
ok2 = plane.readMXS(inMxs2)
planeobject = plane.getObject(planeName);
scene.addObject(planeobject);
newMat = scene.createMaterial('default')
planeobject = scene.getObject(planeName)
planeobject.setMaterial(newMat)
if not newMat.read(newM):
print ('ERROR: cannot open newM')
# Save modified scene to a new MXS
outPath = outFolder+'/'+outMxs
ok = scene.writeMXS(outPath);
if __name__ == "__main__":
inMxs1 = inputFolder+'/'+scene_name+'.mxs'
inMxs2 = outFolder+'/'+outMxs
outFolder = outputFolder
outMxs = 'new'+'_'+scene_name+'.mxs'
newM = 'C:/Program Files/Next Limit/Maxwell Render 4/materials database/mxm files/default.mxm'
add_inf_plane_to_scene(inMxs1,inMxs2,outFolder,outMxs,newM)
################################################################