[Closed] Create VrayLight Mesh from source objects
Hello, I tried to make a script that creates a VRay Mesh Light in the place of the currently selected geometry that has the same functionality as the V-ray Mesh Light Button on the V-Ray Toolbar:
for obj in selection do
(
mesh_pos = obj.pivot
VRayLight type:3 pos:mesh_pos mesh_replaceOnPick:on mesh_source:obj
delete obj
)
However, the last line causes the mesh light’s source to be deleted as well.
If I click the V-ray Mesh Light Button, the original geometry gets deleted, but the Mesh Light’s Source remains intact. How should I modify my code so that the mesh source remains unchanged but I don’t have to keep any unnecessary geometry?
Can anybody help me with this question?
Of course, I could use the already ready button Vray Toolbar, but I need to use this as a function of the part of the script that does many other things.
Interesting… I was actually working on a script recently and learned a lot about the inner workings of a Vray Mesh light in order to be able to extract the mesh. When it’s contained in the light it’s a type of derived mesh object and the ‘mesh_shape’ property appears. When it’s picked as a reference instead you don’t get this property. There’s no way as far as I can see to get around this. I’ve logged it with Chaosgroup for you.
- Delete obj is superfluous because if replace is on, then your mesh would no longer exist in the scene:
Replace mesh with light If enabled when you pick the mesh, the mesh becomes a light source and the mesh object no longer
exists in the scene as a mesh object. When this option is disabled, a
copy of the picked mesh’s structure is created at the location of the
VRayLight icon, and this becomes the light source.
-
the culprit here is the mesh_source method. For this test, comment out your Delete (as explained above) so even tho your script
has assigned the obj to the Light, if you check the Pick mesh button on your light, even tho it contains the name of the object there, the
extract button is still greyed out…meaning it really HASN’T got the mesh yet…and if you’ve commented out the Delete, the object is still
there proving it hasn’t successfully stored the mesh yet since if it has, it would have got rid of it after…as per help text above. -
so I’m not a mxs expert but I reckon you’ll have to find another way to emulate the ‘pick’ mesh action…because if you test it by picking
it manually in the viewport…it works fine !!!
(I’ve tried assigning it with getnodebyname obj.name…but no cigar)
Noob out…
Just press toolbar button.
Button index may differ from vray version to version, but for mine 3.2 it’s 16
(
delete geometry
select (GeoSphere())
vrayToolbarHWND = (ch = windows.getChildHWND #max "V-Ray Toolbar"; if ch != undefined do ch[1])
vrayToolbarButtons = windows.getChildrenHWND vrayToolbarHWND
UIAccessor.PressButton vrayToolbarButtons[16][1]
)
@dZorg here is the solution from Chaosgroup. I knew there would be something with the baseObject to make it work.
fn createVRayMeshLight = (
local sel = (selection as array)
for nod in sel where not isDeleted nod do (
local vrLightNode = VRayLight type:3 mesh_replaceOnPick:on mesh_source:nod pivot:nod.pivot transform:nod.transform
vrLightNode.transform.controller = nod.transform.controller
refs.replaceReference vrLightNode.baseObject 2 nod.baseObject
)
for nod in sel do delete nod
)
createVRayMeshLight()