Example #1
0
        /// <summary>
        /// Assign a new system definition to this behavior.
        /// </summary>
        /// <param name="newSystemObject"></param>
        public void SetSystem(LSystemObject newSystemObject)
        {
            systemObject = newSystemObject;
            if (systemObject != null)
            {
                steppingHandle?.Dispose();
                var globalParams = GetComponent <ILSystemCompileTimeParameterGenerator>();
                if (globalParams == null)
                {
                    steppingHandle = new LSystemSteppingHandle(systemObject, true, this);
                }
                else
                {
                    steppingHandle = new LSystemSteppingHandle(systemObject, false, this);
                }
                steppingHandle.OnSystemStateUpdated += LSystemStateWasUpdated;
            }
            OnSystemObjectUpdated?.Invoke();

            ResetState();
        }
        public void InitializeWithSpecificSystem(LSystemObject systemObject)
        {
            if (turtle != null)
            {
                turtle.Dispose();
            }
            if (systemObject == null)
            {
                return;
            }
            if (!operationSets.Any(x => x is TurtleMeshOperations))
            {
                // don't create an interpretor if there are no meshes. no point.
                return;
            }
            if (systemObject.compiledSystem == null)
            {
                // compiles so that the custom symbols can be pulled out
                // TODO: extract custom symbols w/o a full system compilation
                systemObject.CompileToCached(silent: true);
            }
            var volumetricWorld = GameObject.FindObjectOfType <OrganVolumetricWorld>();
            var damageWorld     = volumetricWorld.damageLayer?.effects.OfType <VoxelCapReachedTimestampEffect>().FirstOrDefault();

            turtle = new TurtleInterpretor(
                operationSets,
                new TurtleState
            {
                transformation = Matrix4x4.Scale(initialScale),
                thickness      = 1f,
                organIdentity  = new UIntFloatColor32(0)
            },
                systemObject.linkedFiles,
                systemObject.compiledSystem.customSymbols,
                volumetricWorld,
                damageWorld
                );
        }