public void updateAllStates(WorkspaceState prevState, float t) { // t is used as the interpolation parameter. foreach (VisualElement element in this.elementStates.Keys) { VisualElementState curElementState = elementStates[element]; if (prevState.ElementExists(element)) { // Interpolate between states VisualElementState prevElementState = prevState.elementStates[element]; prevElementState.BlendStates(curElementState, t); } else { // Pop in from zero scale VisualElementState pseudoState = new VisualElementState(curElementState); pseudoState.SetStateScale(Vector3.zero); pseudoState.BlendStates(curElementState, t); } } foreach (VisualElement element in prevState.elementStates.Keys) { if (!this.ElementExists(element)) { // Disable VisualElementState prevElementState = prevState.elementStates[element]; VisualElementState pseudoState = new VisualElementState(prevElementState); pseudoState.SetStateScale(Vector3.zero); prevElementState.BlendStates(pseudoState, t); } } }
public VisualElementState(VisualElementState newState) { this.element_ = newState.GetStateElement(); this.statePosition_ = newState.GetStatePosition(); this.stateScale_ = newState.GetStateScale(); this.stateRotation_ = newState.GetStateRotation(); this.stateMaterial_ = newState.GetStateMaterial(); }
public WorkspaceState(WorkspaceState prevState) { this.elementStates = new Dictionary <VisualElement, VisualElementState>(); foreach (VisualElement element in prevState.elementStates.Keys) { VisualElementState elementState = prevState.elementStates[element]; VisualElementState newElementState = new VisualElementState(elementState); this.elementStates.Add(element, newElementState); } }
public void SetColorSelected(Material mat) { foreach (VisualElement element in this.selectedVisualElements_) { // set the material for state & the gameobject VisualElementState state = this._curState.elementStates[element]; state.SetStateMaterial(mat); element.GetComponent <Renderer>().material.CopyPropertiesFromMaterial(mat); } }
public void UpdateState() { VisualElementState state = this.workspace.GetCurrentState().elementStates[this]; state.SetStatePosition(this.gameObject.transform.position); state.SetStateScale(this.gameObject.transform.lossyScale); state.SetStateRotation(this.gameObject.transform.rotation); Material mat = new Material(this.gameObject.GetComponent <Renderer>().material); state.SetStateMaterial(mat); }
// This functions updates/adds new element as a state in the workspace. public void AddState(VisualElement element) { VisualElementState newState = new VisualElementState(element); if (!this.ElementExists(element)) { elementStates.Add(element, newState); } else { elementStates[element] = newState; } Debug.Log("Element count: " + elementStates.Count); }
// This function assigns a blend of this state with another. public void BlendStates(VisualElementState secondState, float t) { // A t-value of 0 will assign the state stored in the caller. // A t-value of 1 will assign the state passed into the function. // A t-value between 0 and 1 will assign a blend of the two states. if (t >= 0 && t <= 1) { // Interpolate the transform values and assign them. Vector3 secondPosition = secondState.GetStatePosition(); Vector3 secondScale = secondState.GetStateScale(); Quaternion secondRotation = secondState.GetStateRotation(); Vector3 lerpedPosition = Vector3.Lerp(this.statePosition_, secondPosition, t); Vector3 lerpedScale = Vector3.Lerp(this.stateScale_, secondScale, t); Quaternion lerpedRotation = Quaternion.Slerp(this.stateRotation_, secondRotation, t); element_.gameObject.transform.position = lerpedPosition; element_.gameObject.transform.localScale = lerpedScale; element_.gameObject.transform.rotation = lerpedRotation; // Lerp the main colors of each material and assign it. Renderer rend = element_.GetComponent <Renderer>(); rend.material.Lerp(this.stateMaterial_, secondState.GetStateMaterial(), t); } }