Notifications
Clear all

[Closed] Cobwebs – download

I added this to sample the amount of testing and i then stop it if the testing amount == the arr.count.


fn fnRandomLimited arr usedIdx =
(
	numItms = arr.count
	usedItm = arr[usedIdx]
	num = arr[usedIdx]
	testing = 0
	
	while num == arr[usedIdx] AND testing == numItms AND distance num usedItm <= disMin OR distance num usedItm >= disMax do
	(
		num = arr[random 1 numItms]
		testing += 1
	)
	print (distance num usedItm)
	return num
)

1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

Now is much better

Your script is really interesting and practical.
I usually practice to give my visual tests when
someone create something that is worth.
After all they are good for the presentation of your script.

Last test. JM initials.I’m go to sleep.
Cheers!

Very cool,
I’m back at it today. Condensing the code quite a bit and also adding more functionality.
We will hopefully be seeing a new version today.

I’ve gotta work on this while…loop. It’s causing me some issues still.

Are you saw my answer to you on scripspot?

Yeah that is not quite it.

Here check this out.

Take this script below and run it.
It has everything within the script for testing.
The while loop needs work.
I wrote in comments what it needs to do but it doesn’t seem to be working right with the distance and the limit on testing. I need it to not make a spline unless there are two valid points.

That way there will be a limit to the distance the splines can be created.


delete objects

--Create test shape
sp = splineShape()
for o = 1 to 2 do
(
	s = if o == 1 then 1 else -1
		
	for i = 1 to 4 do
	(
		idx = addnewSpline sp
		
		ptA = [20*i+(random 2 10),50*s+(random 2 10),0]
		ptB = [20*i+(random 2 10),75*s+(random 2 10),10]
		ptC = [20*i+(random 2 10),100*s+(random 2 10),0]
		addKnot sp idx #smooth #curve ptA
		addKnot sp idx #smooth #curve ptB
		addKnot sp idx #smooth #curve ptC
	)
)
	updateShape sp
	select sp


/*
CONDITIONS
- 1. Has to be within the distance limits Min/Max
- 2. Can not be a point 3 matching the currently being used point 3
- 3. Stop the while loop if it has tested all available options
*/

disMin = 50 
disMax = 80

fn fnRandomLimited arr usedIdx =
(
	numItms = arr.count
	usedItm = arr[usedIdx]
	num = arr[usedIdx]
	testing = 0
	
	while num == arr[usedIdx] AND distance num usedItm <= disMin OR distance num usedItm >= disMax OR testing == numItms do
	(
		num = arr[random 1 numItms]
		testing += 1
	)
	print (distance num usedItm)
	return num
)
clearlistener()

sp = $
midPts = #()
midPts = for idx = 1 to (numSplines sp) collect (getKnotPoint sp idx 2)

sp = splineShape()
for i = 1 to midPts.count do
(
	idx = addnewSpline sp
	
	ptA = midPts[i]
	ptB = fnRandomLimited midPts i
	addKnot sp idx #smooth #curve ptA
	addKnot sp idx #smooth #curve ptB
)
updateShape sp
select sp

 PEN

Cool idea.

Thanks Paul,
I should have a revision of this out later tonight. It’s coming along pretty good. It’s a rather simple idea. Could also be used for cables handing from the ceiling or where-ever.

Are you want to achive this:
–Find all splines with three knots and then draw connection splines between them.
–First knot(yellow spline) is the 2nd knot of blue 1st spline,
and 2nd knot (yellow spline) need to be placed to the other 2nd knot of blue spline and so on.
My english is limited but the image shows what i meant.

Yeah I got that part working but the problems lies in where it finds the second point to place the second knot of the spline.

I only want it to place a knot if the distance is within the distance limits, but at the same time is not placed on an currently being used position.

If that makes sense.

2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

are you looking for an algorithm for big number of points? your algorithm might be fixed but it will be slow even for 100 points.
i see another solution:
#1 collect all points which might be connected
#2 start from fist one and connect it to another in the distance interval
#3 when you do connection remove connected point from the list
#4 when there are no any available connection for first point go to the next free…

that also slow… if we are talking about >1000 points. the best solution to make it faster is to use 3D grid. there are couple samples on this forum…

but for the first algorithm i will try for write the loop…

(@denist)
Joined: 11 months ago

Posts: 0

something like this:


  (
 	delete objects 
 	sp = geosphere name:"points" radius:40 segments:16
 	mesh = snapshotasmesh sp
 	
 	t1 = timestamp()
 	
 	points = mesh.verts as bitarray
 	positions = for p in points collect (getvert mesh p)
 	connections = #()
 	
 	dmax = 10
 	dmin = 1
 	
 	fn getDistance base p = distance positions[base] positions[p]
 	fn makeConnect base p = append connections [base, p] 
 	
 	while not points.isempty do
 	(
 		base = undefined
 		for p in points do
 		(
 			if base == undefined then 
 			(
 				deleteitem points p
 				base = p
 			)
 			else 
 			(
 				d = getDistance base p
 				if not (d > dmax or d < dmin) do 
 				(
 					makeConnect base p
 					deleteitem points p
 				)
 			)
 		)
 	)
 	format "points:% connections:% time:%
" mesh.numverts connections.count (timestamp() - t1)
 	connections
 )	
  

pretty fast for ~2.5K points

Page 2 / 12