maxscript rotate texture

maxscript rotate texture

Anonymous
Not applicable
2,006 Views
11 Replies
Message 1 of 12

maxscript rotate texture

Anonymous
Not applicable

hello guys,

i asked many question and may be trivial question but because i am new in 3d max and max script

i draw some face represent walls and some represent roofs and some represent doors an windows

but texture of doors and window but not all window or all doors rotated how to fixx it

 

Capture.PNG

0 Likes
Accepted solutions (1)
2,007 Views
11 Replies
Replies (11)
Message 2 of 12

Swordslayer
Advisor
Advisor

Instead of using #face mapping, I'd advise you to do the mapping part manually using polyop.setMapVert and polyop.setMapFace functions.

 

Couple of notes to get you started: the map vertices do not correspond to polymesh vertices, they are positions in UVW space (and most of the time, the third coordinate should be zero to get flat mapping). Then, the map faces are defined using these vertices so some faces can share the same vertex/vertices (in the case that those verts define an edge, it means there won't be a map seam) or they can be defined by unique vertices. When you define map vertices, you defined them as positions, when you define map faces, you define them using map vert indices - so you have to first set the number of mesh vertices you'll be using (and their position) and only after that build map faces using those verts.

 

A nice example of using these functions is this Klvnk's post.

0 Likes
Message 3 of 12

Anonymous
Not applicable
i tried this but also not work

fn drawDoor vertices =
(
thick=.25
face1=#()
face2=#()
face1Normal = normalize (cross (vertices[3] - vertices[2]) (vertices[1] -
vertices[2]))
face2Normal=-face1Normal ;

face1[1]= (vertices[1]+ (thick*face1Normal))
face1[2]= vertices[2]+(thick*face1Normal)
face1[3]= vertices[3]+(thick*face1Normal)
face1[4]=vertices[4]+ (thick*face1Normal)
face2[1]= (vertices[1]+ (thick*face2Normal))
face2[2]= vertices[2]+(thick*face2Normal)
face2[3]= vertices[3]+(thick*face2Normal)
face2[4]=vertices[4]+ (thick*face2Normal)
obj = convertToPoly (mesh vertices:face1 faces:#())

polyOp.createPolygon obj #(1,2,3,4)

obj2 = convertToPoly (mesh vertices:face2 faces:#())

polyOp.createPolygon obj2 #(4,3,2,1)
img_path = "C:\Users\Abdo\Desktop/Door.jpg"

channel = 1;
num_faces = polyop.getNumFaces obj;
for f = 1 to num_faces do(
uvF = polyOp.getMapFace $ channel f;
polyOp.setMapVert obj channel uvF[1] [0,0,0];
polyOp.setMapVert obj channel uvF[2] [100,0,0];
polyOp.setMapVert obj channel uvF[3] [0,100,0];
polyOp.setMapVert obj channel uvF[4] [100,100,0];
)
mat=standardmaterial();

mat.diffuseMap = bitmapTexture filename:(img_path)

-- to display material on face
showtexturemap mat true

/*
uvw to adjust texture mapping
*/
polyop.applyUVWMap obj \
#face \
obj.material=mat
mat2=standardmaterial();

mat2.diffuseMap = bitmapTexture filename:(img_path)
-- to display material on face
showtexturemap mat2 true

/*
uvw to adjust texture mapping
*/
polyop.applyUVWMap obj2 \
#face \
obj2.material=mat2


)
0 Likes
Message 4 of 12

Anonymous
Not applicable

i tried this but also not work

 

fn drawDoor vertices =
(

thick=.25

face1=#()
face2=#()
face1Normal = normalize (cross (vertices[3] - vertices[2]) (vertices[1] - vertices[2]))
face2Normal=-face1Normal ;

face1[1]= (vertices[1]+ (thick*face1Normal))
face1[2]= vertices[2]+(thick*face1Normal)
face1[3]= vertices[3]+(thick*face1Normal)
face1[4]=vertices[4]+ (thick*face1Normal)

face2[1]= (vertices[1]+ (thick*face2Normal))
face2[2]= vertices[2]+(thick*face2Normal)
face2[3]= vertices[3]+(thick*face2Normal)
face2[4]=vertices[4]+ (thick*face2Normal)

obj = convertToPoly (mesh vertices:face1 faces:#())

polyOp.createPolygon obj #(1,2,3,4)

obj2 = convertToPoly (mesh vertices:face2 faces:#())

polyOp.createPolygon obj2 #(4,3,2,1)

img_path = "C:\Users\Abdo\Desktop/Door.jpg"

channel = 1;
num_faces = polyop.getNumFaces obj;
for f = 1 to num_faces do(
uvF = polyOp.getMapFace $ channel f;

polyOp.setMapVert obj channel uvF[1] [0,0,0];
polyOp.setMapVert obj channel uvF[2] [100,0,0];
polyOp.setMapVert obj channel uvF[3] [0,100,0];
polyOp.setMapVert obj channel uvF[4] [100,100,0];
)
mat=standardmaterial();

mat.diffuseMap = bitmapTexture filename:(img_path)

-- to display material on face
showtexturemap mat true

/*
uvw to adjust texture mapping
*/
polyop.applyUVWMap obj \
#face \

obj.material=mat


mat2=standardmaterial();

mat2.diffuseMap = bitmapTexture filename:(img_path)
-- to display material on face
showtexturemap mat2 true

/*
uvw to adjust texture mapping
*/
polyop.applyUVWMap obj2 \
#face \

obj2.material=mat2


)

0 Likes
Message 5 of 12

Swordslayer
Advisor
Advisor

I can see multiple issues worth pointing out here. You are setting map vert positions to values like [100,100,0], while the UV space size is 1,1 (unless you are using UDIM - which you aren't, they need a special texture map anyway). The vertex indices for createPolygon are absolute, i.e. if you are using 1..4 for the second polygon, you are creating it using the same verts as the first one, you need 5..8. If you are building the reversed face in simple reverse order (i.e. 4321 or rather 8765, instead of 6587 where the first two verts line up with the first two verts of the first face), it's a good idea to collect the vertex positions in reverse order as well, i.e. instead of counting from 1 to 4 in the loop counter, count backwards. And a note, use the verbatim string literal (at sign) with paths, it won't bite you here but when you have a filename or directory name starting with 't', you would find out - \t expands to tab, \n expands to newline and so on, it's a way to represent some special characters within string. All in all, this is how I'd write it:

 

fn drawDoor vertices thickness UVScale mat mapChannel =
(
	local faceNormal = normalize (cross (vertices[3] - vertices[2]) (vertices[1] - vertices[2]))
	local face1 = for v = 1 to vertices.count collect vertices[v] + thickness * faceNormal
	local face2 = for v = vertices.count to 1 by -1 collect vertices[v] - thickness * faceNormal
	local faceVerts = face1 + face2

	local obj = convertToPoly (mesh vertices:faceVerts faces:#())
	polyOp.createPolygon obj #(1,2,3,4)
	polyOp.createPolygon obj #(8,7,6,5)

	polyop.setMapSupport obj mapChannel true
	local projectionMatrix = arbAxis faceNormal * scaleMatrix (UVScale * [1,1,1])
	local faceCount = polyOp.getNumFaces obj

	for f = 1 to faceCount do
	(
		local uvF = polyOp.getMapFace obj mapChannel f

		for v = 1 to vertices.count do
			polyOp.setMapVert obj mapChannel uvF[v] (polyOp.getVert obj v * inverse projectionMatrix)
	)

	obj.material = mat
	return obj
)

imgPath = @"C:\Users\Abdo\Desktop\Door.jpg"
mat = standardMaterial diffuseMap:(bitmapTexture filename:imgPath)
showTextureMap mat true -- to display material on face

drawDoor #([0,0,0], [100,0,0], [100,100,0], [0,100,0]) 25 100 mat 1
0 Likes
Message 6 of 12

Anonymous
Not applicable

i write code as it's

 

fn drawDoorV2 vertices thickness UVScale mat mapChannel =
(
v1Temp=vertices[1]-vertices[2]
v1temp.x=abs v1temp.x
v1temp.y=abs v1temp.y

v2Temp=vertices[1]-vertices[4]
v2temp.x=abs v2temp.x
v2temp.y=abs v2temp.y
width=v2temp.x;
heigt=v2temp.y;
if v1temp.x>v2temp.x then
(
width=v1temp.x
)
if v1temp.y>v2temp.y then
(
height=v1temp.y
)
local faceNormal = normalize (cross (vertices[3] - vertices[2]) (vertices[1] - vertices[2]))
local face1 = for v = 1 to vertices.count collect vertices[v] + thickness * faceNormal
local face2 = for v = vertices.count to 1 by -1 collect vertices[v] - thickness * faceNormal
local faceVerts = face1 + face2

local obj = convertToPoly (mesh vertices:faceVerts faces:#())
polyOp.createPolygon obj #(1,2,3,4)
polyOp.createPolygon obj #(5,6,7,8)

polyop.setMapSupport obj mapChannel true
local projectionMatrix = arbAxis faceNormal * scaleMatrix ([width , height ,1] * [1,1,1])
local faceCount = polyOp.getNumFaces obj

for f = 1 to faceCount do
(
local uvF = polyOp.getMapFace obj mapChannel f

for v = 1 to vertices.count do
polyOp.setMapVert obj mapChannel uvF[v] (polyOp.getVert obj v * inverse projectionMatrix)
)

obj.material = mat
return obj
)

 

 

but not work as i need 

as this out put some doors texture reversed and some not appear and appear color instead of it 

Capture.PNG

0 Likes
Message 7 of 12

Swordslayer
Advisor
Advisor
Looks like either your computed width or height is zero, for those filled only with color (throw a unwrap modifier on top and look where the verts are in the uv space). As for the orientation, the vertex order still matters, if you can't guarantee all the vertex position arrays will have a similar ordering, make some rules and sort them accordingly before passing them to the function.
0 Likes
Message 8 of 12

Anonymous
Not applicable

yes i had checked about  width or height and found it equal zero 
but what about texture  has repeated it self and not adjuste (regardless it flipped)

0 Likes
Message 9 of 12

Swordslayer
Advisor
Advisor
That's still a problem of that width/height calculation, with orthogonal geometry such as you have there in the picture, the projection matrix will use for x and y (which will eventually be U and V) coords either x or y for U and z for V. Note that if you start using rotated faces, you will have to adjust your calculations again to take that into account. ArbAxis is okay when you want to derive the matrix using Z-axis as a base, later in the process you might find it best to construct the matrix yourself.
0 Likes
Message 10 of 12

Anonymous
Not applicable

i think i haven't problem in width or height 

as i have polygon vetices 1..4  so when i substract 2,1 get width or heigyt and subtract other get other

i wrote this

v1Temp=vertices[1]-vertices[2]
v1temp.x=abs v1temp.x
v1temp.y=abs v1temp.y
v1temp.z=abs v1temp.z

v2Temp=vertices[1]-vertices[4]
v2temp.x=abs v2temp.x
v2temp.y=abs v2temp.y
v2temp.z=abs v2temp.z

xScale=v2temp.x;
yScale=v2temp.y;
zScale=v2temp.y;

if v1temp.x>v2temp.x then
(
xScale=v1temp.x
)
if v1temp.y>v2temp.y then
(
yScale=v1temp.y
)
if v1temp.z>v2temp.z then
(
zScale=v1temp.z
)
if xScale<1 then
xScale=1
if yScale<1 then
yScale=1
if zScale<1 then
zScale=1 

0 Likes
Message 11 of 12

Anonymous
Not applicable

this is all function

 

fn drawDoorV2 vertices thickness UVScale mat mapChannel =
(
v1Temp=vertices[1]-vertices[2]
v1temp.x=abs v1temp.x
v1temp.y=abs v1temp.y
v1temp.z=abs v1temp.z

v2Temp=vertices[1]-vertices[4]
v2temp.x=abs v2temp.x
v2temp.y=abs v2temp.y
v2temp.z=abs v2temp.z

xScale=v2temp.x;
yScale=v2temp.y;
zScale=v2temp.y;

if v1temp.x>v2temp.x then
(
xScale=v1temp.x
)
if v1temp.y>v2temp.y then
(
yScale=v1temp.y
)
if v1temp.z>v2temp.z then
(
zScale=v1temp.z
)
if xScale<1 then
xScale=1
if yScale<1 then
yScale=1
if zScale<1 then
zScale=1

local faceNormal = normalize (cross (vertices[3] - vertices[2]) (vertices[1] - vertices[2]))
local face1 = for v = 1 to vertices.count collect vertices[v] + thickness * faceNormal
local face2 = for v = vertices.count to 1 by -1 collect vertices[v] - thickness * faceNormal
local faceVerts = face1 + face2

local obj = convertToPoly (mesh vertices:faceVerts faces:#())
polyOp.createPolygon obj #(1,2,3,4)
polyOp.createPolygon obj #(5,6,7,8)

polyop.setMapSupport obj mapChannel true
local projectionMatrix = arbAxis faceNormal * scaleMatrix ([xScale , yScale , zScale] * [1,1,1])
local faceCount = polyOp.getNumFaces obj

for f = 1 to faceCount do
(
local uvF = polyOp.getMapFace obj mapChannel f

for v = 1 to vertices.count do
polyOp.setMapVert obj mapChannel uvF[v] (polyOp.getVert obj v * inverse projectionMatrix)
)

obj.material = mat
return obj
)

 

0 Likes
Message 12 of 12

Anonymous
Not applicable
Accepted solution

yea i solved it by my previous code submitted in problem definition 
and check clockwise and anticlockwise if points clockwise it take texture if no 

it take reversed texture and reversed teture done manually for image

0 Likes