grasshopper C# 中:
就是我发现transform的命令好像除了对该变量作用外,还会对所有赋值该变量的其他变量同时作用……这个会导致我没法再继续使用transform之前的变量的值了(详情在gh文件里)
就跟平时了解到的数值替换的思路不一样,比如正常情况应该是:
b = brepA;
a = b;
b.Transform;
结果应该是:
a = brepA;
b = brepTrans;
但现在是:
a = brepTrans;
b = brepTrans;
这样的话我像继续用brepA的话就没法用了,除非重新用函数再生成一个
c = brepA;
现在我采用的方法就是重新用函数生成一个新的变量,,但还是想搞明白为啥transform会有这种连锁反应……
private void RunScript(Transform Trans, ref object A, ref object B, ref object C, ref object D)
{
//Trans 是一个输入的旋转90°的transform类型的值
CreateObject T = new CreateObject();
Mesh meshSample = new Mesh();
Mesh meshSample2 = new Mesh();
Mesh meshSample3 = new Mesh();
Mesh meshSample4 = new Mesh();
T.GetBox(meshSample);//创建mesh三棱锥(A)
A = meshSample;
meshSample2 = meshSample;//将meshSample(A)赋值给meshSample2(B),
meshSample2.Transform(Trans); //对meshSample2(B)进行旋转指令,但同时meshSample(A)也随着进行了旋转指令
B = meshSample2;//
T.GetBox(meshSample3);//独立创建mesh三棱锥(C)
T.GetBox(meshSample4);//独立创建mesh三棱锥(D)
meshSample4.Transform(Trans);//非赋值的transform对D有影响但对C没有影响
C = meshSample3;
D = meshSample4;
}
// <Custom additional code>
class CreateObject
{
public void GetBox(Mesh meshResult) //创建一个三棱锥mesh
{
meshResult.Vertices.Add(-10, -20, 0);
meshResult.Vertices.Add(-5, -35, 0);
meshResult.Vertices.Add(10, -25, 0);
meshResult.Vertices.Add(0, -25, 20);
MeshFace mf1 = new MeshFace(0, 1, 3);
meshResult.Faces.AddFace(mf1);
MeshFace mf2 = new MeshFace(1, 2, 3);
meshResult.Faces.AddFace(mf2);
MeshFace mf3 = new MeshFace(2, 0, 3);
meshResult.Faces.AddFace(mf3);
MeshFace mf4 = new MeshFace(0, 2, 1);
meshResult.Faces.AddFace(mf4);
}
}
// </Custom additional code>
}
Transform Debug.gh (9.1 KB)