[Closed] setNumCPVVerts
I’m not sure that I get this fully or at all. I want to set vertex colors on an object so I gather I need to use setNumCPVVerts and then buildVCFaces, but buildVCFaces tells me “Runtime error: BuildVCFaces – mesh has no color-per-vertex vertices: TriMesh”
When I check GetNumCPVVerts[font=Garamond] [/font] it returns 0. I get what it is wanting but don’t understand just how to set it.
Any one have any ideas on this?
call “defaultVCFaces” first. it will create vertex color channel. after that you will be able to set the number of cpv verts.
Doesn’t work, how about a working example as what I have isn’t going any where and I have tried all sorts of things.
Here is what I just tried…
defaultVCFaces $.mesh
setNumCPVVerts $.mesh 100 true
buildVCFaces $.mesh true
You are trying to operate live on the $.mesh. I think what happens is $.mesh grabs the mesh from the object into a TriMesh value. Then you modify that in memory. Then you calll the next function and it grabs a NEW TriMesh (not the one already in memory you modified) and of course it was not changed yet, so you get an error and so on.
$.mesh makes sense if you are READING data from an object. It gives you the TOP OF THE STACK TriMesh representation of the object even if it is not an Editable Mesh.
As mentioned by others, these methods are designed to operate on Editable Meshes so you will have to collapse the stack and remove the .mesh from your code.
They CAN operate on a TriMesh, but then you wouldn’t be able to feed the changes back to your object unless it was an EdiableMesh to start with.
So if you do either myMesh = $.mesh or myMesh = snapshotAsMesh $ (this gives you world space state of the mesh), then the methods will operate on the TriMesh value correctly, but it would only make sense if you would assign that myMesh value back to some object, for example to a fresh EditableMesh’s .mesh property. Otherwise the changes will remain on the memory copy of the mesh and not appear in the scene which is of course not what your want…
those vertex color commands only works if the object is an Editable Mesh
convertto $ Editable_mesh
defaultVCFaces $.mesh
setNumCPVVerts $.mesh 100 true
buildVCFaces $.mesh true
Paul, here’s a section of a script I wrote that we use on a daily basis:
obj=$ -- added this here to make it obvious
-- Go to polygon mode and select all
subobjectLevel = 1
-- get numver of verts in the object
nv=0
nv= obj.numverts
-- since we don't know if the artist has used Epoly or Emesh, try both.
for i = 1 to nv do
(
try (polyop.setvertcolor $ 0 i (color 190 190 190)) catch ()
try (meshop.setvertcolor $ 0 i (color 190 190 190)) catch ()
)
I shouldn’t have mixed up $ and obj, but it works.
Hmm, what I have is a scripted plugin object and I don’t want to collapse it. I have been able to set the number of color verts to the same as the triMesh using defaultVCFaces on the triMesh that is being stored in a variable and it works. So the other functions don’t work the same way as this one? and I need to do it on the baseObject?