Easy Vertex Manipulation Script

Hi,

Im trying to write a simple script which will allow for easy manipulation of vertexes. As anyone whos tried this out knows its not as simple as in the modelling engine where theres just one vertex at the end of each edge. From what i understand by asking loads of questions here, when a mesh is imported into the GE it is divided into seperate triangles, so for an ico sphere for example there are five vertices in one point in space due to five triangles vertices converging in the same point in space. So to move that apparently singular point you need to move five vertexes at once- otherwise things get messy…

So heres the script which i need some help with:


import GameLogic

cont = GameLogic.getCurrentController()

own = cont.getOwner()

scene = GameLogic.getCurrentScene()
grid = scene.getObjectList()["OBSphere"]
mesh = grid.getMesh(0)

if own.snap==0:
	n =0
	for v_index in range(mesh.getVertexArrayLength(0)):
		vertex = mesh.getVertex(0, v_index)
		v_xyz = vertex.getXYZ()
		if v_xyz in GameLogic.globallist == 0: ## coords not in global list
			GameLogic.globallist.append(v_xyz) ## puts those coords in global list
			GameLogic.list,n = [] ## creates a new list
			GameLogic.list,n.append(v_index) ## adds vertex index to new list
			n =+ 1
			print GameLogic.list1
			print GameLogic.globallist
		if v_xyz in GameLogic.globallist == 1: ## if coords are in the global list
			m = GameLogic.globallist.index(v_xyz) ## find how far along the global list those coords are
			GameLogic.list,m.append(v_index) ## appends the index to the list of indexes for that coord
	own.snap=1



You’ll have to copy and paste that, its a bit messy with notes too self :smiley:

The idea is that is runs through the vertex index’s XYZ cooords, if it is the first instance of those coords the coords are added to a global list and a seperate list is created in which the index number is stored.
If it is not the first instance of these coords the vertex index value is added to the list with other vertexes from the same coords.

Im not too good at explaining things at the best of times but that wasnt too good. I want to end up with a global list of coords and seperate lists of all the indexes at those coords. The lists kinda reference each other because all indexes in list0 have the same coords,[ which happen to be the 0 value of the global list]

One problem with the code is the list creation thing, i dont know how to substitue variables into declaring new lists.
I dont know what the others are yet. :smiley:

If someone could take a look id appreciate i think it could be a useful script for many people as it will make lists for any shape :smiley:

Thanks
Will

Да ПОСОСИ, ПИДОР ЕБАННЫЙ,ЗАСУНЬ СВОЮ ХУЕТУ СЕБЕ В…ПАДЛ

I must say that pyzdec is completely right!

pizdec:
=)))) Thumb up comrade .))))

За державу не обидно .)))

угу :slight_smile:

:slight_smile: =)
! ! !

You don’t wanna know what pizdec means in my language :o

Actually, it’s an indoeuropean word… so it can mean the same thing in many languages .) U’d better don’t find out what does it mean in mine .)))

ok so i dont know what pizdec means and im not too bothered,

after re-reading my post it doesnt make much sense but if anyone can tell me how to do the following then maybe i can figure this out. thanks.

How can i make a new list / dictionary / whatever, incorporating the variable into teh name i.e.

n=1

If var==1:
GameLogic.newlist"n" = []
n+1

so each time var==1 a new list is created with a different name to the last. the lists would be named GameLogic.newlist1, GameLogic.newlist2 e.t.c

thanks

setattr(GameLogic,“newlist”+str(n),[])

But a much better way would be to use a list of lists.

GameLogic.lists = []

#Creating the newlist
GameLogic.lists.append([])
GameLogic.lists[-1].append(vertex)

cheers saluk!

thanks for the first part, now i know how to do something else in python! i think i understand the second part but dont have my laptop in front of me at the moment, ill let you know how it goes though :smiley:

will

Hi,
This forum has been really helpful over the past few months, so i thought id try and give something back, i hope this script is useful to some people.

This script should allow easy vertex manipulation, ive only tested it on one mesh but it should logically work for any. Thanks to saluk for the help. Oh yeah and pizdec :wink:

Replace OBSphere with the object you want to mess with.
Change nx to change the “point” of the object you are moving.

The script creates a GameLogic.globallist with each “point’s” XYZ, it also creates a list of lists (GameLogic.list) with all the vertex indexes at any given point. The lists correspond to one another so GameLogic.list[0]'s indices all lie at GameLogic.globallist[0]'s xyz coords.

The variables arent particuarly explanatory!


import GameLogic

cont = GameLogic.getCurrentController()
own = cont.getOwner()

scene = GameLogic.getCurrentScene()
grid = scene.getObjectList()["OBSphere"]
mesh = grid.getMesh(0)

if own.snap==0:
	for v_index in range(mesh.getVertexArrayLength(0)):
		vertex = mesh.getVertex(0, v_index)
		v_xyz = vertex.getXYZ()
		yo = v_xyz in GameLogic.globallist
		if yo == False:		
			GameLogic.globallist.append(v_xyz) ## puts those coords in global list
			GameLogic.list.append([]) ## creates a new list in list
			GameLogic.list[-1].append(v_index) ## adds vertex index to new list						
		if yo == True: ## if coords are in the global list
			m = GameLogic.globallist.index(v_xyz) ## find how far along the global list those coords are
			GameLogic.list[m].append(v_index) ## appends the index to the list of indexes for that coord
	own.snap=1

######### this part is where you can move "points" around #######
if own.time>2:
	own.time=0.5
nx = 0 which vertex/coords/[point on sphere]
for v in GameLogic.list[nx]:
	v_h =mesh.getVertex(0,v)
	v_hxyz = v_h.getXYZ()
	v_h.setXYZ([GameLogic.globallist[nx][0]*own.time,GameLogic.globallist[nx][1]*own.time,GameLogic.globallist[nx][2]*own.time])


Merry Christmas :smiley: