Notifications
Clear all

[Closed] getting newly added vertex

Hello.
I am tessellating a number of triangular polygon like so:

	for i in 1 to nfaces do
	(
		myObj.tesselateBy = 1
		myObj.EditablePoly.tessellate i
	)

Then I would like to have access to the new vertex just created, and move it along the normal of the initial polygon. How can I access that vertex?
Thank you

18 Replies

So, it looks line the 4 new vertices are added in the end of the vertex numbering, with the center vertex last. So I try the following:

nfaces = myObj.numfaces
 	for i in 1 to nfaces do
 	(
 		theNormal = polyop.getFaceNormal myObj i
 		myObj.tesselateBy = 1
 		myObj.EditablePoly.tessellate i
 		newnVerts = myObj.numverts
 		polyop.moveVert myObj newnVerts theNormal
 	)

which I think should move the last vertex. But it looks that somehow the vertex count is not updated until the end of the loop, so I still get the old number of vertices (before the tessellation). Running this line by line on one polygon works, but not inside the loop. Any ideas? Thanks.

newly added vertices after tessellation are

#{numverts_before_tessellation+1..numverts_after}

If you have a list of faces to tessellate, and do them one by one (as in your code), the original indices might be messed up.

Instead you could do it in a reversed loop or you could also tessellate all of the faces at once using polyop.tessellateByFace() function.

Additionally, you could store the original faces normals to use them later as offset value to move the vertices.

This is one way you can do it, but there are many different approaches:

(
 	-- Create a test object
 	gc()
 	delete objects
 	obj = converttopoly (box lengthsegs:1 widthsegs:1 heightsegs:1)
 	polyop.meshsmoothbyface obj #all
 	
 	-- Store all the faces normals
 	normals = for j = 1 to obj.numfaces collect polyop.getfacenormal obj j
 	
 	-- Store the numvert of vertices before tessellation
 	numverts = obj.numverts
 	
 	-- Tessellate all the faces
 	obj.tesselateby = 1
 	 for i = obj.numfaces to 1 by -1 do obj.editablepoly.tessellate i
 --	or
 	--polyop.tessellatebyface obj #all
 -- 	or
 	--polyop.tessellatebyface obj #{1..obj.numfaces}
 
 	-- Move all the new vertices based on their original face normal
 	offset = 10
 	for j = numverts+1 to obj.numverts do polyop.movevert obj j (normals[j-numverts]*offset)
 )

Thank you for the answers guys. I am afraid that I gave up with the tessellate options, it is a mesh trying to figure out the renumbering. It seems like <Poly>.EditablePoly.tessellate faceIndex is actually tessellating all the faces no matter the value provide as faceIndex. In the small script I posted above all the faces are tessellated the same way if I run it for all the faces or if I run it for some of them. polyop.tessellateByFace works better, but then the numbering of the faces is changing in every run of the loop. For example I tessellate face #1 in the first iteration of the loop: that face is gone and the new faces created are added in the end of the array. So what was face #2 becomes face #1 in the second iteration. This way I can tessellate face #1 in each iteration, but that gives the desired results only for .tessellateby = 1.
So I ended up following a different approach: I create a new empty poly object, create vertices at the same place of the vertices of the original object and then iteratively create the vertices that would result from the tessellation. Then I create the faces. This way I can always have access to the original structure of the object. That is a lot more work, but I think that it will give me more control over the process in the long run…

The code above (#4) has an error, it should be ‘obj.editablepoly.tessellate #Face’ instead of ‘obj.editablepoly.tessellate I’, and you would need to select the face/s before in order to make it work just on those faces.

Here is a fixed version using editablepoly.tessellate(), hope it works.

(
 	gc()
 	delete objects
 	obj = converttopoly (box lengthsegs:1 widthsegs:1 heightsegs:1)
 	polyop.meshsmoothbyface obj #all
 
 	offset = 10
 	
 	obj.tesselateby = 1
 	for j = obj.numfaces to 1 by -1 do
 	(
 		normal = polyop.getfacenormal obj j
 		obj.selectedfaces = #{j}
 		obj.editablepoly.tessellate #face
 		polyop.movevert obj obj.numverts (normal*offset)
 	)
 )

I am trying to figure out what the purpose of your script would be. Would you mind to explain what you want to achieve?

(
 	gc()
 	delete objects
 	obj = converttopoly (geosphere segments:20 smooth:off)
 
 	offset = 10
 	oldnum = obj.numverts

	obj.tesselateBy = 1 
 	norms = for f=1 to obj.numfaces collect (polyop.getfacenormal obj f)*(random 0 offset)
	polyop.tessellateByFace obj #all
	polyop.movevert obj #{oldnum+1..obj.numverts} norms
 )

but it’s interesting to know what it is for …

Yes, I am curious too

(
 	gc()
 	delete objects
 	obj = converttopoly (geosphere segments:2 smooth:off) 
 	offset = 10
 	numverts = obj.numverts
 	numfaces = obj.numfaces

	obj.tesselateBy = 0
 	norms = for f=1 to obj.numfaces collect (polyop.getfacenormal obj f) * offset
	polyop.tessellateByFace obj #all
	obj.selectedverts = #{obj.numverts-numfaces+1..obj.numverts}
	polyop.movevert obj #selection norms
	for v in #{1..numverts} do
	(
		d = normalize (polyop.getvert obj v - obj.center) * offset * 2
		polyop.movevert obj v -d
	)
 )

let’s make anything cool even if senseless

Page 1 / 2