Aller au contenu


MapPointToTexture


  • Vous ne pouvez pas répondre à ce sujet
4 réponses à ce sujet

#1 Matse

  • Moderateur
  • 3 592 messages

Posté 16 octobre 2006 - 01:15

Salut à tous,

suite à une question voici un script écrit par le fabuleux James Newton et modifié par Alexx

Ce script permet, à partir d'un modelsUnderLoc ou d'un modelsUnderRay en mode #detailed sur un modèle texturé, de connaître le point2D correspondant dans l'image de la texture

exemple d'utilisation :

Lingo
 
data = sprite(1).camera.modelsunderloc(the mouseloc, 1, #detailed)
if data.count then
tLoc = mMapPointToTexture(data[1], 512,512) -- en imaginant que la texture qui nous intéresse fasse 512*512
end if
 


Lingo
 
-- MAP POINT TO TEXTURE --
--
-- © October 2001, James Newton <newton@planetb.fr>
 
-- Bidouillage d'Alexx : remplacement de l'objet anImage par ses dimensions tWidth,tHeight
 
on mMapPointToTexture(iSectList, tWidth,tHeight) ----------------------------
-- RETURNS the point in the Bitmap member used by the texture
-- defined implicitly in <iSectList>
--
-- INPUT:
-- <iSectList> should be a property list of the format:
-- [#model: model("model name"),
-- #distance: <float>,
-- #isectPosition: <vector>,
-- #isectNormal: <vector>,
-- #meshID: <integer>,
-- #faceID: <integer>,
-- #vertices: [<vector>, <vector>, <vector>],
-- #uvCoord: [#u: <float>, #v: <float>]]
-- <anImage> can be VOID, an image object, or any type of object
-- with width and height properties (eg: propList)
--
-- When you use aCamera.modelsUnderLoc(aLoc, #detailed) or
-- aMember.modelsUnderRay(aPoint, aVector, #detailed), the result is
-- a linear list of lists with this format.
---------------------------------------------------------------------

tModel = iSectList.model
tResource = tModel.resource

isMesh = (tResource.type = #mesh)

if not isMesh then
-- We need to use the mesh deform modifier to get texture data
if not((tModel.modifier).getpos(#meshdeform))then
-- Add mesh deform modifier... but remember to remove it later
tModel.addmodifier(#meshdeform)
isModified = true
end if
end if

tFace = iSectList.faceID
tUVCoord = iSectList.uvCoord

-- Determine how the iSect data maps to this particular face
if isMesh then
tCoordList = tResource.textureCoordinateList
tFaceList = tResource.face[tFace].texturecoordinates

else
tCoordList = tModel.meshdeform.mesh[iSectList.meshID].textureCoordinateList
tFaceList = tModel.meshdeform.mesh[iSectList.meshID].face[tFace]
if isModified then
-- Remove the modifier now that it has done its job
tModel.removeModifier(#meshdeform)
end if
end if

-- tCoordList will be a list of lists, each containing two floating-
-- point numbers between 0.0 and 1.0. The first number defines the
-- relative horizontal position of a point in the texture, the
-- second number defines the relative vertical point. The origin
-- point [0.0, 0.0] is in the bottom left hand corner.
--
-- tFaceList will be a list with three integer values [a, b, c]
-- These values determine which entry in tCoordList is used by the
-- chosen face. The first entry <a> defines the origin. The u
-- value increases from <a> to <b>. Any point on the line between
-- <a> and <b> will have a v value of zero. The v value increases
-- from <a> to <c>. Any point on the line between <a> and <b> will
-- have a v value of zero.

-- Calculate the position of the points <a>, <b> and <c> within the
-- Bitmap member.

tLocA = tCoordList[tFaceList[1]] -- [<float>, <float>]
tLocA = point(tLocA[1] * tWidth, (1 - tLocA[2]) * tHeight)

tLocB = tCoordList[tFaceList[2]] -- [<float>, <float>]
tLocB = point(tLocB[1] * tWidth, (1 - tLocB[2]) * tHeight)

tLocC = tCoordList[tFaceList[3]] -- [<float>, <float>]
tLocC = point(tLocC[1] * tWidth, (1 - tLocC[2]) * tHeight)

tUVector = (tLocB - tLocA) * tUVCoord.u -- actually a 2D point...
tVVector = (tLocC - tLocA) * tUVCoord.v -- ... rather than a vector

-- Start from the origin <a>, move first in the u direction then in
-- the v direction to end up at the point in the texture

return tLocA + tUVector + tVVector
end mMapPointToTexture
 


#2 Little Critter's

    Ceinture Bleue

  • Members
  • 88 messages

Posté 30 octobre 2006 - 12:51

Salut

J’ai tester ce script a quelque reprise avec une maille créé a partir d’un algorithme (générateur de terrain avec son code couleur ou luminosité) bref ça ne fonctionne pas, j’ai du utiliser une autre méthode beaucoup plus complexe pour obtenir mon point.
Est-ce que quelqu’un d’autre que moi a déjà utiliser ce script avec une maille créé en lingo et a réussi a le faire fonctionner correctement si oui ça m’intéresse de savoir comment tu t’y est pris.

Merci


#3 Matse

  • Moderateur
  • 3 592 messages

Posté 30 octobre 2006 - 01:06

Salut,

ben écoutes moi je m'en sers en ce moment même, sur des modèles de type mesh copiés à partir de plans standards, pour permettre de dessiner sur la couche alpha de la texture et ça fonctionne très bien. Je l'utilise exactement comme je l'ai mis dans l'exemple :

tLoc = mMapPointToTexture(pRolloverModel[1], alphaBMP.width, alphaBMP.height)


pRolloverModel étant le résultat d'un modelsUnderLoc, et alphaBMP l'acteur de ma texture.

#4 Little Critter's

    Ceinture Bleue

  • Members
  • 88 messages

Posté 30 octobre 2006 - 01:37

Salut Matse

Ok si tu dis que ça fonctionne avec une maille fait en lingo c'est que ça marche je vais revoir les anciens test que j'ai fait, et en fait je crois que j'utilisais modelUnderLoc a la place modelsUnderLoc je crois que ce doit être la source de mon problème.

Je te le confirme après vérification

Merci

#5 Matse

  • Moderateur
  • 3 592 messages

Posté 30 octobre 2006 - 01:50

Yop,

ah oui il faut impérativement utiliser modelsUnderLoc (ou modelsUnderRay, si on se sert d'autre chose que de la souris) en mode #detailed, sinon le script n'a pas les coordonnées UV de l'intersection avec le modèle.





1 utilisateur(s) li(sen)t ce sujet

0 membre(s), 1 invité(s), 0 utilisateur(s) anonyme(s)

authorised training centre

Centre de Formation Mediabox - Adobe et Apple Authorised Training Center.

Déclaré auprès de la Direction du Travail et de la Formation Professionnelle

Mediabox : SARL au capital de 62.000€ - Numéro d'activité : 11 75 44555 75 - SIRET : 49371646800035

MEDIABOX, 23, rue de Bruxelles, 75009 PARIS - Tel. 0826 466 613 - Fax. 01 72 70 31 38

FFP