Where can I learn about polydata and polymat?

I have been searching for a good tutorial on polydata,

does anyone know of any?

You should probably stick to a single thread, as “polydata” and “polymat” aren’t Python data types - they’re variable names in the script in the blend file in the other thread you made. I posted an answer there.

I see, I thought that they were part of bullet or the physics call func’s

You’re not going to find a tut on things this advanced. By the time you’re dealing with polydata, it is assumed you can read and understand the API.
But, if you want more help, you’ll have to be a bit more specific.

I’m assuming you have already got the polyProxy from somewhere (raycast etc).
What can you do with it?
Well, you can get it’s verticies with:

polyData.v1
polyData.v2
polyData.v3
polyData.v4

You can toggle the face visibility:

polyData.visible == False

You can get the faces material:

polyData.getMaterial()

And so on. As I said, look at the API

I have, the issue I have currently, is that I am not sure what is broke, so I don’t know what to fix…

the list/property stuff I can do

my issue is that I don’t know why, if you look at the .blend and my other thread, is that only some of the faces work…

Help? try the .blend in the link?, rotate any cube 90 degrees…

/uploads/default/original/3X/8/2/822a6dfe3be434bd05b935b396cbb8d114455377.blendd=1362290824

@ this point I understand what Raco has coded, but what I don’t understand is why the “pairing” is applying to the “struck” face,

I need

Cube A: Cast Ray from any face , Hit any face, once hit look up material get face ID number
then change hostID to Id number

I have

Cube A: Cast Ray from any face , Hit any face, once hit look up material get face ID number then if it is my own number change hostID to Id number

*I think

I am not sure

polyData.getMaterial() is what Raco uses, to look up material name,
and then use the end of the material “Sensor_01”, “Sensor_02” etc.

then it uses that to set the property “hostID” on the other cube,but it is not working as intended I believe,

as it only works if it hits a face in it’s pair,

the pair is not to check against, it is to map where the ray is next emitted,
So Face 1 and 2 are “linked”
So Cube A emits ray striking face 1,Cube A looks up Cube B’s “pair” for face 1 which is face 2
Host Id = 2

HAHAHAAH it was all about communication errors

He thought I meant to check to see if the struck face was it’s pair!!
I wanted to set the hostID as the PAIR!!

Like I hit face 2
look up pair is face 1
hostID =1

not check against it :slight_smile:
Fixed it :slight_smile:

from bge import render # for drawing linesfrom mathutils import Vector # for easy editing of Vectors

distance = 3 # the distance of the ray
pairs = [[1, 2], [2,1], [4,3], [3,4], [5,6], [6,5]] # editable list of data for every face

note: The first value is the id of the face, when hit, the second value will return. The second value is the id of the face that will cast a ray.

def castRay(cont):
# get the owner of the controller, this is the cube
object = cont.owner
# get coordinates to calculate the start and end of the ray
if not ‘polyData’ in object: # once the property exists, this won’t run
# get the mesh
mesh = object.meshes[0]
# create a list
polyData = []
# loop as many times as there are polygons in the mesh
for polyIndex in range(mesh.numPolygons):
# get the polygon
poly = mesh.getPolygon(polyIndex)
# get the polygon’s material name
polyMat = poly.material_name
# check the material name if it contains a string value
if ‘Sensor_’ in polyMat:
# get the polygon’s material id
matID = poly.material_id
# get the number of vertexes in the poly
numVerts = poly.getNumVertex()
# create two vectors
coords = Vector((0, 0, 0))
normal = Vector((0, 0, 0))
# loop as many times as there are vertexes
for vertIndex in range(numVerts):
# get the vertex
vert = mesh.getVertex(matID, vertIndex)
# add the vertex’ position to the position Vector
coords += vert.XYZ
# add the vertex’ normal to the normal Vector
normal += vert.normal
# normalize the position Vector
polyPos = coords / numVerts
# normalize the normal Vector and scale it to the distance
polyNormal = (distance + 1) * normal / numVerts
# append the material name, position and normal Vectors
polyData.append([polyMat, polyPos, polyNormal])
# save the list to a property on the cube
object[‘polyData’] = polyData
# get the cube’s transform data
transform = object.worldTransform
# get the list with all the polydata from the saved property
polyData = object[‘polyData’]
# get the active face from the game property
hostID = object[‘hostID’]
# loop and get the data for every polygon
for data in polyData:
# get the suffix of the polygon’s material name and cast to integer
id = int(data[0][-2:])
# check if the integer equals the game property, to get the face data
if hostID == id:
# recalculate the start of the ray
start = transform * data[1]
# recalculate the end of the ray
end = transform * data[2]
# preview by drawing a line from start to end
render.drawLine(start, end, [255, 0, 0])
# cast ray from start to end, get hit object and polygon
hitOb, _, , hitPoly = object.rayCast(end, start, 0, ‘’, 0, 0, 1)
# if the ray hits a polygon then do the following
if hitPoly:
# get the polygon’s material name
hitMat = hitPoly.material_name
# check the material name if it contains a string value
if 'Sensor
’ in hitMat:
# get the suffix of the material name
hitID = int(hitMat[-2:])
# get the material’s pair from the pairs list
pair = pairs[id]
# if the first value corresponds with the hit poly then

                # change the game property of the hit object
                hitOb['hostID'] = RIGHT HERE
                # set the game property of the owner to zero
                object['hostID'] = 0
                 # set the state of the owner to the first state
                object.state = 1

the issue is I need to set the value RIGHT HERE

two the second item on the list pairs, how do I do?

It says invalid index, is item 0 the first item or item 1?

Here we go :slight_smile:

ALL DONE !!!

Now moving onto looking up properties etc,

Attachments

HAHAAH.blend (509 KB)

@BluePrintRandom:

DO NOT ADD CONSECUTIVE POSTS - EDIT YOUR LAST POST!

I really advice to improve your posting/writing style. Your posts are nearly unreadable and you necessarily flood the forum with them.
If you want help, then present your problems in a way that others can at least understand what your problem is. Avoid any mumbling.

DO NOT ADD CONSECUTIVE POSTS, as it ads to the topic, and keeps a chronological record,
instead,

AND DO NOT ASK THE MAN BEHIND THE CURTAIN…

Please count your posts in this thread.
I told you multiple times not to do this.

You can easily edit your last post. You know that. But you seem not to care.
This is a forum not a blog.

I will try, and I think you are awesome. just a little rigid for my tastes, go have some fun. Smile :slight_smile:

Character means having fun when the world is falling apart around you :slight_smile: