Notifications
Clear all

[Closed] UVW Unwrap unknown Error

This is driving me nuts, getting an unknown error when try to unwrap part of an object. The goal here is that i create a picture frame and then unwrap each side so that the texture is applied evenly. I get no errors in the listener so nothing to really work off, tried a few ways to do this and get the same error either way right now I am using:

fn unwrapFrame =
	(
		if (isValidNode picture_Frame) then
		(
			select picture_Frame
			side1Faces = #{3,7,11}
			setCommandPanelTaskMode #modify  --changes to the modify panel
			local theUnwrap = Unwrap_UVW()
			addModifier $ theUnwrap
			classof $
			theUnwrap.setTVSubObjectMode 3
			theUnwrap.selectPolygons side1Faces
			theUnwrap.planarMap()
		)
	)

it gets all the way to the “theUnwrap.planarMap()” before it encounters a problem
i have also tried the route of not setting the unwrap as local and using the object modifier properties but get the same result
thanks for any responses

13 Replies

correction I’m using:

fn unwrapFrame =
	(
		if (isValidNode picture_Frame) then
		(
			select picture_Frame
			side1Faces = #{3,7,11}
			setCommandPanelTaskMode #modify  --changes to the modify panel
			local theUnwrap = Unwrap_UVW()
			addModifier $ theUnwrap
			classof $
			theUnwrap.setTVSubObjectMode 3
			theUnwrap.selectPolygons side1Faces
			theUnwrap.unfoldMap 0
		)

No ideas? I still haven’t found any solution

Since I still have no idea what the problem is, anyone have any ideas on how to more or less do what i was trying to do? Unwrap a few given polys together and then relax or unfold them so they lay flat without stretching?

it’s often easier to generate the Geometry and UV’s on the fly as it were to get the results that you want.

the profile code is from DenisT, very cool and very professional. the rest was some minor changes to some prototyping code I had.
-- simple object picture frame scripted plugin
 -- profile curve code by denisT
 
 plugin simpleObject picframe
 	name:"picframe"
 	classID:#(0x68021924, 0x627ffe63)
 	category:"Scripted"
 (
 -- params	
 	
 	parameters main rollout:params
 	(
 		curve 		type:#maxobject
 		width		type:#float ui:width_spnr default:10.0;
 		height	  type:#float ui:height_spnr default:10.0;
 		size		type:#float ui:size_spnr default:2.0;
 		zscale	  type:#float ui:zscale_spnr default:1.0;
 		mapCoords 	type:#boolean default:on ui:ui_mapCoords
 		contUV		type:#boolean default:on ui:ui_contUV
 		manualUpdate type:#boolean default:off animatable:off ui:ui_manualUpdate
 	)
 	
 -- rollout	
 	
 	rollout params "Params"
 	(
 		local updating = on
 		
 		spinner width_spnr "Width:" range:[0, 1e9, 0] fieldwidth:64 type:#float align:#right;
 		spinner height_spnr "Height:" range:[0, 1e9, 0] fieldwidth:64 type:#float align:#right;
 		spinner size_spnr "Size:" range:[0, 1e9, 0] fieldwidth:64 type:#float align:#right;
 		spinner zscale_spnr "Z Scale:" range:[-1e9, 1e9, 0] fieldwidth:64 type:#float align:#right;
 		checkbox ui_mapCoords "Generate Map Coords." align:#left offset:[-2,4]
 		checkbox ui_contUV "Continuous UV Coords." align:#left offset:[-2,4]
 		
 		group "Profile: "
 		(
 			CurveControl ui_profile numCurves:1 width:144 height:100 align:#left offset:[-4,2] enabled:on \
 				x_range:[0,1] y_range:[-0.5,1] x_value:0 \
 				scrollValues:[0,-10] zoomValues:[128,60] \
 				uiFlags:#(#constrainY, #noFilterButtons) \
 				rcmFlags:#(#move_xy, #move_x, #move_y, #corner, #delete) 
 			
 			checkbox ui_manualUpdate "Manual Update" align:#left offset:[-2,0]
 			button ui_updateProfile "Update" width:71 align:#left offset:[-4,0] tooltip:"Update Profile" across:2
 			button ui_resetProfile "Reset" width:71 align:#right offset:[4,0] tooltip:"Reset Profile"
 		)
 		
 		fn setProfile action:#ui update: = if isproperty this #curve do 
 		(
 			if update == unsupplied do update = not manualUpdate
 			c = ui_profile.curves[1]
 			
 			if not iskindof curve bezier_float do curve = bezier_float()
 			t = curve
 				
 			n = 1f
 			
 			while t.keys.count < c.points.count do addnewkey t (n += 1)
 			while t.keys.count > c.points.count do deletekey t 1
 			for n=1 to c.points.count do 
 			(
 				p = c.points[n]
 				k = t.keys[n]
 				
 				k.time = p.value.x
 				k.value = p.value.y
 				k.inTangentType = #linear
 				k.outTangentType = #linear
 				k.x_locked = p.lock_x
 				k.y_locked = p.lock_y
 				k.selected = p.selected
 			)
 			if update do 
 			(
 				this.doBuildMesh()
 				redrawviews()
 			)
 		)
 		
 		fn getProfile = if isproperty this #curve do 
 		(
 			c = ui_profile.curves[1]
 			t = curve
 			
 			c.numPoints = t.keys.count
 			for n=t.keys.count to 1 by -1 do 
 			(
 				p = c.points[n]
 				k = t.keys[n]
 
 				p.value = [k.time, k.value]
 				p.bezier = off
 				p.corner = on
 				p.lock_x = k.x_locked
 				p.lock_y = k.y_locked
 				p.selected = k.selected
 			)
 		)
 
 		on ui_profile deleted c val do if not loading and not updating do setProfile()
 		on ui_profile ptChanged c val do if not loading and not updating do setProfile()
 		on ui_profile tangentChanged c val type do if not loading and not updating do setProfile()
 		
 		fn resetProfile update:off = 
 		(
 			c = ui_profile.curves[1]
 			c.numpoints = 4
 			c.points[2].value = [0,1]
 			c.points[3].value = [1,1]
 			c.points[4].value = [1,0]
 			c.points[1].lock_x = c.points[4].lock_x = on
 			c.points.lock_y = off
 			
 			setProfile update:update
 		)
 		on ui_updateProfile pressed do undo "Update Frame Profile" on 
 		(
 			updating = on
 			setProfile update:on
 			updating = off
 		)
 		on ui_resetProfile pressed do undo "Reset Frame Profile" on 
 		(
 			updating = on
 			resetProfile update:on
 			updating = off
 		)
 		on params open do
 		(
 			updating = on
 			deleteAllChangeHandlers id:#frame_callback
 			c = ui_profile.curves[1]
 			if not iskindof curve bezier_float then resetProfile update:off else getProfile()
 
 			ccTarget = (refs.dependents ui_profile.curves[1])[1]
 			when topology ccTarget change id:#frame_callback do 
 			(
 				if ui_profile.curves[1].numpoints != numkeys curve do setProfile action:#curve
 			)
 			updating = off
 		)
 		on params close do  deleteAllChangeHandlers id:#frame_callback
 	)		
 
 -- viewport create	
 	
 	tool create
 	(
 		 on mousePoint click do case click of
 		 (
 			 1: 
 			 (
 				 nodeTM.translation = gridPoint
 				 width = 0.0;
 				height = 0.0;
 				size = 0.01;
 			 )
 			 3: #stop
 		 )
 		 on mouseMove click do case click of
 		 (
 			 2: 
 			(
 				width = 2.0 * abs gridDist.x;
 				height = 2.0 * abs gridDist.y;
 			)	
 			3: size = amax (abs gridDist.x) (abs gridDist.y)
 		 )
 	)
 		
 -- simple lerp
 	
 	fn lerp  a b s = (a + s * (b - a))	
 
 -- sets edge vis
 		
 	fn mxssetedgevisflags m face flags =
 	(	
 		setEdgeVis m  face 1 flags[1];
 		setEdgeVis m  face 2 flags[2];
 		setEdgeVis m  face 3 flags[3];
 	)
 	
 -- generate ucoords base on distances	
 	
 	fn GetUCoords nsegs =
 	(
 		ucoords = #();
 		ucoords.count = nsegs + 1;
 		ucoords[1] = 0.0;
 		if nsegs == 1 then
 			ucoords[2] = 1.0;
 		else
 		(
 			tlen = 0.0;
 			p1 = getvert mesh 1
 			for i = 2 to nsegs + 1  do
 			(
 				p2 = getvert mesh i; 
 				tlen += distance p1 p2;
 				ucoords[i] = tlen;
 				p1 = p2;
 			)
 			for i = 1 to ucoords.count do ucoords[i] /= tlen; -- normalize to the total length
 		)		
 		ucoords	
 	)	
 
 -- generate V coords base on the x or y dimension	
 	
 	fn GetVCoords nsegs xdim =
 	(	
 		vcoords = #();
 		vcoords.count = nsegs + 1;
 		scalar = 1.0/size;
 		
 		for i = 1 to nsegs + 1  do
 		(
 			p = getvert mesh i;
 			if xdim then
 				vcoords[i] = scalar * abs p.x;
 			else
 				vcoords[i] = scalar * abs p.y;
 		)
 		vcoords;
 	)	
 
 -- create the mesh	
 	
 	fn doBuildMesh =
 	(
 		nsegs = curve.keys.count - 1;
 		nsegs_p1 = nsegs + 1;
 		nverts = nsegs_p1 * 4;
 		nfaces = nsegs * 4 * 2;
 		
 -- offsets and sizes		
 		
 		w = width * 0.5;
 		h = height * 0.5;
 		s = size * 0.5;
 		
 -- "cardinal" points that form the interior and exterior corners of the picture frame		  
 		
 		cp = #([-w-s,-h-s,0],[-w+s,-h+s,0],[w+s,-h-s,0],[w-s,-h+s,0],[w+s,h+s,0],[w-s,h-s,0],[-w-s,h+s,0],[-w+s,h-s,0]);
 		
 		setNumVerts mesh nverts;
 		setNumFaces mesh nfaces;
 		
 -- geo verts		
 		
 		vi = 1;	-- vert incrementer
 		for i = 1 to 4 do
 		(
 			pind = i*2;
 			p1 = cp[pind - 1];
 			p2 = cp[pind];	
 			for j = 1 to nsegs_p1  do
 			(
 				p = lerp p1 p2	(curve.keys[j].time as float/(ticksperframe as float)); 
 				p.z = curve.keys[j].value * zscale;
 				setvert mesh vi p;
 				vi += 1;
 			)
 		)	
 		
 -- geo faces			
 		
 		fi = 1;	-- face incrementer
 		si_offset = 0;
 		ei_offset = nsegs_p1;
 		for i = 1 to 4 do
 		(	
 			for j = 1 to nsegs  do
 			(
 				s1 = si_offset + j;
 				e1 = ei_offset + j;
 				s2 = s1 + 1;
 				e2 = e1 + 1;
 				
 				setface mesh fi [e1,e2,s1]
 				mxssetedgevisflags mesh fi #{1,3}
 				fi += 1;
 				setface mesh fi [s2,s1,e2]
 				mxssetedgevisflags mesh fi #{1,3}
 				fi += 1;
 			)
 			si_offset += nsegs_p1;
 			ei_offset += nsegs_p1;
 			if i == 3 then ei_offset = 0;
 		)	
 		
 		if mapCoords then
 		(	
 			if contUV then
 			(	
 			
 -- allocate mapping			
 			
 				ntverts = nverts + nsegs_p1;
 				meshop.setMapSupport mesh 1 true;
 				meshop.setNumMapVerts mesh 1 ntverts;
 				meshop.setNumMapFaces mesh 1 nfaces; 	
 
 -- mapping verts			
 			
 				tlen = 2 * (width + height);
 				vcoords = #(0.0, width/tlen, (width + height)/tlen, (2.0 * width + height)/tlen, 1.0);
 				ucoords = GetUCoords nsegs;
 				vi = 1;
 				for i = 1 to 5 do -- no wrap around with uv verts
 				(
 					for j = 1 to nsegs_p1 do
 					(
 						meshop.setmapvert mesh 1 vi [ucoords[j], vcoords[i],0.0];
 						vi += 1;
 					)
 				)	
 			
 -- mapping faces	
 
 				fi = 1;	
 				si_offset = 0;
 				ei_offset = nsegs_p1;
 				for i = 1 to 4 do
 				(	
 					for j = 1 to nsegs  do
 					(
 						s1 = si_offset + j;
 						e1 = ei_offset + j;
 						s2 = s1 + 1;
 						e2 = e1 + 1;
 						meshop.setMapFace mesh 1 fi [e1,e2,s1]
 						fi += 1;
 						meshop.setMapFace mesh 1 fi [s2,s1,e2]
 						fi += 1;
 					)
 					si_offset += nsegs_p1;
 					ei_offset += nsegs_p1;
 				)	
 			)
 			else -- create mapping base on xy positions
 			(
 				ntverts = 4 * 2 * nsegs_p1;
 				meshop.setMapSupport mesh 1 true;
 				meshop.setNumMapVerts mesh 1 ntverts;
 				meshop.setNumMapFaces mesh 1 nfaces;
 				
 				ucoords = GetUCoords nsegs;
 				w_vcoords = GetVCoords nsegs true;
 				h_vcoords = GetVCoords nsegs false;
 				
 				vi = 1;
 				for i = 1 to 4 do
 				(	
 					for j = 1 to nsegs_p1 do
 					(	
 						if i == 1 or i == 3 then
 							vcoord =  w_vcoords[j];
 						else
 							vcoord =  h_vcoords[j];
 						meshop.setmapvert mesh 1 vi [ucoords[j], 0.5 + vcoord,0.0];
 						vi += 1;
 					)
 					
 					for j = 1 to nsegs_p1 do
 					(	
 						if i == 1 or i == 3 then
 							vcoord = w_vcoords[j];
 						else
 							vcoord = h_vcoords[j];
 						meshop.setmapvert mesh 1 vi [ucoords[j], 0.5 - vcoord, 0.0];
 						vi += 1;
 					)
 				)	
 
 				fi = 1;	
 				si_offset = 0;
 				ei_offset = nsegs_p1;
 				for i = 1 to 4 do
 				(	
 					for j = 1 to nsegs  do
 					(
 						s1 = si_offset + j;
 						e1 = ei_offset + j;
 						s2 = s1 + 1;
 						e2 = e1 + 1;
 						meshop.setMapFace mesh 1 fi [e1,e2,s1]
 						fi += 1;
 						meshop.setMapFace mesh 1 fi [s2,s1,e2]
 						fi += 1;
 					)
 					si_offset += nsegs_p1 * 2;
 					ei_offset += nsegs_p1 * 2;
 				)		
 			)	
 		)		
 		update mesh;
 	)
 	on update do doBuildMesh();
 	on buildmesh do doBuildMesh();
 )

profile editing options are on the right click menu btw.

Thanks for the response. But that seems a bit more complicated than I need. The frame is very simple at 13 polygons and all the values I need I can hard code, and honestly a lot of that is beyond me. I don’t really want the user to have to do any of the unwrap as the idea of the script is to quickly allow a modeler to create a simple picture frame that appears in a lot of buildings and move on. So even a simple unwrap will be good. This is part of a larger script by the way.

no probs, there maybe something there you can use, i’ve added a non distorting UV mapping option just to increase the complexity a bit

Without seeing all the code it is hard to diagnose. Replacing picture_frame here with $ and everything runs fine in 2014 SP3.

-Eric

Hey thanks for the responses, I’m looking at the code and I get that you’re changing the coordinates, but I’ve never really worked with meshes. I’ve been working with polys. Are you changing the coordinates of the faces and vertices? Are you doing the vertices to smooth out the face’s shape then move the faces?

I did run the unfold and the listener came up with actionMan.executeAction 2077580866 “40051” which if I run goes all the way up to the dialog box for unfold mapping. Anyway I could simply go through that, not show the box and make it start?

I attached my current code, its pretty slow and the connections aren’t working at the moment. This is my first script so be nice, but I’m good at taking criticism. lol

Hey thanks for the responses, I’m looking at the code and I get that you’re changing the coordinates, but I’ve never really worked with meshes. I’ve been working with polys. Are you changing the coordinates of the faces and vertices? Are you doing the vertices to smooth out the face’s shape then move the faces?

I don’t “move” anything. The mesh is built from scratch every time a parameter is changed. The general procedure is

calculate numverts and numfaces
create the a mesh with space allocated for the verts and faces (in this case as a simple object it’s created for us) so we just allocate the space needed with:


setNumVerts mesh nverts;
setNumFaces mesh nfaces;

then you set the vert position (in local coordinates)

setvert mesh vi p;

vi is the vert index which we increment as we step through each vert.
Next we have to create the faces, these are triangles that index into the vertex arrays. So we need to calculate the correct indices for each face

setface mesh fi [e1,e2,s1]

stepping through each face with fi. We also have to set edge visibility (makes it look like quads) but you could equally set smoothing group and material ID for faces here too.

We then repeat the process for mapping coords and mapping faces which work in exactly the same way but require slightly different handling depending on the requirement

ie in our case UV faces don’t usualy wrap around like geometry so we have extra run of verts to compensate.

Page 1 / 2