Notifications
Clear all

[Closed] How to optimize this code

Can someone tell me the answers to these 3 questions (Q1,Q2,Q3)
or tell me where I can find a better explanation than the MaxScript Help?

[u][i][b]VData Channels Methods[/b][/i][/u]
The number of vertex data channels can be set from [b]0[/b] to [b]100[/b].
The first ten channels for Discreet's (ei. Autodesk's) use only.
[b]polyop.setVDataChannelSupport <Poly poly> <int vdChannel> <boolean support>[/b]
[u]channel 1:[/u] Soft Selection
[u]channel 2:[/u] Vertex weights (for NURMS MeshSmooth)
[u]channel 3:[/u] Vertex Alpha values
[u]channel 4:[/u] Cornering values for subdivision use
----------------------------------------------------------------------------------------------------------
[b]Q1:[/b] [i]Which would be other channels (5-10)?[/i]
[b]Q2:[/b] [i]Does this mean that user can't use first 10 channels because are already reserved?

[/i]———————————————————————————————————-

EData Channels Methods

The number of edge data channels can be set from 0 to 10.
The first two channels for Discreet’s ei. Autodesk’s) use only.
channel 1: edge knot data
channel 2: edge crease data
polyop.setEDataChannelSupport <Poly poly> <int edChannel> <boolean support>
———————————————————————————————————-
Q3: Is there a polygon method (PData or something similar)?
———————————————————————————————————-

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0
Q1: first 10 channels used by max (4 reserved, and other 6 can be changed by max for any reason)

Q2: you can use channels 11-100
Q3: EData the same as VData – one float per item (vertex or edge)

Ok Denis, thanks for your response.
Have you received today p-message that I sent you?

yes, i did.

Code is not perfect but do the job.
With this tool is easy to recreate loft object, align bone to the spline(guide) inside volume
or for spline UVW mapping.
What do you think about?

i’ve replicated all these shapes with a function that is similar to my extrudeEdge but using of bevel faces instead of extrude. you have to do several bevels with some specific setting for height and outline values… that makes any shape of the wrinkle.

1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

Now that you explained to me how to use the [color=YellowGreen]Data Channels Methods[/color], all the rest is easy to achieve. I am planning to use “bevel” only for #2 and #4 type. For #1 and #3 type extrudeEdge FN and “crease” edges. I think that is OK.

After a small change of Denis function i’m little bit closer to the desire look
of edge deformation.
Now i need to select extruded edges and apply creasing but i have a problem with
ConvertSelectionToBorder” operation.


 	fn moveVertLocXY obj vertIdx rand =
 	(
 		movevert = polyOp.moveVert
 		norm = matrixFromNormal (getNormal obj.mesh vertIdx)
 		in coordsys norm movevert obj vertIdx (random -rand rand)		
 	)
 	fn extrudeEdges obj edgeExtrudeWidth:1 edgeExtrudeHeight:-2 rand:[2,2,0] divideIdx:2 = 
 	(
 		edges = obj.selectededges as bitarray
 		if not edges.isempty do
 		(
 			vdChannel = 81
 			divideedge = polyOp.divideEdge
 			obj.edgeChamferSegments = obj.extrusionType = 1
 			obj.weldThreshold = edgeExtrudeWidth*4
 			polyOp.setVDataChannelSupport obj vdChannel on
 			verts = polyOp.getVertsUsingEdge obj edges
 			obj.constrainType = 2
 			for v in verts do moveVertLocXY obj v rand
 			for edge in edges do
 			(
 				for d = divideIdx to 1 by -1.0 do (divideedge obj edge (1 - 1/(d+1)))
 			)
 			edges = obj.selectededges as bitarray
 			verts = polyOp.getVertsUsingEdge obj edges
 			for v in verts do 
 			(
 				polyOp.setVDataValue obj vdChannel v v
 				moveVertLocXY obj v (rand/2)
 			)				
 			obj.constrainType = 0
 			faces = obj.faces as bitarray
 			polyOp.chamferEdges obj edges edgeExtrudeWidth
 			vertList = obj.verts as bitarray
 			obj.selectedfaces = facesToExtrude = (obj.faces as bitarray - faces) 
 			polyop.extrudeFaces obj facesToExtrude edgeExtrudeHeight
 			obj.GrowSelection selLevel:#Face
 			for v in verts do
 			(
 				vertsToWeld = #{}
 				for k in (obj.verts as bitarray - vertList) where (polyop.getVDataValue obj vdChannel k) == v do append vertsToWeld k
 				polyOp.weldVertsByThreshold obj vertsToWeld
 			)
 			polyop.freeVData obj vdChannel
 
 			--select sharp (extruded) edges (problematic part)
 			obj.selectedverts = polyOp.getVertsUsedOnlyByFaces obj obj.selectedfaces
 			obj.ConvertSelectionToBorder #Vertex #Edge
 			extEdges = obj.selectededges as bitarray
 			 -- i add this only for problem preview
 			max modify
 			subobjectLevel = 2
 		)
 	)
 with redraw off (extrudeEdges $)

I try another solution for ConvertSelectionToBorder problem and it’s works fine.
Just replace the line “obj.ConvertSelectionToBorder #Vertex #Edge” with this code:

extV = polyOp.getVertsUsedOnlyByFaces obj obj.selectedfaces
ve = polyOp.getEdgesUsingVert obj extVerts
ev = polyop.getEdgeVerts
extVCnt = extVerts.numberset
extE = #{}
for s in vertedges where ((extV-((ev obj s) as bitarray)).numberset== extVCnt-2) do append extE s
obj.selectededges = extE

poly edge border means an open edge… you don’t need it. i know you like to illustrate your question by a picture… could you show what edges you want to find?

Hi Denis
Sure

I already have selected polygons, which will later be assigned unique material ID,
but i need also to have selected top edge loop, and then i be able to assigne “crease value”
ei “obj.EditablePoly.setEdgeData 1 1.0”

Page 7 / 8