我正在尝试在Unity中使用compute-rhino3d的库进行开发,但是发现在不提供server的情况下无法运行。教程中只需要提供AuthToken即可。请问是”https://compute.rhino3d.com“这个云端server不能运行了吗?我必须要部署一个虚拟或本地的服务器才能够运行吗?
开发方法参考了官方给出的油管视频:https://www.youtube.com/watch?v=zUbm83ynn0Q
以及对应的.NET开发方法,同时也使用Python进行了auth token的测试,方法同样参考了官方教程视频
我在使用rhino3dm库时,没有遇到任何问题,但在尝试使用compute-rhino3d时遇到了以下问题:
- 官方教程显示,使用compute-rhino3d时,只需要提供对应的AuthToken,而server并不是必须的——我在使用Python进行尝试时,使用代码如下:
import rhino3dm
import random
import compute_rhino3d
import compute_rhino3d.Util
import compute_rhino3d.Curve
model = rhino3dm.File3dm()
compute_rhino3d.Util.authToken = "MyAuthToken"
def sample():
curves = []
for i in range(20):
pt = rhino3dm.Point3d(random.uniform(-10, 10), random.uniform(-10, 10), 0)
# print(pt)
model.Objects.AddPoint(pt)
circle = rhino3dm.Circle(pt, random.uniform(1, 4))
model.Objects.AddCircle(circle)
curve = circle.ToNurbsCurve()
curves.append(curve)
bcurves = compute_rhino3d.Curve.CreateBooleanUnion(curves)
for bcurve in bcurves:
print(bcurve)
model.Write('test.3dm', 5)
if __name__ == '__main__':
sample()
报错如下:
Traceback (most recent call last):
File “C:\Users\15167\PycharmProjects\RhinoTest\venv\lib\site-packages\requests\models.py”, line 971, in json
return complexjson.loads(self.text, **kwargs)
File “C:\Users\15167\AppData\Local\Programs\Python\Python310\lib\json_init_.py”, line 346, in loads
return _default_decoder.decode(s)
File “C:\Users\15167\AppData\Local\Programs\Python\Python310\lib\json\decoder.py”, line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “C:\Users\15167\AppData\Local\Programs\Python\Python310\lib\json\decoder.py”, line 355, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\15167\PycharmProjects\RhinoTest\Scripts\computeRhinoSample.py”, line 30, in
sample()
File “C:\Users\15167\PycharmProjects\RhinoTest\Scripts\computeRhinoSample.py”, line 22, in sample
bcurves = compute_rhino3d.Curve.CreateBooleanUnion(curves)
File “C:\Users\15167\PycharmProjects\RhinoTest\venv\lib\site-packages\compute_rhino3d\Curve.py”, line 581, in CreateBooleanUnion
response = Util.ComputeFetch(url, args)
File “C:\Users\15167\PycharmProjects\RhinoTest\venv\lib\site-packages\compute_rhino3d\Util.py”, line 35, in ComputeFetch
return r.json()
File “C:\Users\15167\PycharmProjects\RhinoTest\venv\lib\site-packages\requests\models.py”, line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
在使用Unity进行尝试时,我参考了上述油管教程中的内容,代码如下:
using System.Data;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using Rhino.Compute;
using Rhino;
public class TestCompute : MonoBehaviour
{
// Start is called before the first frame update
public string authToken;
public Material mat;
private Rhino.FileIO.File3dm model;
private float prevHeight, prevPipeRad, prevAngle, prevSegments;
private float height = 10;
private float pipeRad = 2;
private float angle = 30;
private int segments = 5;
void Start()
{
ComputeServer.AuthToken = authToken;
GenerationGo();
}
// Update is called once per frame
void Update()
{
}
// a function used to create 3d objects
private void GenerationGo()
{
model = new Rhino.FileIO.File3dm();
int num = 10;
float outerRad = 2f;
var curves = new List<Rhino.Geometry.Curve>();
for(int i = 0; i < num; i++)
{
var pt = new Rhino.Geometry.Point3d(0, 0, height / (num - 1) * i);
var circle = new Rhino.Geometry.Circle(pt, pipeRad);
// creat a polygon inside the circle
var polygon = Rhino.Geometry.Polyline.CreateInscribedPolygon(circle, segments);
var curve = polygon.ToNurbsCurve();
curve.Rotate(i * Mathf.Deg2Rad * angle, new Rhino.Geometry.Vector3d(0, 0, 1), new Rhino.Geometry.Point3d(0, 0, 0));
curve.Translate(new Rhino.Geometry.Vector3d(Mathf.Deg2Rad * angle * i, Mathf.Sin(Mathf.Deg2Rad * angle * i), 0) * outerRad);
// create from loft
curves.Add(curve);
// model.Objects.AddCurve(curve);
}
var brep = BrepCompute.CreateFromLoft(curves, Rhino.Geometry.Point3d.Unset, Rhino.Geometry.Point3d.Unset, Rhino.Geometry.LoftType.Normal, false);
foreach(var obj in brep)
{
model.Objects.AddBrep(obj);
}
// write the model into an obj file
string path = Application.dataPath + "/test.3dm";
model.Write(path, 5);
}
private void OnGUI() {
//lables
GUI.Label(new Rect(10, 10, 90, 20), "Height");
height = GUI.HorizontalSlider(new Rect(100, 15, 100, 20), height, 1.0f, 20.0f);
GUI.Label(new Rect(10, 30, 90, 20), "Radius");
pipeRad = GUI.HorizontalSlider(new Rect(100, 35, 100, 20), pipeRad, 0.5f, 5.0f);
GUI.Label(new Rect(10, 50, 90, 20), "Angle");
angle = GUI.HorizontalSlider(new Rect(100, 55, 100, 20), angle, 0.0f, 90.0f);
GUI.Label(new Rect(10, 70, 90, 20), "Segments");
segments = (int)GUI.HorizontalSlider(new Rect(100, 75, 100, 20), segments, 3, 8);
}
}
报错如下:
WebException: The remote server returned an error: (404) NOT FOUND.
System.Net.HttpWebRequest+d__240.MoveNext () (at <39d8670c8f6e487fb992d3c14d754584>:0)
— End of stack trace from previous location where exception was thrown —
System.Net.HttpWebRequest.GetResponse () (at <39d8670c8f6e487fb992d3c14d754584>:0)
Rhino.Compute.ComputeServer.PostWithConverter[T] (System.String function, Newtonsoft.Json.JsonConverter converter, System.Object[] postData) (at Assets/Plugins/RhinoCompute.cs:48)
Rhino.Compute.ComputeServer.Post[T] (System.String function, System.Object[] postData) (at Assets/Plugins/RhinoCompute.cs:21)
Rhino.Compute.BrepCompute.CreateFromLoft (System.Collections.Generic.IEnumerable`1[T] curves, Rhino.Geometry.Point3d start, Rhino.Geometry.Point3d end, Rhino.Geometry.LoftType loftType, System.Boolean closed) (at Assets/Plugins/RhinoCompute.cs:991)
TestCompute.GenerationGo () (at Assets/Scripts/TestCompute.cs:67)
TestCompute.Start () (at Assets/Scripts/TestCompute.cs:33)
请问我要怎么才能快速地开始使用compute-rhino3d?如果我可以的话我希望不用自己部署服务器。