首先思路是分为客户端、服务器、中间件三大块。先从客户端传入json文件给包括mesh,灯光,模型的中间件,其中mesh和灯光可以用已有的API调用服务器的内容,然后调用模型中包含的json文件包括对应的ID号、三维信息,这些信息通过访问数据库中的vrscenes文件(或者max文件)来获取对应的其他参数,然后生成对应的场景文件;最后实现的效果大致如下:
一部分会在安装VRay的时候就有,其他一部分自己添加
def __init__(self, filename):
with open(filename) as f:
self.house = json.load(f)
def dumpMsg(renderer, message, level, instant):
if level == vray.LOGLEVEL_ERROR:
print("[ERROR]", message)
elif level == vray.LOGLEVEL_WARNING:
print("[Warning]", message)
elif level == vray.LOGLEVEL_INFO:
print("[info]", message)
renderer.setOnLogMessage(dumpMsg)
DEMO_house = json2vr.House("./json/name.json")
for i in range(len(walls)):
string1 = 'wall_' + str(i) + '_node'
string2 = 'mesh_' + str(i) + '_node'
mesh.append(renderer.classes.GeomStaticMesh(string2))
for i in range(len(wall["Vertices"])):
x = wall["Vertices"][i]["x"]
y = wall["Vertices"][i]["y"]
z = wall["Vertices"][i]["z"]
point = vray.Vector(x, y, z)
vertices_list.append(point)
def make_transform(rotX=0, rotY=0, rotZ=0, scale=1, offset=vray.Vector()):
mS = vray.Matrix(scale)
mX = vray.Matrix.makeRotationMatrixX(rotX)
mY = vray.Matrix.makeRotationMatrixY(rotY)
mZ = vray.Matrix.makeRotationMatrixZ(rotZ)
transform = vray.Transform(mS * mZ * mY * mX, offset)
return transform
light = renderer.classes.LightRectangle()
lightPos = vray.Vector(0, 0, 270)
light.transform = make_transform(0, 0, 0, 1, lightPos)
light.color = vray.Color(1, 1, 1)
light.u_size = 500
light.v_size = 500
light.intensity = 2
light.invisible = 0
第二个是使用全局灯光模式,具体的属性见上。
gi = renderer.classes.SettingsGI.getInstanceOrCreate()
gi.on = True
gi.primary_engine = 0
gi.secondary_engine = 3
newBRDF = renderer.classes.BRDFDiffuse()
newBRDF.color = vray.AColor(r, g, b, a)
newMaterial = renderer.classes.MtlSingleBRDF()
newMaterial.brdf = newBRDF
renderer.plugins[node].material = newMaterial
或者获取对性的贴图,在VRay里面使用贴图都需要借助bitmap来进行设置贴图属性之后赋给材质然后设置diffiuse和reflect两个必要的参数,加上一些可选的设置,包括反光度,透光度等等,
newBRDF = renderer.classes.BRDFDiffuse()
newBRDF.color = vray.AColor(r, g, b, a)
newMaterial = renderer.classes.MtlSingleBRDF()
newMaterial.brdf = newBRDF
renderer.plugins[node].material = newMaterial
renderer.load(filename)
del renderer.plugins['setting']
获取对应数据重新建立一个node将对应vrscene的position,mesh,贴图全部赋进去即可。VRay值支持读取一个vrscene后面的会覆盖前面的,所以官方采用不同的物体的vrscene放在一个统一的vrscene里一起导入即可,再删除原来初始化的node即可
table = renderer.classes.Node()
table.geometry = renderer.plugins[geometry]
os.chdir(path)
table.material = material1
table.transform = make_transform(rotX, rotY, rotZ, scale, offset)
renderer.startSync()
renderer.waitForRenderEnd(20000)
renderer.export("exportAll.vrsence")
image = renderer.getImage()
image.save("name.jpg")
*这里到导出设置上询问了官方,给出的解决方案是和unreal里导出属性相同的compressed和hexArrays属性。
RayExportSettings settings;
setting.compressed = false;
setting.hexArrays = false;
vrayRendrer.exportScene(''filename.vrscene'',settings);
最后生成全景图片效果: