Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Placing objects on volume
#1
Hi !
I wrote this code to place objects on my spline volume :
Code:
CurvySpline spline = GetComponentInParent<CurvySpline>();
CurvyGenerator cg = transform.parent.GetComponentInChildren<CurvyGenerator>();
CGDataReference m_Volume = new CGDataReference(cg.GetComponentInChildren<BuildShapeExtrusion>(), "Volume");
CGVolume m_VolumeData = m_Volume.GetData<CGVolume>();


Vector3 p = spline.Interpolate(tfPosition);
Vector3 up = spline.GetRotatedUp(tfPosition, 0);
Vector3 fwd = spline.GetTangent(tfPosition);

if(crossTfPosition != 0 && m_VolumeData != null)
{
     m_VolumeData.InterpolateVolume(tfPosition, crossTfPosition, out p, out fwd, out up);
}
transform.localPosition = p;
transform.localRotation = Quaternion.LookRotation(fwd, up);

So basically when crossTfPosition > 0, I'm searching a position on the volume, else I'm just taking the position on the spline (as crossTF 0 is on my spline).
When tfPosition is 0 or 1, I get the same position distance on spline using spline.Interpolate() and volume.InterpolateVolume(). But for any values in between, the position distance is totally different. It's like the tfPosition is stretched or not normalized in one of that functions.

Can you tell me if my code is correct, if there is a better way to do it and what could be the issue with the TF calculation ?

Thanks for support !
regards,
Anthony
Reply
#2
Hi,

The difference in the position returned by Interpolate and InterpolateVolume does not seem to be caused by a mistake in your code, but is probably an issue in Curvy itself. I will take a deeper look at this soon.

Meanwhile, some remarks:
- you can optimize your code by computing p, up, and fwd only in the else section of your if. In your current code, when crossTfPosition != 0 you end up computing these vectors twice, once through the spline and then through the volume
- was there any reason that made you code your own object placing code instead of using a Volume Spots CG module?

Have a nice day and happy new year
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#3
After a deeper look, here is my answer:
The spline.Interpolate method takes as an input a TF. A TF is not equally distributed on a spline. Please read this to learn more about it.
On the other hand, m_VolumeData.InterpolateVolume takes a value between 0 and 1 that is proportional to the length.

This difference beetween the two is already handled by the Volume Spots CG module, so using it will solve your issue. But if you have any reason to not use the Volume Spots module, simply replace the first parameter of your InterpolateVolume call by this:
Code:
spline.TFToDistance(tfPosition) / spline.Length

Also, on a different subject, if you are using Curvy 5.0.0, you will notice a compiler warning telling you that GetRotatedUp is obsolete and will be removed in a future update. Just inline this method in your own script to solve this. By inlining it, you will also benefit from the side effect which is that you can avoid computing the tangent twice.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#4
Hi Aka,
Thanks for the explaination and solution. I thought TF was equally distributed in any case!

Regarding the script, I needed a more custom object placement system with custom grid and pattern options.

Thanks again for you very fast reply and happy new year Wink
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Method of scattering objects along spline joebain 1 3 11-26-2024, 03:20 PM
Last Post: _Aka_
  Duplicate Volume references become null joebain 5 33 11-18-2024, 10:46 AM
Last Post: joebain
  making objects solid cielpandapie 1 3 10-18-2024, 12:17 AM
Last Post: _Aka_
  Nested Spline Volume Spot Instantiation merobbins5 3 7 07-26-2024, 09:58 AM
Last Post: _Aka_

Forum Jump: