Sprite attached to mesh

Blitz3D Forums/Blitz3D Beginners Area/Sprite attached to mesh

nivek(Posted 2004) [#1]
How do I attach a sprite to a mesh so it moves with the mesh? I made the mesh the parent of the sprite but that didn't work. I then tried using AlignToVector along with the picked coordinates but the sprite disappears. It may be inside the mesh where I can't see it. I need to attach it to the surface. I was also trying to paint a color onto the mesh texture which I figured out how to do but I can't obtain the color I want. I want a very dark red color but I always get a pink color when applying to the flesh tone texture.

Thanks


jfk EO-11110(Posted 2004) [#2]
you should use aligntovector, then turn the sprite 180 degrees since it may look away from the camera, then move it a tiny bit forward to prevent it will blink on the surface of the object due to floating point inaccuracy in the zbuffer. and parent it to the object, of course (don't confuse child and parent in the parameters)


Synchronist(Posted 2004) [#3]
You may wish to check this thread out:
http://www.blitzbasic.com/Community/posts.php?topic=36125
I think Vorderman provided a solution for this problem.


nivek(Posted 2004) [#4]
I tried jfk’s advise but it still doesn’t work. It might help to explain what I’m trying to do. The mesh is a human figure called “man”. The sprit is called sbhole which is a bullet hole. I use a type called bhole. When the man mesh is shot the bullet hole is created at the picked position then the “die” animation plays and the man falls backwards. I want the sprite to remain attached to the man mesh while he falls. Here is the code:

If PickedEntity()=man Then
bh.bhole=New bhole
bh\entity=CopyEntity(sbhole)
bh\alpha=1
PositionEntity bh\entity,PickedX(),PickedY(),PickedZ()
EntityParent bh\entity,man
AlignToVector bh\entity,PickedX(),PickedY(),PickedZ(),2
RotateEntity bh\entity,0,0,180
Animate man,3,5,die
EndIf

Any help is appreciated.
Thank


Inner(Posted 2004) [#5]
I'd just paint the bullet hole onto the players texture, and re-texture the model, but that's just me.


nivek(Posted 2004) [#6]
Thanks Inner, can you advise me on how to do that properly because when I try it the color comes out wrong. How do I get a deep dark red?
Thanks


Inner(Posted 2004) [#7]
(asuming your using 2d commands to write to the texture)

Color 128,0,0 (should be a darkish red)

Color -> RED,GREEN,BLUE .. the greater the number the brighter the color, obviously the lower the number the darker the color.

alternatively;
paint program draw a red dot, of your desired appearence. load the image in as 2d, and draw the image to the texture at desired location, of course then you could get fance and instead of loading in just a static image, you could load in a whole anim strip of diferent types of holes.


jfk EO-11110(Posted 2004) [#8]
But this way you still need the formula to find the right position on the texture. In the examples from the Blitz CD (no idea if they come with the download version as well) is something named paintmesh or something similar. You could use it to calculate the position of the hole on the texture.

But IMHO this is all a big trouble, compared to the sprite method. Don't forget, if multiple meshes are using this Texture, they may have that bullethole too, automaticly.

Blitz optimizes the Loading of Textures, so when you load a texture muliple times, it will use an instance of the first on instead. You really need to create new textures in this case, using CreateTexture and CopyRect from the original one... Big troubles IMHO.

If I was you, I would write that sprite thing as a seperate test, using a sphere and a sprite. If this once works, you know how to deal with it.

THere is an other thing you may need to consider: You "man" mesh: is this mesh animated? Did you load it with LoadAnimMesh? Well, then you need to handle the children, and not the top handle. Because LoadAnimMesh is using a Dummy Pivot at the top level of the Model, and it's children are Meshes or bones.

The easiest way to prevent such troubles would be to attach the Sprite not to "man", but to the handle that was returned by the pick command you used (I guess Linepick or CamerPick)

picknick=CameraPick(mousex(),mousey())
if picknick<>0
 positionentity spri,pickedx(),pickedy(),pickedz(),1
 alignToVector spri,pickednx(),pickedny(),pickednz(),1
 turnentity spri,0,180,0
 moveentity spri,0,0,.05
 parententity spri,picknick
endif



nivek(Posted 2004) [#9]
I think the problem is the animation of the mesh. If I move the mesh after attaching the bullet hole the bullet hole moves with mesh but the bullet hole doesn't move with the animation. When the man mesh falls backwards to the ground the bullet whole stays in it's original position so it ends up hanging in mid air.

Thanks


nivek(Posted 2004) [#10]
Thanks again Inner. The idea of drawing the image directly onto the texture is interesting and will probably work in my program since I will only have 1 mesh visible at once. I wonder if you could explain in more detail how to do it in Blitz3D because I'm not sure.

Thanks