Fake highlight texture?

Hi, two questions…

  1. If you look at a ball in a comic, there’s almost always a white circle on it to show how the light falls on it.

So… is there a way of getting an alpha texture onto a sphere, like a white circular highlight, so that whereever the camera moves, the highlight appears to follow the camera? Like a halo map?

  1. Is there a python method for finding all the vertices of a mesh, and then spawning objects at these vertices? (It’s to make an explosion effect)

Many thanks,

1/1 credit(s)

  1. why not use actual specular highlights? they’re on by default, and I’d hazard that they’re cheaper performance-wise than a texture. You can adjust the softness and brightness in the texture pane.

  2. you can use this script:


g=GameLogic
c=g.getCurrentController()
o=c.owner

scene=g.getCurrentScene()

pos=o.position
scale=o.worldScale

mesh=o.meshes[0]
m=mesh.numMaterials
while m>0:
    m-=1
    v=mesh.getVertexArrayLength(m)
    while v>0:
        v-=1
        vert=mesh.getVertex(m,v)
        vpos=vert.XYZ#get vertex position (local coordinate space)
        vpos=[vpos[0]*scale[0],vpos[1]*scale[1],vpos[2]*scale[2]] #apply scaling
        obpos=[vpos[0]+pos[0],vpos[1]+pos[1],vpos[2]+pos[2]]#apply position
        
        ob=scene.addObject('spawned',o) #add object
        ob.position=obpos #position object
        ob.worldOrientation=[0,0,0] #clear object's rotation
        
        #clear object's scaling (irritatingly complicated)
        wscale=ob.worldScale
        wscale=[wscale[0]/scale[0],wscale[1]/scale[1],wscale[2]/scale[2]]
        ob.localScale=wscale

The problem is, a vertex’s position is given in local coordinates. I went ahead and added the object position, but if the object is rotated at all the spawned objects will appear as though the object had its rotation cleared first. It’s definitely possible to apply rotation, but I don’t know the formula offhand.
The script will work if the object is positioned or scaled in any way, except if the scale = 0 (then the script’ll crash and burn)

If you want the smaller objects to scale with the emitter object, remove (or just comment out) the last chunk of the script. Technically you could remove just the very last line, but it’d still calculate the scaling required and that’s a waste of processor time if it’s not applied.

If you convert your position lists into vectors, you can transform (rotate) those vectors with a matrix:

vpos = Matrix(*own.worldOrientation) * Vector(vert.XYZ)

That would account for object rotation.

However, more important that additional functionality, is making sure that current procedures are working properly:

Right now, you’re effectively adding 24 different objects, not 8 as you might expect; each face holds its own personal set of vertexes, so, for a cube, it’s 6 * 4 = 24.

The following modifications should account for that, and object rotation:


g=GameLogic 
from Mathutils import Vector, Matrix 
c=g.getCurrentController() 
o=c.owner 

pos = Vector(o.position) 
scale = Vector(o.worldScale) 
 
rot_mat = Matrix(*o.worldOrientation) 
primary_vertices = [] 
 
mesh=o.meshes[0] 
m=mesh.numMaterials 
while m>0: 
    m-=1 
    v=mesh.getVertexArrayLength(m) 
    while v>0: 
        v-=1 
        vert=mesh.getVertex(m,v) 
        if not vert.XYZ in primary_vertices: 
            primary_vertices.append(vert.XYZ) 
            vpos = rot_mat * Vector(vert.XYZ)#get vertex position (local coordinate space) 
            vpos.x *= scale.x; vpos.y *= scale.y; vpos.z *= scale.z 
            obpos = pos + vpos #apply position 
                     
            ob=scene.addObject('spawned',o) #add object 
            ob.position=obpos #position object 
            ob.worldOrientation=[0,0,0] #clear object's rotation 
                     
            #clear object's scaling (irritatingly complicated) 
            wscale = Vector(ob.worldScale) 
            wscale.x /= scale.x; wscale.y /= scale.y; wscale.z /= scale.z 
            ob.localScale=wscale

PS: If you find that object scaling is so “irritatingly complicated”, use a different object for the “other” argument -> one that has a constant scale of 1.

Ah yes, I had forgotten about the vertex splitting. My bad.

The irritating thing about scaling is that I’m used to scaling to be a multiplier, where 1 is unscaled- but when setting the scale through python, a scale of 1 makes it so that the bounding box has a side length of 1. As far as I can tell, there’s no way to clear an object’s scale without knowing beforehand the measurements of the bounding box…

This is AWESOME-O! Perfect so far, except there was a small bug, which I fixed below:

 
 
g=GameLogic 
from Mathutils import Vector, Matrix 
c=g.getCurrentController() 
o=c.owner 
pos = Vector(o.position) 
scale = Vector(o.worldScale) 
scene=g.getCurrentScene() # just needed to define scene
 
rot_mat = Matrix(*o.worldOrientation) 
primary_vertices = [] 
 
mesh=o.meshes[0] 
m=mesh.numMaterials 
while m>0: 
    m-=1 
    v=mesh.getVertexArrayLength(m) 
    while v>0: 
        v-=1 
        vert=mesh.getVertex(m,v) 
        if not vert.XYZ in primary_vertices: 
            primary_vertices.append(vert.XYZ) 
            vpos = rot_mat * Vector(vert.XYZ)#get vertex position (local coordinate space) 
            vpos.x *= scale.x; vpos.y *= scale.y; vpos.z *= scale.z 
            obpos = pos + vpos #apply position 
 
            ob=scene.addObject('Plane',o) #add object [ I changed to an alpha mapped plane, to simulate shrapnel ready to fly off ]
            ob.position=obpos #position object 
            ob.worldOrientation=[0,0,0] #clear object's rotation 
 
            #clear object's scaling (irritatingly complicated) 
            wscale = Vector(ob.worldScale) 
            wscale.x /= scale.x; wscale.y /= scale.y; wscale.z /= scale.z 
            ob.localScale=wscale
 

Thanks a lot! But there is one thing I need to ask - is there a way of making each “particle”, or spawned object, stay where it was spawned for about half a second, and then explode outwards in random velocities, at the same time? I know it’s a big ask, but I’m trying to perfect a killer7 style explosion. ANYWAYS, thanks again!

Regards,

1/1 credit(s)

PS About the fake highlight on the circle; a better example is like a semi-transparent bar on a window, indicating it is shiny, which moves with the camera. Could this be done with texturing?

You can map a texture to “camera”, so it should stay in the same place on the camera (and only show up if the textured object is at the same place on the screen).

Excellent thinking… But could you tell me how I do this?

Many thanks

1/1 credit(s)

In the texture mapping pane (where you’d set the scale of the texture, and set it to UV, or global, or local, or whatever) click on “camera”. If that doesn’t work, try “reflect”.

I’m really sorry but I can’t find this… Do you have an example or tutorial I could use?

Many thanks for your time

1/1 credit(s)

When I said camera before, I must’ve been thinking of using camera coordinates in the node editor, sorry for saying the wrong name X|

You’re actually looking for “Win” (window), which is in the map input pane (far right pane, middle tab) in the shading buttons (F5). make sure you have the proper texture selected if you have more than one (left tab, same pane)

Yeah, sorry dude - still can’t figure it out. :eek:

So here’s a copy of what I’m trying to do - could you change what’s wrong please?

Many thanks again

1/1 credit(s)

Attachments

texture_test.blend (146 KB)