PDA

View Full Version : get alpha value at specified vertex


AroundTheFur
10-25-2006, 05:58 PM
hey guys

so i can't figure out how to return the alpha value at vertex X, on a mesh with a map in its opacity slot. i'm sure this is very easy to do but digging endlessly through the reference hasn't turned up anything.

thanks
-s

AroundTheFur
10-25-2006, 09:46 PM
i did figure it out, and for those wondering it went something like this for the Particle Birth Script:


on ChannelsUsed pCont do

(

pCont.useTime = true --enable the Time channel

pCont.useAge = true --enable the Age channel

pCont.usePosition = true --enable the Position channel

pCont.useSpeed = true --enable the Speed channel

pCont.useScale = true --enable the scale

)

on Proceed pCont do

(

if (sliderTime == 0) do

(

--Our object to be used

targetOb = $Object01

for i in 1 to targetOb.verts.count do

(

--Get the vertex uv space coordinates

vCoord = meshop.getMapVert targetOb 1 i

--Find the relational pixel value in the bitmap

realVCx = vCoord.x * targetOb.material.opacitymap.bitmap.width

--We need to flip the Y here because my object's vert # start at the bottom left

realVCy = abs((vCoord.y * targetOb.material.opacitymap.bitmap.height) - targetOb .material.opacitymap.bitmap.height)

--Finally, get the pixel value of the relative vertex location

bValue = getPixels targetOb.material.opacitymap.bitmap [realVCx,realVCy] 1

--Use the bitmap in the bump slot for our scale value (you could just put it wherever)

sValue = getPixels targetOb.material.bumpmap.bitmap [realVCx,realVCy] 1

--If the alpha value here is greater than 0

if(bValue[1].value > 0) do

(

--Create a particle

pCont.AddParticle()

--get the index of the last particle that was added

pCont.particleIndex = pCont.NumParticles()

--Set the age of the particle to 0 – newborn!

pCont.particleAge = 0

--Set the particle position using the above variables

pCont.particlePosition = targetOb.verts[i].pos

--Set the particle scale

pCont.particleScale = abs((sValue[1].value/255)-1)*3.3

)

)

)

)

on Release pCont do

(


)


this script will create particles on an object ($Object01) at vertices where the material's alpha is greater than 1, so its basically on or off. Also if you put a material in the bump slot (i just stuck it there because i dont care about it) it will set scale according to the value of that (dark is bigger).

I modified one of the reference scripts for this, with some obvious hacks. I couldnt get the alpha value out of a bitmap so i had to generate a seperate alpha (b&w) map. If anyone wants to clean this up and make it work more efficiently (instead of having to use seperate alpha maps and using the slots in the material editor), please feel free!

CGTalk Moderation
10-25-2006, 09:46 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.