Notifications
Clear all

[Closed] Cobwebs – download

I noticed with spline creation I have to do a complete redraw in order for the substrands to be created. Is there a way I can avoid doing that process as it slows down the script quite a bit?

I’ll try to put together a basic sample script for quicker and easier testing. But if anyone happens to know the answer to this ahead of time id be glad to know.

1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

I don’t know about other way then update shape fn. It’s good that you use it outside for-loop.

Alright so I’ve got an improvement suggestion from Branko and this is what he has suggested as a base.

It’s definitely a quicker way of calculating random points on objects. I was wondering why this doesn’t work on a cylinder or any shape other than a sphere very well?
When it boils down to it I’m trying to find ways to improve the processing of the script. One case is finding if there is a faster way of generating pos/point3 values on the surface of objects.


start = timeStamp()

sph = geosphere radius:50 pos:[30,65,28]
cyl = cylinder radius:50 height:50 pos:[100,50,28]

objCol = #(sph,cyl)

surfacePosArr = #()

for obj in objCol do
(
	for i = 1 to 20 do
	(
		seed (random 100000 999999)
		centRay = ray obj.center (random (point3 1 1 1) (point3 -1 -1 -1)) 
		intRay = intersectRay obj centRay
		if intRay != undefined do 
		(
			append surfacePosArr intRay.pos
			-- create point helper to see intersection place (don't use in the script)
			point drawontop:on size:5 pos:intRay.pos wirecolor:(random (point3 0 0 0) (point3 255 255 255))
		)
	)
)
surfacePosArr -- intersection positions arr
print surfacePosArr

1 Reply
(@kickflipkid687)
Joined: 11 months ago

Posts: 0

Have you tried looking into RayMeshGridIntersect()? I use this on my ShrinkWrap script and its quite fast.

does it work to do just an update shape and not have to do viewport redraw. i feel like the completeredraw shouldn’t affect the spline creation no matter what.

Try this. I don’t know if normal modifier can solve the problem when
the object center outside the volume (bended cylinder). Then try with shell modifier.


delete objects
clearlistener()
max create mode
surfacePosArr = #()
sph = geosphere radius:50 pos:[30,65,28]
cyl = cylinder radius:50 height:50 pos:[100,50,28]
objCol = #(sph,cyl)
mody = Normalmodifier flip:on --1.solution
--mody = Shell outerAmount:0 innerAmount:0.01 --2.solution
with redraw of
(
	addModifier objCol normMod
	for obj in objCol do
	(
		for i = 1 to 20 do
		(
			seed (random 100000 999999)
			centRay = ray obj.center (random (point3 1 1 1) (point3 -1 -1 -1))
			intRay = intersectRay obj centRay
			if intRay != undefined do
			(
				append surfacePosArr intRay.pos
				-- create point helper to see intersection place (don't use in the script)
				point drawontop:on size:5 pos:intRay.pos wirecolor:(random (point3 0 0 0) (point3 255 255 255))
			)
		)
		format "objcenter = %
" intRay
	)
	deletemodifier objCol mody
)
surfacePosArr -- intersection positions arr
print surfacePosArr

If that is the case i may stick with the particle systems then.
I’ll see what other options their are out there.

Do you have any examples of it working with multiple objects? I’ve read around here on cgtalk as well as other online resources saying it was rather slow.

If the particles creations are fester then this code, then use the particles.

delete objects
  clearlistener()
  max create mode
  surfacePosArr = #()
  
  -- create scenr (every object in the scene will have center outside volume)
  obj1=text size:100 kerning:0 leading:0 pos:[0,0,0] text:"Jocker
Martini" wirecolor:blue
  addModifier obj1 (extrude amount:30)
  for c in 1 to 2 do
  (
  	obj2=Cylinder smooth:on heightsegs:10 height:360 radius:20 wirecolor:blue
  	addModifier obj2 (Bend BendAngle:180 BendDir:90)
  	obj2.pivot = obj2.center ; z = obj2.pos.z 
  	if mod c 2 != 0 then obj2.pos = [-230,0,z] else obj2.pos = [230,0,z] 
  )
  posTArr = #([-156.646,140,0], [-78.3232,140,0], [-5.72205e-006,140,0], [78.3232,140,0], [156.646,140,0], [156.646,-140,0], [78.3232,-140,0], [-5.72205e-006,-140,0], [-78.3232,-140,0], [-156.646,-140,0])
  for t in 1 to 10 do (Torus smooth:2 segs:24 sides:12 radius1:20 radius2:10 wirecolor:blue pos:posTArr[t])
  objCol = objects as array
  mody = Normalmodifier flip:on --1.solution
  --mody = Shell outerAmount:0 innerAmount:0.01 --2.solution
  with redraw off with undo off
  (
  	t1 = timestamp() ; m1 = heapfree
  	addModifier objCol mody
  	for obj in objCol do
  	(
  		for i = 1 to 300 do
  		(
  			seed (random 100000 999999)
  			centRay = ray obj.center (random (point3 1 1 1) (point3 -1 -1 -1))
  			intRay = intersectRay obj centRay
  			if intRay != undefined do
  			(
  				append surfacePosArr intRay.pos
  				-- create point helper to see intersection place (don't use in the script)
  				point drawontop:on size:5 pos:intRay.pos wirecolor:yellow	 --(random (point3 0 0 0) (point3 255 255 255))
  			)
  		)
  	)
  	deletemodifier objCol mody
  	format "time:% memory:%
" (timestamp() - t1) (m1 - heapfree)
  )
  surfacePosArr -- intersection positions arr
  --print surfacePosArr

on my laptop this is the execution time:
with point helpers (slower but better memory)
time:768 memory:1848L
without point helpers
time:365 memory:115344L

2 Replies
(@kickflipkid687)
Joined: 11 months ago

Posts: 0

My results were

time:1094 memory:736388L
(@gazybara)
Joined: 11 months ago

Posts: 0

Hi Matthew,
Very nice solution you post here.
The only thing that I do not like in my code is the memory issue
when i don’t create point helpers.
Do you know why this issue occurs?

To work with multiple objects, I have a fast attach method I got from here I think, that brings them into 1 mesh, then I run it on that. I’ve attached millions of polies worth into 1 mesh and it was fairly quick. Maybe a few seconds or so. But I’m not sure if that’s too slow for you or not.

Sorry, looking at it, I used MeshProjInterSect()

This is what I used:


  --Thanks to Lo of CGTalk for this one
  fn customAttach source nodes = 
  (
  	with undo off 
  	(
  		insertitem source nodes 1
  		local count = nodes.count
  		local att = meshop.attach			
  		local vertArr = for o in nodes collect o.numVerts
  		local sortedVertArr = deepcopy vertArr
  		for i = 1 to nodes.count-1 do if not keyboard.escpressed do
  		(
  		--	pb.value = 100 - nodes.count*100./count								
  			sort sortedVertArr
  			local a = findItem vertArr sortedVertArr[1]
  			vertArr[a]=-1
  			local b = findItem vertArr sortedVertArr[2]
  			local nA = nodes[a]
  			att nA nodes[b]
  			sortedVertArr[1]=vertArr[a]=nA.numVerts
  			deleteItem vertArr b
  			deleteItem sortedVertArr 2
  			deleteItem nodes b
  			--verts += nA.numverts								
  		)
  	)
  	nodes[1]
  )

  if (objs.count > 1) do
  (
  			st = timeStamp()
  			objs = (for o in objs collect snapshot o)
  			local otherObjs = for i = 2 to objs.count collect objs[i]
  			shrinkTargetMesh = customAttach objs[1] otherObjs
  )

  --GET Closest Hit
  fn tTclosestPointOnSurf surf refPos = 
  (
  	tTShrinkHitTest.closestFace refPos doubleSided:true
  	closestPoint = tTShrinkHitTest.getHitPos()
  	closestFace = tTShrinkHitTest.GetHitFace()
  	
  	return #(closestPoint,closestFace)
  )

  tTShrinkHitTest = MeshProjIntersect()
  tTShrinkHitTest.setNode shrinkTargetMesh
  tTShrinkHitTest.build()
  
  local mGFaceNorm = getFaceNormal
  local pGetVert = polyop.GetVert

  for vert in theVerts do   
  (
           local pnt = pGetVert theSel vert node:theSel
                                  
                                  --Use Best Guess Method
                                  if (tTProjDir == "Best Guess") do
                                  (
                                      local theHit = tTclosestPointOnSurf shrinkTargetMesh pnt
                                      local theNormal = mGFaceNorm shrinkTargetMesh (theHit[2] +1)
                                   )
  )
  

Thanks Branko and Matt for the examples.
I will check them out. I emailed bobo to see what his thoughts were on quick ways to generate positions on objects surfaces. I’ll post again and let you guys know what he said. It may be something we could all benefit from and see how fast it is as another option to the few you two posted already.

When can we expect this post?
I test again my code and I came to the conclusion that it is better to use Normal mod. then
Shell because Shell produces more polys and double the time. Are you try using particles to create 300 random positions. How is your time and memory?

Page 6 / 12