Notifications
Clear all

[Closed] weight maps?

Is it possible for a change handler to react to vertex color change?
I’d like to interactively paint properties of objects based on vertex colour of a plane below them, like radius of the spheres scattered on a grid.

I know about the particles and how to set it up with PFlow.

3 Replies
1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

*Create a Plane called Plane01 with lots of segments
*Create any number of spheres on top of it
*Add Vertex Paint to the Plane01
*Evaluate the following script:


unRegisterRedrawViewsCallback paintedFunction
fn paintedFunction =
(
	theMesh = snapshotAsMesh $Plane01
	for o in $Sphere* do
	(
		theInt = intersectRayEx $Plane01 (Ray o.pos [0,0,-1])
		if theInt != undefined then
		(
			theFace = getVCFace theMesh theInt[2]
			theVert1 = getVertColor theMesh theFace.x
			theVert2 = getVertColor theMesh theFace.y
			theVert3 = getVertColor theMesh theFace.z
			theColor = theVert1 * theInt[3].x + theVert2 * theInt[3].y + theVert3 * theInt[3].z 
			o.wirecolor = theColor
			o.radius = length (theColor as Point3) * 0.02
		)
	)	
	delete theMesh 
)
registerRedrawViewsCallback paintedFunction

Start painting on the Plane and the spheres will change their radius and wireframe color based on the underlying vertex color painted on the plane.

Note that this is pretty brute force approach (updating each time the viewport is updated), so if the scene is generally very slow, the script might not be very interactive.
In the typical case though (several hundred spheres, a plane with 20×20 segments and nothing else around), it should be really fast.
You could add a timestamp to measure the time since the last call and if the time since the last redraw is below a certain threshold, skip the update completely. You could also use a polled approach using a timer control which ticks every N milliseconds and keeps the spheres updated…

Thanks a lot!

It really is quite fast, even with a 50/50 plane and lots of spheres:)
Finally I’d like to write a tool that lets you pick source and target to paint object placement and other properties picked from a dropdown list.
But I have one question… is it possible to animate vertex colors?
I tried painting with VertexPaint mod over time with animate on but the result was not promising:)

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

It is technically possible by scripting the UVW_Unwrap modifier, but it is not a feature that is really exposed in the UI. So you can store animated vertex colors (or UVWs), but the UI is not really there so people can do it easily.