01-04-2015, 07:54 PM
Hi Jake,
I am trying to add another button to the spline tools that creates a Mesh Builder and Detaches in one step using the script below, but I am having a few problems.
Essentially the Detached gameobject seems to have its mesh filter uninitialised, even though the Mesh Filter Component says CurvyMesh.
Also, I want to delete the MeshBuilder object itself, only to be left with the detached GameObject which should have its own mesh.
Could you please tell me what is the best way to achieve this?
thanks
Nalin
[font][ToolbarItemInfo(Text = "Mesh-Bld-Nalin", Tooltip = "Create a Mesh Builder", Image = "meshbuilder,24,24",
Order = 83, AppliesTo = ToolbarItemTarget.Spline | ToolbarItemTarget.Group)]
public class TBSplineCreateMeshBuilderNalin : ToolbarItem
{
public override void Action()
{
var mb = SplinePathMeshBuilder.Create();
mb.Spline = (CurvySplineBase)Toolbar.Selection[0];
// Nalin - try to position it in the same place
mb.transform.position = Selection.activeGameObject.transform.position;
// Rectangle and other parameters
mb.UV = SplinePathMeshBuilder.MeshUV.Absolute;
mb.CapShape = SplinePathMeshBuilder.MeshCapShape.Rectangle;
mb.CapWidth = 6;
mb.CapHeight = 0.5f;
mb.gameObject.renderer.castShadows = false;
// stripy material
Material material = (Material)Resources.LoadAssetAtPath("Assets/Curvy/Examples/ScriptsAndData/Mat_BlackWhite.mat", typeof(Material));
mb.gameObject.renderer.material = material;
// create detach version because we don't need intermediate version
Transform detachedMB = mb.Detach();
Selection.activeGameObject = detachedMB.gameObject;
Undo.RegisterCreatedObjectUndo(Selection.activeGameObject, "Create Mesh Builder");
}
}[/font]
I am trying to add another button to the spline tools that creates a Mesh Builder and Detaches in one step using the script below, but I am having a few problems.
Essentially the Detached gameobject seems to have its mesh filter uninitialised, even though the Mesh Filter Component says CurvyMesh.
Also, I want to delete the MeshBuilder object itself, only to be left with the detached GameObject which should have its own mesh.
Could you please tell me what is the best way to achieve this?
thanks
Nalin
[font][ToolbarItemInfo(Text = "Mesh-Bld-Nalin", Tooltip = "Create a Mesh Builder", Image = "meshbuilder,24,24",
Order = 83, AppliesTo = ToolbarItemTarget.Spline | ToolbarItemTarget.Group)]
public class TBSplineCreateMeshBuilderNalin : ToolbarItem
{
public override void Action()
{
var mb = SplinePathMeshBuilder.Create();
mb.Spline = (CurvySplineBase)Toolbar.Selection[0];
// Nalin - try to position it in the same place
mb.transform.position = Selection.activeGameObject.transform.position;
// Rectangle and other parameters
mb.UV = SplinePathMeshBuilder.MeshUV.Absolute;
mb.CapShape = SplinePathMeshBuilder.MeshCapShape.Rectangle;
mb.CapWidth = 6;
mb.CapHeight = 0.5f;
mb.gameObject.renderer.castShadows = false;
// stripy material
Material material = (Material)Resources.LoadAssetAtPath("Assets/Curvy/Examples/ScriptsAndData/Mat_BlackWhite.mat", typeof(Material));
mb.gameObject.renderer.material = material;
// create detach version because we don't need intermediate version
Transform detachedMB = mb.Detach();
Selection.activeGameObject = detachedMB.gameObject;
Undo.RegisterCreatedObjectUndo(Selection.activeGameObject, "Create Mesh Builder");
}
}[/font]