Notifications
Clear all

[Closed] Pipes Generator

Am I supposed to get an error in the sorting?

Also @Joker it seems that you used the same way i did after all for sorting the array, are you still looking for a better way or you are happy with it now?

1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

no… it will take long time. but if you try to do it for 100,000 item array it will take probably hours…

@Joker I see yeah I already switched my sorting function in my function library to the optimized version that Denis posted heh me and you had similar ways(although mine had the flaw of not returning 0). I have not had the time to open the file yet but I will as soon as I get home

@Denis I see, I did not get an error I was just wondering if that is what I should expect. I made a version of your test script you gave me so that is will return 0 and I can see now how much faster it is! thx for pointing that out Denis!

Do you guys see ways to improve upon my post ‘comment 101’. If not I shall work on getting that implemented as an option to build pipes towards target and/or free flow (current system)

it’s not about fast or slow. your previous function was just wrong. every qsort comparison function HAS TO return 0 for equal items, negative value less or equal -1, and positive value greater or equal 1.
otherwise for some combination of items in array the qsort function might never end.

Understood! good to know.

you don’t need collect and after that sort distances. you can find the minimum distance in the same loop:


   (
   	local pipeNodes = #($pt_start_01,$pt_start_02,$pt_start_03)
   	local rots = #(-90,0,90,180)
   	local trgt = $target
   	struct ThePoint (node, dist, angle)
   	
   	fn getBestRotation block target step:45 =
   	(
   		local end = block.children[1]
   		local origin = block.transform
   		local dist = distance end target, best = 0
   		for angle=0 to 360 by step do 
   		(
   			block.transform = prerotatez block.transform step
   			if (d = distance end target) < dist do
   			(
   				dist = d
   				best = angle
   			)
   		)
   		block.transform = prerotatez origin best
   	)
   
   	exPipes = #()
   	clearlistener()
   	
   	for i = 1 to 10 do (
   		_thePipe = pipeNodes[random 1 pipeNodes.count]--random pipe
   		
   		if i == 1 then 
   		(
   			maxOps.cloneNodes _thePipe expandHierarchy:true cloneType:#copy actualNodeList:&refPipes newNodes:&newPipes
   			pipeCtrl = newPipes[1]
   			pipeCtrl.transform = copy (prerotatez  (matrix3 1) rots[random 1 rots.count])
   			ends = for o in newPipes where findString o.name "end" != 0 collect o
   			join exPipes newPipes[2]
   		)
   		else
   		(
   			maxOps.cloneNodes _thePipe expandHierarchy:true cloneType:#copy actualNodeList:&refPipes newNodes:&newPipes
   			pipeCtrl = newPipes[1]
   			tm = exPipes[exPipes.count].transform
   			pipeCtrl.transform = copy tm
   			--fnRotateTowardsTarget pipeCtrl
   			getBestRotation pipeCtrl trgt step:45
   			join exPipes newPipes[2]
   		)	
   	)
   	print exPipes.count
   )
   

i could miss something but i hope the idea is clean.

i fixed some bug in code above… finally we have to rotate origin transform

another thought. i’m not sure that checking the only distance is enough. we have also to check ‘direction’ of end point. better pointing of current end point to the target will help next block be closer.
that means every block has to look at the target the best way for the next block.

How would that be factored into the function?
Doing some sort of ray off the z-axis of the pipe’s end helper?
Using that see if it is even pointing remotely in the right direction of the target object?

1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

you have to compare angle between point direction and vector from point position and target position (dot product of normalized vectors).

Alright…sounds simple. We will see.
I’m going to see how to get the rotation part implemented first and then take a stab at the additional vector methods you have mentioned here.

Page 10 / 12