Announcement

Collapse
No announcement yet.

Rectangle/disc light preview texmap

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    rajdarge,

    It's certainly a good idea to avoid scaling if one is not sure what the collateral effects might be. But if you know, you can take that to your advantage. I've used scale and negative scaling on rigs on purpose, for instance. In this very case the scaling itself is not a problem at all, unless you plan to do more than previewing the light texture with the plane. I did this because the texture in VrayLight and the plane are flipped in the X axis, i.e. a gradient shows up reversed. In case of just matching the transform as you did, you need to flip the mesh or UVs for the texture of the plane to match. Just as a tip, for simple controller setups, you can fix any scale issue (not axis skewing though) by simply applying it to the gizmo of an XForm modifier, like this: $.xform.gizmo.scale = $.scale.controller.value, and reset the object level scale with "$.scale.controller.value = [1,1,1].".

    Also, scaling allowed me to instance the width and length of the plane with light sizes. This is not script/expression or wire controllers. IMO controller instancing is the best way to bind parameters because they are always bidirectional (like 2 way wires), produce no circular dependency (i.e you can instance the whole transform controller of a hierarchy of bones), they throw no error like script/expression controller if light is deleted, or lock parameters in the case of wire, and are faster to evaluate than any those. So it's very safe/useful to use.

    I didn't bother doing it for Disc Lights because I rarely use them, but I guess I'd do it the way you said, with a Circle and a UVW Map on top.

    Regards,

    -Eugenio

    Comment


    • #17
      Ok taking those things on board I then modified the script as follows:
      Code:
      (    objs = if selection.count == 0 then lights else selection as array
          
          name = "LightTex"
          
          for l in objs where isKindof l VrayLight and (l.type == 0 or l.type == 4) and l.texmap != undefined do
          (
      		l.size0.controller = Bezier_Float() 
      
      		planeName = (l.name + "_" + name)
      		if isValidNode (p=(getNodeByName planeName)) do delete p        
              mat = standardMaterial name:(name + "_" + l.name) diffuseMap:l.texmap opacityMap:l.texmap\
      			selfIllumAmount:100 showInViewport:true
              if l.type == 4 then 
      		(
      			p  = Circle radius:1
      			p.radius.controller = l.size0.controller
      			UVmapMod = Uvwmap()
      			floatExpC_1 = Float_Expression name:"radius"
      			floatExpC_1.AddScalarTarget  "W"  l.size0.controller
      			floatExpC_1.SetExpression  "W*2" -- muliply by 2
      			UVmapMod.length.controller = floatExpC_1
      			UVmapMod.width.controller = floatExpC_1
      			addmodifier p UVmapMod
      			p. transform = (scaleMatrix [-1,1,1] * l.transform)
      		)
      		else
      		(
      			
      			p = plane  lengthsegs:1 widthsegs:1 wireColor:(if l.texmap_on then color 180 255 50 else color 230 120 0) name:planeName
      			p.width.controller = l.size0.controller
      			p.length.controller = l.size1.controller = Bezier_Float()
      			p. transform = (scaleMatrix [-2,2,2] * l.transform)
      		)
      		p.wireColor = (if l.texmap_on then color 180 255 50 else color 230 120 0)
      		p.name = planeName  
      		p.parent = l  
      		 -- take out the negative scaling. 
      		p.renderable = false
      		p.isFrozen = true
      		p.showFrozenInGray = false 
              p.material = mat
          )
      )
      the UV Map has to be multiplied. You could apply a scalematrix to the gizmo, but I've forgotten what a subanim is so I couldn't work out how to do it.
      I use disc lights all the time as they are pretty close to a beauty dish which I was using extensively over the last 4 years. As I've been using symmetrical texture maps I didn't even notice the flip, so here is a directional texture to test it all out.
      Click image for larger version

Name:	UVFlipTex.png
Views:	1
Size:	61.6 KB
ID:	863370
      Its all been a gentle re-introduction to maxscript which has allowed my to decipher stuff I wrote all that time ago.
      The docs are almost as opaque as reading Bjarne Stroustrup, but making them online was a great step.
      I still haven't been able to crack the SDK to produce working code. But a lot of max is a bit of a mystery still, especially particle flow, and I miss reactor... feel free dear reader(s) to polish the code and make it tighter. And to the dev team - the part of the code that is mine is public domain as far as I am concerned. Though the heart of the code belongs to Midiaeffects
      There is one more question I have about negative scaling. What happens when the scene file is saved and then loaded again, perhaps by another member of your team?
      isnt there a potential time bomb sitting in the scene?
      Last edited by rajdarge; 03-09-2016, 03:45 PM.

      Comment


      • #18
        Well, I'm not a maxscripter myself really. But I know my bits and it helps me so much.

        Regarding scale, there's nothing inherently problematic on it that breaks a scene as a potential cause of a bug. What happens is that object level scale messes up the transform matrix and therefore any tool that access the object transform will misbehave. So to predict where problems might arise you better have a pretty good grasp of how the feature works. But as I said, the preview objects in this case have no reason to cause problems unless you foresee others using them for something else, like start linking things on them or applying modifiers (which also should work for the most part).

        Anyway, I changed your code a bit, replacing UVWMap with Extrude, since it generates mapping coordinates and scale them properly, without the need for expressions and whatnot. Also, just in case I removed the object level scale and applied it to an XForm. So, no scale problems anymore .

        -Eugenio

        Code:
        (       
            objs = if selection.count == 0 then lights else selection as array
            
            name = "LightTex"
            
            for l in objs where isKindof l VrayLight and (l.type == 0 or l.type == 4) and l.texmap != undefined do
            (
                l.size0.controller = Bezier_Float() 
                
                shapeName = (l.name + "_" + name)
                if isValidNode (p=(getNodeByName shapeName)) do delete p 
                
                mat = standardMaterial \
                name:(name + "_" + l.name) \
                diffuseMap:l.texmap \
                opacityMap:l.texmap \
                selfIllumAmount:100 \
                showInViewport:true
                
                if l.type == 4 then --Disc
                (
                    p  = Circle()
                    p.radius.controller = l.size0.controller
                    addmodifier p (Extrude amount:0 startCap:off mapCoords:on)
                    sm = scaleMatrix [-1,1,1]
                )
                else --Plane
                (
                    p = plane  lengthsegs:1 widthsegs:1 wireColor:(if l.texmap_on then color 180 255 50 else color 230 120 0) name:shapeName
                    p.width.controller = l.size0.controller
                    p.length.controller = l.size1.controller = Bezier_Float()
                    sm = scaleMatrix [-2,2,2]
                )
                
                addModifier p (Xform gizmo:sm)
                p.transform = l.transform
                p.wireColor = (if l.texmap_on then color 180 255 50 else color 230 120 0)
                p.name = shapeName
                p.parent = l  
                p.renderable = false
                p.isFrozen = true
                p.showFrozenInGray = false 
                p.material = mat
            )
        )

        Comment

        Working...
        X