[Closed] Billboarding for Viewport
What I’m after is some Maxscript which creates a billboarding effect toward the viewport for as many objects as I want. In other words, I want to create a script that mimics the ‘LookAt’ constraint but constrained to the viewport rather than a camera. Honestly I can’t believe there isn’t a plugin for this already – but I’ve not found it.
After searching for quite a while I came across this (posted below) which is a start but incomplete. Run the script yourself and you’ll understand why. For the overall goal the script must preserve the x, y, z coordinates of each object and face these objects toward the viewport ‘camera’ (me) in real time. The script must also be able to differentiate between different objects. That is, it cannot affect everything in the scene. How this differentiation is made is entirely up to you. I must also be able to save, exit, and reopen Max with this effect remaining intact.
As far as experience is concerned I’m entirely new and am essentially asking you to do this for me. Should you do so posting your script or uploading the Max file ought to suffice. The best case scenario is a Max file that allows me to copy a billboarding object (plane or text) and its billboarding effect from the main UI or one where I can simply copy paste the script into a transform controller (if that’s how you go about it).
Should anyone propose this, yes I can create this in the UDK. However, such a setup is far too slow for my purpose. The purpose of this script is to create what is essentially a realtime 3D flow chart using billboarding planes/text accompanied by non-billboarding splines used to connect them. Besides applications just as a flow chart, it serves as a means to test different setups for a 3D menu system rather than the typical and woefully cluttered 2D ones. Factoring in the ability to group, hide/show, and many other options available in Max, it is the ideal platform for this purpose. Regardless of the limited functionality of the UDK, just waiting for each package to update every time I make changes is worth avoiding its use. This also goes for Unity.
I do not expect any help so do as you will. Perhaps doing so offers you the opportunity to feel good or a feeling of having accomplished something. That’s all I can offer in gratitude. :shrug:
The script:
with redraw off
(
callbacks.removeScripts id:#camFace
delete objects
global cameraFaced
fn cameraFaced node: = if isvalidnode node do
(
ntm = node.transform
vtm = getViewTM()
node.transform = translate (rotate (scalematrix ntm.scale) (inverse vtm.rotation)) ntm.pos
)
global myText = text name:“myText” isselected:on
cameraFaced node:myText
callbacks.addScript #viewportChange “cameraFaced node:myText” id:#camFace
)
Select the objects you want to act as billboards and then run this:
callbacks.removeScripts id:#camFace
fn cameraFaced node = (
for i in node do (
ntm = i.transform
vtm = getViewTM()
i.transform = translate (rotate (scalematrix ntm.scale) (inverse vtm.rotation)) ntm.pos
)
)
global mySelObjects = (getCurrentSelection())
cameraFaced(mySelObjects)
callbacks.addScript #viewportChange "cameraFaced(mySelObjects)" id:#camFace
if you show anyone else code please point to the original source: http://forums.cgsociety.org/showpost.php?p=6577193&postcount=8
I appreciate your timely and effective response. For what it’s worth, well done sir. This meets all my needs and is therefore a perfect solution. One could not have done better.
Thank you.
I just took the code he posted and modified it for his purpose, had no idea the source…
sorry. my bad. i were not following whole discussion.
btw. we have to understand that showed solution doesn’t work for render. i remember that i’ve posted a solution where ‘billboard’ object’s transform was wired to a camera by using scripted transform controller
it has to work with render.
delete objects
bb = text name:"billboard" isselected:on
cam = targetcamera name:"camera" pos:[0,0,1000] dir:z_axis target:(targetobject pos:bb.center)
cam.target.pos = bb.center
sc = bb.rotation.controller = rotation_script()
sc.addnode "cam" cam
sc.setexpression "cam.transform.rotation"
viewport.setcamera cam
there is a flip issue. but there is another thread where this issue was solved