Notifications
Clear all

[Closed] UV Link

 MZ1

I’m looking for a way to link uv to another object, so we can move,rotate,scale it globally without any problem. this is my example that works:

delete objects
obj = circle material:(Standardmaterial diffuseMap:(checker()))
uvMd = Uvwmap()
ctrlObj = point size:150 wirecolor:green isselected:true centermarker:false axistripod:false cross:false box:true 
addModifier obj uvMd
transformScript = transform_script()
transformScript.addnode "ctrlObj" ctrlObj
transformScript.setexpression "ctrlObj.transform"
uvMd.Gizmo.controller = transformScript
-- rotate objects (EulerAngles 90 0 0)

But for some reason I need to rotate all objects so I can look them in front view (making some 2d stuff)
The problem is as soon as I rotate objects (uncomment last line), the UV transform in not correct. So my question is what transformation matrix I should apply so UV works correctly?

8 Replies

UVW Map is Object Space Modifier.
If you transform obj. with some other Object Space Modifier like XForm mod. under UVW Map on stack it will not affect Map gizmo (and you can simply instance (same) PRS Controller on UVW and “ctrlobj”)

Hope that answers transformation matrix question…

2 Replies
(@cgt139746852)
Joined: 10 months ago

Posts: 0

He means you need transform the world space transforms to UVW Map’s space transforms , other object space modifiers are same .
you should use matrix multiplication to transform , for this question , you can reference this
add the circle and change script

transformScript.addnode “oObj” obj
transformScript.setexpression ” a=oObj.transform * ctrlObj.transform * inverse oObj.transform”

as you rotate all object , so the planer of UVW map rotated twice , you need rotate back , change script

transformScript.setexpression “inverse ((EulerAngles 90 0 0) as matrix3) * oObj.transform * ctrlObj.transform * inverse oObj.transform”

 MZ1
(@mz1)
Joined: 10 months ago

Posts: 0

Great, thank you!

 MZ1

Sorry I don’t get your answer, would you please post working solution?

I’m sorry to say this, but it’s wrong. This does not take into account the possible object’s transform. I can give you the right answer or let you fix it yourself …

it’s a reference not a solution , you’r an excellent developer,why always poor performance
if you need need need to pin to the circle , use oObj.transform instead of ((EulerAngles 90 0 0) as matrix3)

fn bindMapGizmoToNode node modi target offsetTM: = 
(
	c = modi.Gizmo.controller = transform_script()
	c.addnode "node" node
	c.addobject "modi" (RefTargMonitor reftarg:modi)
	c.addnode "target" target
	
	c.addconstant "offsetTM" (if offsetTM == unsupplied then (Matrix3 1) else offsetTM as matrix3)  

	ss  = "nodeTM = node.objecttransform\n"
	ss += "modTM = getModContextTM node modi.reftarg\n"
	ss += "targetTM = target.objecttransform\n"
	ss += "offsetTM * targetTM * (inverse modTM) * (inverse nodeTM)"
	
	c.setexpression ss

	c
)	

delete objects
t = teapot radius:5 wirecolor:brown material:(Standard diffusemap:(Checker()) showinviewport:on)
addmodifier t (UVWMap())
p = point size:10 box:on axistripod:on cross:on wirecolor:green isselected:on

bindMapGizmoToNode t t.uvwmap p offsetTM:(angleaxis 180 z_axis)
	
 MZ1

Cool, I didn’t know “RefTargMonitor” usage!