Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / 3dsMAX spline to AGK bezier [source]

Author
Message
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 12th Feb 2016 04:12 Edited at: 17th Feb 2016 03:31


0. Download attachments
1. Goto: \3dsMAX
2. Copy "save_agkxml.ms" to your /scripts folder of your 3ds max
3. Run script
4. Select path
5. Open MaxScript Listener
6. Enter: exportasxml("your_path_name")
7. Hit Enter
8. Find path files where you placed your script
9. Copy paths to agk
10. Use 3dbenzier Engine to display them

Enjoy!

Mirror: movies.online-arts.de/Files/3dsMAXsplineToAGK.zip (OLD)

3ds_to_AGK_with_tangents.ms - Current 3dsMax script


[/url]

Attachments

Login to view attachments
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 12th Feb 2016 09:53
Nice, what does it actually produce? Functions to reproduce the path or some kind of object?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 12th Feb 2016 09:58
Is there a Blender alternative? It might make it a little more accessible. $185 per month for 3DSMax is a LOT for most hobbyist programmers.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 12th Feb 2016 11:02
Quote: "Is there a Blender alternative? It might make it a little more accessible"


If you can export the points, you can use this set of functions to make the Spline data. All you need after that is to join the dots with 2D lines.
https://forum.thegamecreators.com/thread/215963#msg2574770
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 12th Feb 2016 19:23 Edited at: 16th Feb 2016 02:28
Quote: "what does it actually produce? Functions to reproduce the path or some kind of object?"

Currently, it produces a list of points. It would be possible to add the curve points once I get more efficient in benzier calculations.
Quote: ""Is there a Blender alternative? It might make it a little more accessible""

Hmm sorry I don't have skills in writing scripts for blender right now But there should be a script, that could save the points of the spline and export them to a readable format. I think I will write a blender script, when I manage to add bend points to the benzier curve library, but I still have to learn more about the process of benzier calculation.



Custom spline library with 2 tangents

[/url]
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 16th Feb 2016 04:04 Edited at: 16th Feb 2016 04:09
UPDATE:

I have managed to add tangent information to the export script!
Currently it does not work so well, when I try to import it to AppGameKit, because I made quite a mess inside some functions, but the 3dsmax export script does work quite well.
The errors in the import can be managed very well, once I have the time for that.










3ds_with_tangents.ms

3ds Max exporter for knot position, InVec and OutVec




Coming script features (once the importer is working correctly):
*Closed spline or not?

[/url]
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 16th Feb 2016 08:42
Quote: "*Closed spline or not?"


This isn't too difficult. You simply make the in Vector of the first point into the out Vector of the last point. I think it is a good addition to have, it allows you to make racing circuits etc.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 16th Feb 2016 15:04
That`s right I will manage to add this. I hope, that this export script will manage each spline exactly like in 3dsmax. Combined with a library that can build meshes from spline data we could actually build roads on the coming terrain system. Or a distribution system like a row of buildings or streetlights along the lane.

If I heard on your tutorial, it would work right now but I changed the logic in order to get "... something else" and adjusted the InVec and OutVec to the knot points, instead to the benzier between two knots. (I had quite problems with the logic of the non-existing curve)

PS: Does anyone know, if .ms scripts are working with Maya or other software? (Maybe there are converter?)


[/url]
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 16th Feb 2016 15:21
Quote: " Combined with a library that can build meshes from spline data we could actually build roads on the coming terrain system. Or a distribution system like a row of buildings or streetlights along the lane."


You have the same dream as I do This is as far as I have got so far with a randomly generated closed spline...

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 16th Feb 2016 21:34 Edited at: 16th Feb 2016 21:55
I made something similar in DBP a while ago, I try to find that But the basic idea is awesome!


Aaaand by the way:


It works! - 100% , thanks to your tutorial I managed to rewrite my previous calculations and tada!
3dsMAX spline to AppGameKit, no problem now!

Before the public release, I have to add some functions to this library, optimize the current code and add some flags to the .ms exporter

BatVink, do you know how to get the total length of a curve? My current method is to rasterize the curve and add the distances between the points on the curve,
but there should be a faster, a direct way. (This will be done next, now I will work on the exporter again)

[/url]
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 16th Feb 2016 22:31
Quote: "It works! - 100%"

Congratulations!

Quote: "BatVink, do you know how to get the total length of a curve?"


In a word...no
The nearest I could get is to measure the distances between the points I make in the array, and add them together to get an approximate length. It will always be too short, but when you compare segments, it should be fairly relative to each other.

My biggest problem is speed. My demo takes the same time to travel along each segment. So it will speed up and slow down, especially on tight corners. Perhaps I should do the measurements I mentioned in the last paragraph, and use this as a speed multiplier. It won't be perfect, but it could be close enough for games calculations.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 16th Feb 2016 22:51 Edited at: 17th Feb 2016 04:42
My research from the internetz:
Quote: "The arclength of a Bézier curve can be very complicated; for a quadratic Bézier you have a complicated expression involving logarithms/inverse hyperbolic functions, and for a cubic Bézier one now requires elliptic integrals."

Quote: " The exact length of a cubic spline is very difficult to find. Instead, for most uses, a chorded approximation is easier. Typically, 100 chords will suffice and will be accurate to a fraction of a percent or better. "



I think I will die from this one
Source; http://math.stackexchange.com/questions/12186/arc-length-of-b%C3%A9zier-curves

More from hell: https://pomax.github.io/bezierinfo/#arclength
Maybe interesting: https://en.wikipedia.org/wiki/Abel%E2%80%93Ruffini_theorem
Even more: http://homepage.cs.uiowa.edu/~kearney/pubs/CurvesAndSurfacesArcLength.pdf

I think it would be enough to take the last position of the train on the track and calculate the distance to the current position of the train. I will see.
Another useful way is to create a Look UP table with the t# compared to the position of the point on the line. That is not the best solution, but the fastest

The current task is to get linear speed on a bezier curve.

[/url]
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th Feb 2016 10:48
Quote: "The current task is to get linear speed on a bezier curve."


Yes, my challenge too!
At the moment, I move from 0.0 to 1.0 in a linear fashion across the full curve. But if this is an arced track, then it will slow down in the middle, because the points are more dense on the arc.
I think the intermediate solution is to store the linear distance from one point to the next in the array. Then it can be precalculated and save CPU cycles at runtime. This would be used instead of 0.0 to 1.0.

Or, another idea....
Instead of the points in the array being 1 to 100, they might be something like this:
1, 2, 3, 4.1, 5.2, 6.3, 7.2, 8.1, 9, 10...
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 19th Feb 2016 08:16 Edited at: 19th Feb 2016 09:11
I will do some experiments here.

I ran in a funny behaviour of AGK:
once I try to resize a multi-dimensional array (by using dim on the array again) with a type inside a type
it will delete every information above array[x,0]. Still, hard coded array length will work.

SplineCurvePoints[spline,knots].anchor.x# - can't keep information of x# inside anchor once resized to match except of SplineCurvePoints[spline,0].anchor.x#

Can someone confirm this?

EDIT:

I found a work-around with the .length command.

To resize the first dimension: OA_SplineCurvePoints.length=OA_SplineCurvePoints.length+1
To resize the second dimension: OA_SplineCurvePoints[spline_id].length=OA_SplineCurvePoints[spline_id].length+1

[/url]
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th Feb 2016 09:11
Quote: "I found a work-around with the .length command."


That isn't a workaround, that is the correct way to do it in AGK2
You should also declare your arrays in the new format like this:

global myArray as integer[10]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 19th Feb 2016 09:42
This may seem like a minor niggle but could a mod please change then name of this thread from benzier to Bezier?
It would help a lot of people that perform a forum search for Bezier curves.
AGK V2 user - Tier 1 (mostly)
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 19th Feb 2016 10:32 Edited at: 19th Feb 2016 10:56
Scraggle is right. As I started the project, I thought it was called benzier
It is actually called bézier https://www.youtube.com/watch?v=a0vRIVNzvBs and I thought I heard a "n" in there



Current state:

Done:
Import multiple bézier curves from 3dsMax (as much as AppGameKit can handle)
Perfect alignment to meshes (also exported from 3dsMax as .obj)
Display path with 2d lines
Display bend vectors
Efficient code
3dsMAX export script with knot position/ bend vectors and a header with the name and closed/open state

Not done right now:
Linear speed
Open/Closed (should be around 2 lines of code at that state, but still not done, cause of the linear speed problem)
comments on most steps inside the code


[/url]
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 22nd Feb 2016 20:25
sweet, i have definite use for this!

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-11-25 09:33:51
Your offset time is: 2024-11-25 09:33:51