Creating rope path via script - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html) +--- Thread: Creating rope path via script (/thread-233.html) |
Creating rope path via script - leonrdo - 14-11-2017 Hello, I was wondering there's a way to create the rope curve/shape (bezier or catmull) via script? Like, if I want to make a spiral shape or something else at runtime. Thanks in advance RE: Creating rope path via script - phoberman - 15-12-2017 + 1 Would be very interested in this as well. RE: Creating rope path via script - josemendez - 15-12-2017 (15-12-2017, 02:20 AM)phoberman Wrote: + 1 Hi! Obi/Scripts/Utils/ObiRopeHelper.cs is a good example on how to generate a rope in a fully procedural way. cheers! RE: Creating rope path via script - phoberman - 16-12-2017 Hi Jose – That doesn't really answer the question, which wasn't about generating the entire rope procedurally, but just about creating a specific and precise curve (like a spiral) for a rope. The ObiRopeHelper.cs script only creates an extremely simple rope with two control points. Maybe we should be able to figure out how to make a more complex shape from that script, but it's certainly not obvious, and a more relevant example would be appreciated (and if it's so easy to do, then it shouldn't be difficult to whip up an example). I would also be interested in knowing whether it would be possible to import an existing spline, and if it isn't, I would like to put that forward as a feature request. Certainly part of the problem is that the tools provided for editing Obi Catmull Rom Curves and Obi Bezier Curves are minimal and clunky. For instance, you can't place a control point at any specific location on the curve; you can only click 'Add Control Point' and work with whatever you get. RE: Creating rope path via script - josemendez - 16-12-2017 (16-12-2017, 02:57 AM)phoberman Wrote: Hi Jose – Hi! The sample script uses a spline with just 2 control points, but creating a more complex rope is just a matter of adding additional control points to the spline, like this: path.controlPoints.Add(localStart-direction); path.controlPoints.Add(localStart); path.controlPoints.Add(midPoint1); path.controlPoints.Add(midPoint2); . . . path.controlPoints.Add(midPointN); path.controlPoints.Add(localEnd); path.controlPoints.Add(localEnd+direction); Note that the first and last control points are duplicated, because bezier curves need two endpoints to control curvature. Later today I´ll give you a more complex example. Edit: For instance, to create a spiral-shaped rope, you do something similar to this: Code: float radius = 1; Inserting this code in the ObiRopeHelper.cs script in place of lines 36-39, yields this: Regarding your question about importing existing splines, it is not currently supported and probably won't ever be as it is trivial to implement it yourself. Also there's lots of potential formats that people would want to import and it's not clear which ones would have to be supported, so it's a matter best left to each user and his/her specific needs. Importing a spline involves reading whatever file format you're interested in and adding the control point values to the path, as I just did in the example above. For instance, if you had a .obj-like spline format that consisted of 3 floating point values per line in a plain text file, you'd: read each line of the file and then append the 3 values (x,y,z coords) as a new a control point. Do this in a loop until you reach the end of the file, and you're done (probably in less than 10 lines of code). We are however working in improving the existing editor spline tools, as we are well aware of their shortcomings. Let me know if you need further help. cheers! RE: Creating rope path via script - phoberman - 17-12-2017 Jose – Huge thanks for the detailed example! I can't tell you how much I appreciate it. - pH RE: Creating rope path via script - leonrdo - 10-01-2018 Sorry for inactivity on the post, this is exactly what I was looking for Jose, thanks for replying, as usual hehehe |