示例#1
0
 void OnTriggerStay(Collider other)
 {
     //Vector3[] moldForces = new Vector3[Ms3D.VertCount/2];
     //float xNoise = Random.Range (-50, 20);
     //float yNoise = Random.Range (-50, 20);
     //float zNoise = Random.Range (-50, 50);
     //Debug.Log(other.name);
     if (other.tag == "ExcitedSpawner" || other.tag == "AcceptSpawner")
     {
         MassSpawner3D      testSpawner      = other.GetComponent <MassSpawner3D>();
         MassSpringSystem3D testSpringSystem = other.GetComponent <MassSpringSystem3D>();
         Vector3[]          moldPositions    = new Vector3[testSpringSystem.VertCount / 2];
         //Vector3[] moldPositionsforMyspawner = new Vector3[testSpringSystem.VertCount/2];
         //testSpawner.Primitives[k].transform.position = mySpawner.Primitives[index].transform.position;
         float dist = Vector3.Distance(mySpawner.transform.position, testSpawner.transform.position);
         if (dist < 5.0f)
         {
             //string debugText = "";
             foreach (var indexmass in testSpawner.Primitives)
             {
                 int        index = indexmass.Key;
                 GameObject mass  = indexmass.Value;
                 // use overlapsphere to check whether a voxel of mine is close:
                 foreach (Collider coll in Physics.OverlapSphere(mass.transform.position, radius))
                 {
                     if (coll.transform.parent == this.transform)
                     {
                         Vector3 force = coll.transform.position - mass.transform.position;
                         //debugText += "\nAdding force from " + mass.name + " to " + coll.gameObject.name + " of " + force;
                         break;
                     }
                 }
                 //mass.GetComponent<Rigidbody>().AddForce(force);
                 //mySpawner.transform.GetChild(k).position = testSpawner.transform.GetChild(k / 2).position;
                 //Debug.Log(testSpawner.transform.GetChild(k).name);
                 //moldPositions[k] = testSpawner.transform.GetChild(k).position;
                 //moldPositionsforMyspawner[k] = mySpawner.transform.GetChild(k).position;
                 //moldForces[k].x = xNoise;
                 //moldForces[k].y = yNoise;
                 //moldForces[k].z = zNoise;
             }
             //Debug.Log(debugText);
             //testSpringSystem.positionBuffer.SetData(moldPositions);
             //mySpringSystem.positionBuffer.SetData(moldPositionsforMyspawner);
             //Ms3D.externalForcesBuffer.SetData(moldForces);
         }
     }
 }
    /** Cast a ray from the given screen position and check for collision with mass objects.
     *  If there is a collision with a mass object, add a touch point to the grid touches array
     *  (e.g. to be later be handled by a MassSpringSystem controller).
     */
    public void ProjectScreenPositionToMassSpringGrid(Vector2 screenPosition)
    {
        Ray ray = Camera.main.ScreenPointToRay(screenPosition);

        if (Physics.Raycast(ray, out raycastResult, 500f, LayerMask.GetMask("Layer2")))
        {
            GameObject obj = raycastResult.collider.gameObject;
            //Debug.Log("hit somthing" + obj.name);
            if (MassSpringSystem3D.IsMassUnit(obj.tag) /*||MassSpringSystem3D.IsBoneMassUnit(obj.tag)*/)
            {
                int index = Int32.Parse(obj.name.Substring(7, obj.name.IndexOf(' ') - 7));
                voxelTouched = index;
                //Debug.Log(index);

                //need to translate back from unity world space so we use z here rather than y
                GridTouches.Add(new Vector2(index, SimulatedPressure));
            }
        }
    }
 void Start()
 {
     sb = GetComponent <MassSpringSystem3D>();
 }