08-01-2021, 08:38 AM
(07-01-2021, 09:55 AM)josemendez Wrote: Hi there,
You can create/modify blueprints at runtime, create/modify curve control points, and assign the blueprint to a rope at runtime. It's explained in detail (with sample code) here: http://obi.virtualmethodstudio.com/tutor...ctors.html
Don't expect to be able to modify existing ropes by changing their blueprint after it has been instantiated, though.
Just to make things clear: once you instantiate an actor, it is no longer tied to the blueprint in any way. Blueprints act as a "instruction manual" for the actor to know were to place particles and how to interconnect them using constraints. In this regard, they act just like prefabs: once you instantiate a prefab, modifying the prefab has no impact on the existing instances.
Control points only exist as a way to easily define a curve along which to place particles and define the rope's rest shape. Neither the curve nor its control points have any impact on existing ropes once their simulation has begun.
Thank you for your quick Answer!
I had a look at the Sample Code and tried it out.
But I still have two problems:
1. The Rod is in the Hirachy not under the Solver, so it is not assigned to the Solver and probably will not be simulated correctly.
2. The Blueprint is still not added to the Rod, so when I click play I don't see the Rod at all.
So that is the Code so far:
IEnumerator Start()
{
// create an object containing both the solver and the updater:
GameObject solverObject = new GameObject("solver", typeof(Obi.ObiSolver), typeof(Obi.ObiFixedUpdater));
Obi.ObiSolver solver = solverObject.GetComponent<Obi.ObiSolver>();
Obi.ObiFixedUpdater updater = solverObject.GetComponent<Obi.ObiFixedUpdater>();
// add the solver to the updater:
updater.solvers.Add(solver);
// create the blueprint: (ltObiRopeBlueprint, ObiRodBlueprint)
var blueprint = ScriptableObject.CreateInstance<Obi.ObiRodBlueprint>();
// Procedurally generate the rod path (a simple straight line):
blueprint.path.Clear();
blueprint.path.AddControlPoint(Vector3.zero, -Vector3.right, Vector3.right, Vector3.up, 0.1f, 0.1f, 1, 1, Color.white, "start");
blueprint.path.AddControlPoint(Vector3.one, -Vector3.right, Vector3.right, Vector3.up, 0.1f, 0.1f, 1, 1, Color.white, "end");
blueprint.path.FlushEvents();
// generate the particle representation of the rod (wait until it has finished):
yield return blueprint.Generate();
// create a rod:
GameObject rodObject = new GameObject("rod", typeof(Obi.ObiRod), typeof(Obi.ObiRopeExtrudedRenderer));
// get component references:
Obi.ObiRod rod = rodObject.GetComponent<Obi.ObiRod>();
Obi.ObiRopeExtrudedRenderer rodRenderer = rodObject.GetComponent<Obi.ObiRopeExtrudedRenderer>();
// load the default rod section:
rodRenderer.section = Resources.Load<Obi.ObiRopeSection>("DefaultRodSection");
// instantiate and set the blueprint:
rod.rodBlueprint = ScriptableObject.Instantiate(rodBlueprint);
// parent the cloth under a solver to start simulation:
rod.transform.parent = solver.transform;
}
Greetings
Mona