public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { //print("number of locked particles: " + m_lockedParticlesMasses.Count); m_cntr = cntr; // cache local reference for Gizmo drawing if (m_triggerParent == null) { // have to potentially look for TriggerParent again, since it's added dynamically // TODO: rethink this logic, there are many TriggerParents, but this only looks for one! m_triggerParent = FindObjectOfType <TriggerParent>(); } if (m_triggerParent.changeCollider || moveCol) { //print("change collider"); // update the locked particles: first clear, then call FlexStart again //print("number of locked particles before clear: " + m_lockedParticlesMasses.Count); //this.m_lockedParticlesIds.Clear(); /*this.*/ this.m_lockedParticlesMasses.Clear(); //Equate invMass to 0.0f in for loop below to accumulate locked particles for (int i = 0; i < m_lockedParticlesIds.Count; i++) { cntr.m_particles[m_lockedParticlesIds[i]].invMass = /*0.0f*/ m_Particles.m_mass /*1.0f*/; } this.m_lockedParticlesIds.Clear(); base.FlexStart(solver, cntr, parameters); //for (int i = 0; i < m_lockedParticlesMasses.Count; i++) //{ // print("After clearing, locked particle index: " + m_lockedParticlesIds[i] + " and inv. mass of each locked particle: " + m_lockedParticlesMasses[i]); //} moveCol = false; m_triggerParent.changeCollider = false; } base.PostContainerUpdate(solver, cntr, parameters); }
// Use this for initialization public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { if (try_pick_up) { try_pick_up = false; locked = cntr.m_particles.ToList().Select((v, i) => new IdMass(i, v.invMass)) .Where(v => Vector3.Distance(cntr.m_particles[v.idx].pos, ball.bounds.center) < 1.0f) .ToList(); Debug.LogFormat("Locked {0} points", locked.Count()); } else if (try_drop) { try_drop = false; locked.Select(l => cntr.m_particles[l.idx].invMass = l.inv_mass); locked.Clear(); } else if (locked.Count() > 0) { var locked_ctr = locked.Select(l => cntr.m_particles[l.idx].pos) .Aggregate((lhs, rhs) => lhs + rhs) / locked.Count(); var delta = ball.bounds.center - locked_ctr; foreach (var l in locked) { cntr.m_particles[l.idx].pos += delta; cntr.m_velocities[l.idx] = delta / Time.fixedTime; } } }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) //public override void PreContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { if (long_knife_held) { queue_work(lk_pts); } if (scalpel_held) { queue_work(sl_pts); } if (scissors_closed.gameObject.activeInHierarchy && scissors_held) { queue_work(sc_pts); } if (Time.time > 3 && Time.time < 6 && !has_cut) { has_cut = true; queue_work(tmp_cut_pts); } if (Time.time > 6 && has_cut) { has_cut = false; var ovr = GameObject.Find("UI").GetComponent <OverController>(); ovr.restore_mesh_public(); } }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { solver.m_solverSubSteps = (int)solverSubSteps; parameters.m_numIterations = (int)numOfIterations; if (m_FlexParticleLocker.picked) { //TODO: check if the labeled behavior already contains a behavior and append to that behavior if (m_createBehavior.labeledBehavior.Count == 0) { print("No behaviors in Serilazable Map"); tempIVD = new SerializableMap <int, Vector3>(); tempIVD.Add(m_FlexParticleLocker.pMouseParticleID, m_FlexParticleLocker.pMouseParticlePos); m_createBehavior.labeledBehavior.Add(m_behaviorName.text, tempIVD); } else { print("There are behaviors"); foreach (var index in m_createBehavior.labeledBehavior) { if (m_behaviorName.text == index.Key) { foreach (var behavior in m_createBehavior.labeledBehavior.Values) { print(behavior.Keys); behavior.Add(m_FlexParticleLocker.pMouseParticleID, m_FlexParticleLocker.pMouseParticlePos); //m_createBehavior.labeledBehavior.Add(m_behaviorName.text, behavior); } } } } //this.GetComponent<CreateBehavior>().labeledBehavior.Add(this.GetComponent<CreateBehavior>().behaviorName.text, tempIVD); m_FlexParticleLocker.picked = false; } }
public override void PreContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { if (enabled == false) { return; } if (firstRun) { firstRun = false; _cachedVertices = skinnedMeshRenderer.sharedMesh.vertices; _cachedBindposes = skinnedMeshRenderer.sharedMesh.bindposes; _cachedBoneWeights = skinnedMeshRenderer.sharedMesh.boneWeights; bool createAsset = vertMapAsset == null || rebuildVertMapAsset; if (vertMapAsset == null) { #if UNITY_EDITOR vertMapAsset = ScriptableObject.CreateInstance <VertMapAsset>(); AssetDatabase.CreateAsset(vertMapAsset, "Assets/" + this.name + "VertMapAsset.asset"); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = vertMapAsset; #endif } if (createAsset) { vertMapAsset.vertexParticleMap = new List <int>(); VertMapAssetBuilder vertMapAssetBuilder = new VertMapAssetBuilder(flexShapeMatching, vertMapAsset, skinnedMeshRenderer); vertMapAssetBuilder.CreateAsset(); } particlePositions = new Vector3[vertMapAsset.particleRestPositions.Count]; print("particle rest positions count:" + particlePositions.Length); //Debug.Log(this.skinnedMeshRenderer.name); UpdateParticlePositions(); } else { if (timeDelta < refreshRate) { return; } // Only process once 30 times a second UpdateParticlePositions(); MatchShapes(); // apply to soft body while (timeDelta >= refreshRate) { timeDelta -= refreshRate; } } }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { if (Input.GetKey(m_key)) { for (int index = 0; index < cntr.m_velocities.Length; ++index) { cntr.m_velocities[index] = new Vector3((Random.value - 0.5f) * MAX_JIGGLE_FACTOR, (Random.value - 0.5f) * MAX_JIGGLE_FACTOR, (Random.value - 0.5f) * MAX_JIGGLE_FACTOR); } } }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { var particles = fParticles.m_particles; if (Input.GetKey(m_key)) { for (int pId = 0; pId < fParticles.m_particlesCount; pId++) { particles[pId].pos -= new Vector3((Random.value - 0.5f) * MAX_JIGGLE_FACTOR, (Random.value - 0.5f) * MAX_JIGGLE_FACTOR, (Random.value - 0.5f) * MAX_JIGGLE_FACTOR) * Time.deltaTime; } } }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { parameters.m_numIterations = iterations; if (m_flAgent.reset) { Reset(); print("reset"); } if (m_flAgent.check) { if (iterations <= 25) { print("affect:" + iterations); iterations += 1; } } }
public override void PreContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { //if (UnityObjectHasMoved()) ///* if (UnityObjectTransformchanged())*/ //{ // // copy over movement // //Debug.Log("detected movement"); // Vector3 movement = this.transform.position - new Vector3(transformX, transformY, transformZ); // TranslateFlexPositions(movement); // // and then update transform cache: // CacheTransform(); //} if (transform.hasChanged) { TransformFlexPositions(transforms); CacheLocalTransform(); } }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { if (Input.GetKeyDown(m_key)) { //for (int index = 0; index < cntr.m_velocities.Length; ++index) //{ // cntr.m_velocities[index] = new Vector3(0.0f, -MAX_MELT_FACTOR, 0.0f); //} //melt_object.GetComponent<FlexAnimation>().enabled = false; melt_object.GetComponent <FlexShapeMatching>().enabled = false; } if (Input.GetKeyUp(m_key)) { //for (int index = 0; index < cntr.m_velocities.Length; ++index) //{ // cntr.m_velocities[index] = new Vector3(0.0f, -MAX_MELT_FACTOR, 0.0f); //} //melt_object.GetComponent<FlexAnimation>().enabled = true; melt_object.GetComponent <FlexShapeMatching>().enabled = true; } }
// Update is called once per frame public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { moveCol = false; if (Input.GetKeyDown("o")) { //myCol.center += new Vector3(0.0f, 2.0f, 0.0f); moveCol = true; base.PostContainerUpdate(solver, cntr, parameters); } if (Input.GetKeyDown("k")) { //myCol.center += new Vector3(0.0f, -2.0f, 0.0f); moveCol = true; base.PostContainerUpdate(solver, cntr, parameters); } if (Input.GetKeyDown("j")) { //myCol.center += new Vector3(2.0f, 0.0f, 0.0f); moveCol = true; base.PostContainerUpdate(solver, cntr, parameters); } if (Input.GetKeyDown("l")) { //myCol.center += new Vector3(-2.0f, 0.0f, 0.0f); moveCol = true; base.PostContainerUpdate(solver, cntr, parameters); } if (Input.GetKeyDown("i")) { //myCol.center += new Vector3(0.0f, 0.0f, 2.0f); moveCol = true; base.PostContainerUpdate(solver, cntr, parameters); } if (Input.GetKeyDown("p")) { //myCol.center += new Vector3(0.0f, 0.0f, -2.0f); moveCol = true; base.PostContainerUpdate(solver, cntr, parameters); } }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { //base.PostContainerUpdate(solver, cntr, parameters); int tmp_part_id = -1; if (Input.GetMouseButtonUp(0)) { if (m_mouseParticle != -1) { // we got the end of a mouse drag with a particle selected, // notify whoever needs to know! picked = true; pMouseParticleID = m_mouseParticle; pMouseParticlePos = m_mousePos; //TODO: move the following to a class that is appropriately named //print(m_mouseParticle); //print(m_mousePos); //this.GetComponent<CreateBehavior>().behavior.dictionary.Add(m_mouseParticle, mousePos); //TODO: check if the labeled behavior already contains a behavior and append to that behavior //SerializableMap<int, Vector3> tempIVD = new SerializableMap<int, Vector3>(); //tempIVD.Add(m_mouseParticle, m_mousePos); //this.GetComponent<CreateBehavior>().labeledBehavior.Add(this.GetComponent<CreateBehavior>().behaviorName.text, tempIVD); // remember particle id, since we need to undo parent's setting it back to non-zero mass: tmp_part_id = m_mouseParticle; } } base.PostContainerUpdate(solver, cntr, parameters); // make the base class do its thing first // undo what the parent did, i.e. set the mass back to 0, we want to keep it locked: // TODO: think about this again? if (tmp_part_id != -1) { cntr.m_particles[tmp_part_id].invMass = 0.0f; } }
// Start is called before the first frame update //public override void FlexStart(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) //{ // parameters.m_numIterations = Random.Range(0, 5); // //iterations = parameters.m_numIterations; // //base.FlexStart(solver, cntr, parameters); // print("test in Env reset" + parameters.m_numIterations); //} public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { if (flAgent.check) { parameters.m_numIterations = iterations; //base.PostContainerUpdate(solver, cntr, parameters); if (parameters.m_numIterations > 15 & parameters.m_numIterations < 20) { //AddReward(1.0f); addReward = true; } if (parameters.m_numIterations < 15 || parameters.m_numIterations > 20) { addReward1 = true; } if (parameters.m_numIterations <= 25) { print(parameters.m_numIterations); iterations += 1; } } }
//public override void FlexStart(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) //{ // print(Time.fixedTime); // print(flAnim.particlePositions.Length); // for (int i = 0; i < flAnim.particlePositions.Length; i++) // { // print("index: " + i + "anim particle velocity at start: " + flAnim.particlePositions[i] / Time.fixedTime); // } //} // Start is called before the first frame update public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { //for (int i = 0; i < flAnim.particlePositions.Length; i++) //{ // Debug.DrawLine(flAnim.flexParticles.m_particles[i].pos, flAnim.vertMapAsset.particleRestPositions[i], Color.green); //} if (firstRun) { firstRun = false; for (int i = 0; i < flAnim.particlePositions.Length; i++) { //print("index: " + i + " anim particle pos at post containter update: " + flAnim.particlePositions[i]); //print("index: " + i + " velocity: " + flParticles.m_velocities[i]); //print("temp" + temp[i]); //print("time. Delta time: " + Time.deltaTime); Vector3 delta = new Vector3(); delta = Vector3.zero; velFirst = delta / Time.deltaTime; //print("first anim particle: " + flAnim.particlePositions[i]); //print("delta: " + delta); //print("vel: " + velFirst); temp[i] = flAnim.particlePositions[i]; } } else { for (int i = 0; i < flAnim.particlePositions.Length; i++) { //print("index: " + i + " anim particle pos at post containter update: " + flAnim.particlePositions[i]); //print("index: " + i + " velocity: " + flParticles.m_velocities[i]); //print("temp" + temp[i]); //print("time. Delta time: " + Time.deltaTime); Vector3 delta = new Vector3(); Vector3 vel = new Vector3(); delta = (flAnim.particlePositions[i] - temp[i]); vel = delta / Time.deltaTime; //vel = vel / flAnim.particlePositions.Length; //print("first anim particle: " + flAnim.particlePositions[i]); //print("delta: " + delta); //print("vel: " + vel); velAccumAnim += vel; temp[i] = flAnim.particlePositions[i]; } } print("Avg. velocity of animPaticles: " + (velAccumAnim + velFirst).magnitude / flAnim.particlePositions.Length); for (int i = 0; i < flParticles.m_velocities.Length; i++) { //print(flParticles.m_initialVelocity); //print("index: " + i + "velocity: " + flParticles.m_velocities[i]); flParticles.m_velocities[i] = flParticles.m_velocities[i] /*/ flParticles.m_velocities.Length*/; velAccumFlex += flParticles.m_velocities[i]; } print("Avg. velocity of flexPaticles: " + velAccumFlex.magnitude / flParticles.m_velocities.Length); }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { //Note: might need to use a Coroutine instead! //Stop flex animation first then track particle positions for this object; if (m_UIController.turnOffAnim) { flyCamEnable = true; //List<Vector3> templist = null; //Vector3 temp; this.GetComponent <FlexAnimation>().enabled = false; //might have to move this to start to optimize flyCam.enabled = true; playerController.enabled = false; //StartCoroutine(MoveParticle()); //int x = this.GetComponent<FlexMouseDrag>().m_mouseParticle; if (m_UIController.doneMoving) { m_UIController.turnOffAnim = false; m_UIController.doneMoving = false; //print(reset.position); playerController.enabled = true; } } if (m_UIController.turnOnAnim) { //Note: need to save the behavior as an asset possibly or JSON?, need to ask stefan. //string jsonData = JSONSerializer.ToJson<Dictionary<int, Vector3>>(behavior); //File.WriteAllText(Application.persistentDataPath + "/test.json", jsonData); // test C# way of serializing: XmlSerializer xmlserializer = new XmlSerializer(labeledBehavior.GetType()); //FileStream file = File.Open( "C:/Users/siciit/AppData/LocalLow/DefaultCompany/Nvidia_softAnim_trials/labbehaviorTrial2.xml", FileMode.Open, FileAccess.Write); //FileStream file = File.Open(Application.persistentDataPath + "/labbehaviorTrial2.xml", FileMode.Open, FileAccess.Read); if (!System.IO.File.Exists(Application.persistentDataPath + "/labbehaviorTrial3.xml")) { /* FileStream*/ file = File.Open(Application.persistentDataPath + "/labbehaviorTrial3.xml", FileMode.OpenOrCreate, FileAccess.Write); } else { /*FileStream */ file = File.Open(Application.persistentDataPath + "/labbehaviorTrial3.xml", FileMode.Open, FileAccess.Write); } xmlserializer.Serialize(file, labeledBehavior); file.Flush(); file.Close(); flyCamEnable = false; //JSONSerializer.Save<Dictionary<int, Vector3>>("test", behavior); //if (behaviorName != null) // { // print(behaviorName.text); // } this.GetComponent <FlexAnimation>().enabled = true; m_UIController.turnOnAnim = false; } if (m_UIController.showAnim) { m_UIController.showAnim = false; XmlSerializer readSerialize = new XmlSerializer(typeof(SerializableMap <string, SerializableMap <int, Vector3> >)); //FileStream file = new FileStream(Application.persistentDataPath + "/labbehaviorTrial2.xml", FileMode.Open); ///*FileStream */file = File.Open("C:/Users/siciit/AppData/LocalLow/DefaultCompany/Nvidia_softAnim_trials/labbehaviorTrial2.xml", FileMode.Open, FileAccess.Read); /*FileStream*/ file = File.Open(Application.persistentDataPath + "/labbehaviorTrial3.xml", FileMode.Open, FileAccess.Read); print(file.Name); container = readSerialize.Deserialize(file) as SerializableMap <string, SerializableMap <int, Vector3> >; foreach (var var in container) { print(var.Key); print(var.Value); } //this.GetComponent<GetBehaviors>().localContainer = container; //this.GetComponent<GetBehaviors>().gotXML = true; getBehaviors.localContainer = container; getBehaviors.gotXML = true; //FindObjectOfType<GetBehaviors> ().localContainer = container; //FindObjectOfType<GetBehaviors>().gotXML = true; file.Flush(); file.Close(); } //store list ofvectors that have changed positions; }
public override void FlexStart(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { }