Hey,
Working on a project importing splines (PolyCurves obj) from Rhino to Unity3D. We are using the latest .librhino3dm_native and .Rhino3dm plugins.
Expected result: polyCurve.TangentAt(i) outputs the absolute vector value.
Actual result: polyCurve.TangentAt(i) outputs only the unit vector, correctly.
Is there any scalar method I can call from polyCurve.TangentAt(i).xxx so that I can multiply it with unit vector? Thank you!
Our code C#
using UnityEngine;
using UnityEditor.AssetImporters;
using Rhino.FileIO;
using Rhino.Geometry;
using System;
using Unity.Mathematics;
using UnityEditor;
using UnityEngine.Splines;
using Quaternion = UnityEngine.Quaternion;
[ScriptedImporter(1, "3dm")]
public class Rhino3dmImporter : ScriptedImporter
{
public override void OnImportAsset(AssetImportContext ctx)
{
File3dm file = File3dm.Read(ctx.assetPath);
GameObject gameObject = new GameObject(System.IO.Path.GetFileName(ctx.assetPath));
gameObject.AddComponent<SplineContainer>();
var container = gameObject.GetComponent<SplineContainer>();
gameObject.transform.localPosition = Vector3.zero;
gameObject.transform.localRotation = Quaternion.Euler(0,0,0);
Selection.activeObject = gameObject;
ctx.AddObjectToAsset(gameObject.name, gameObject);
ctx.SetMainObject(gameObject);
// Objects Splines, Solids, Surfaces
foreach (var obj in file.Objects)
{
// Only Splines
if (obj.Geometry is PolyCurve curve)
{
Debug.Log(curve.Domain.Length + " Length");
for (int i = 0; i < curve.Domain.Length; i++)
{
var vectorPositionAt = new float3((float)curve.PointAt(i).X, (float)curve.PointAt(i).Z, (float)curve.PointAt(i).Y);
var vectorTangentAt = new float3((float)curve.TangentAt(i).X, (float)curve.TangentAt(i).Z, (float)curve.TangentAt(i).Y);
container.Spline.Add(new BezierKnot(vectorPositionAt,
-vectorTangentAt,
vectorTangentAt,
quaternion.identity));
if (i + 1 == (int)curve.Domain.Length)
{
var vectorPositionAtEnd = new float3((float)curve.PointAt(i+1).X, (float)curve.PointAt(i+1).Z, (float)curve.PointAt(i+1).Y);
var vectorTangentAtEnd = new float3((float)curve.TangentAt(i+1).X, (float)curve.TangentAt(i+1).Z, (float)curve.TangentAt(i+1).Y);
container.Spline.Add(new BezierKnot(vectorPositionAtEnd,
vectorTangentAtEnd,
-vectorTangentAtEnd,
quaternion.identity));
}
}
}
}
}
}
Photos: