how to find the first and last vertices of a mesh?

im new to the mesh api and am trying to find out how to identify the first and last vertex manually or through python so i can mark them so when i search through a large mesh of combined sub mesh’s to find marked vertices with a Certain color. on a cube for example u got the 8 verts. should i just read in the mesh to a list and print out the list and look at the first and last? will that stay true after the mesh is combined of with the order change after?

I can do a face, but not a verticy,

When a face is struck with rayCast() it can return a material, I use this in my logic cubes as addresses,

but you can’t assign a material to only 1 vert…

You can get individual vertices from a mesh like so:

import bge

# get the object's mesh
cont = bge.logic.getCurrentController()
obj = cont.owner
mesh = obj.meshes[0]

# get the first vertex
firstVert = mesh.getVertex(0, 0)

# get the last vertex
lastIndex = mesh.getVertexArrayLength(0) - 1
lastVert = mesh.getVertex(0, lastIndex)

First and last are very relative descriptions. What is the relation you are referring to?

in other words:
What do you mean with first vertex and last vertex?

I’m looking to make a minecraft type game. Basically I want to have a cube and set the first vert and last vert to a color. duplicate the cube a bunch of times. Then combined them into one big mesh Then use a ray to get the hit face I want(should be able to use the face to get the vert attached to it). Then seach the mesh for the hit vert using some sort of loop to get all the verts between my marked verts. After that ill move the verts to like -10000 or something like that giving the impression the it has been removed. Then recalculate physicsmes. Uggg that was hard to type on my phone lol. Do u get what I’m trying to do now?

What monster is getting at is that we don’t have a definition of first and last. Are you sorting by distance to the camera, height, random number?

Sent from my Nexus 7 using Tapatalk 4

I guess just use a for loop with getVertex I dont know of an other way to sort them lol

So did you mean you wanted to get the first through the last vertices in the mesh? I.e. All of them?

Yep. like in edit mode when u mouse over a vert and hit L and all the linked varts are selected. That kind of what I am trying to emulate

To answer your question on how to mark them:
If they are individual cubes but parented together or something you could change the object color to mark it.
How that works:

object = ray.hitObject # the object you want to mark
object.color = [1.0, 0.0, 0.0, 1.0] # object color will be red (RGBA)

Or if you want you can colorize all vertices, you have to iterate through all like so (mofified script from Mobious):

import bge

# get the object's mesh
cont = bge.logic.getCurrentController()
obj = cont.owner
mesh = obj.meshes[0]

# colorize all vertices
for m_index in range(len(mesh.materials)):
      for v_index in range(mesh.getVertexArrayLength(m_index)):
         vertex = mesh.getVertex(m_index, v_index)
         vertex.color = [1.0, 0.0, 0.0, 1.0]

If you want to join various meshes in the BGE, I have to tell you that is not possible, but it woks if they are individual objects.

This topic gets discussed from time to time. Please do a search in this forum. You will find very interesting threads regarding this topic. The describe the problems with this type of game and offer some solutions.

This is not possible, as the bge does not generate meshes.

this is a blend i got from torakunsama its Similar to what i want to do but i would like to do it with any shape not just cubes. so i could have a desk with a bunch of items on it and i just pick off the microscope or what ever i wanted. but the desk and items are one mesh. so marking the first and last vert of the microscope in the mesh is the only way i can think of to get all the in between verts so i can move the microscope.