Notifications
Clear all

[Closed] Align a sprite to a face

Hi, I’m new in this forum and in MS too.

I’m writing a script to align sprite on selected faces of a object.
But I dont know how to rotate the sprites to align them to the face normal.

A friend talk to me about “quaterion” , I search on internet and MS ref but i’m not familiar with matrix (yes I know, its bad if i want to use MS but I begin ^^ ) so I dont know how to use it well to do what I want.

here is the fonction where I start working on my sprite:


	function WorkOnSprite FaceID NumID ScaleVar = (
		AttaSprite_Copy = copy AttachSprite_Sprite
		AttaSprite_Copy.name = "Sprite_Face"+FaceID as string+"_"+NumID as string
		--print ("Sprite copy name : "+AttaSprite_Copy.name)
		AttaSprite_Copy.scale *= random (1-(ScaleVar/100)) (1+(ScaleVar/100))
		--print ("getFaceCenter : "+polyOp.getFaceCenter AttachSprite_Source FaceID as string)
		--print ("getFaceNormal : "+polyOp.getFaceNormal AttachSprite_Source FaceID as string)
		--print ("getFaceArea : "+polyOp.getFaceArea AttachSprite_Source FaceID as string)
		AttaSprite_Copy.pos = polyOp.getFaceCenter AttachSprite_Source FaceID
--here i want to rotate the sprite copy to align it with the normal of the face
		return AttaSprite_Copy
	)

I’ll ask other question but I prefer solve this one first

ps : sorry for my english, I’m a french user.

4 Replies

___________bump

Try if you can set AttaSprite_Copy.dir to face normal direction or something.

Insert this line

AttaSprite_Copy.rotation /= (matrixFromNormal (polyOp.getFaceNormal AttachSprite_Source FaceID))

before this

AttaSprite_Copy.pos = polyOp.getFaceCenter AttachSprite_Source FaceID

ty for your help.
I dont really know how, but i understand you aply a transformation matrix

Now, to be more familiar with matrix, i’ll try to offset each sprite depending on the normal face (to avoid Z-fight). Any advise before I start ? ^^

After, I’ll use “getFaceArea” to have a random position on each sprite (not always on a face center). Its a good way to do this ?