void rebuildtree()
    {
        ObiCloth cloth = GetComponent <ObiCloth>();

        // cloth.PullDataFromSolver(ParticleData.POSITIONS|ParticleData.VELOCITIES);
        //Debug.Log(cloth.particleIndices[0]);
        Vector4[] positionss = new Vector4[cloth.positions.Length];
        Vector3[] positions  = new Vector3[cloth.positions.Length];
        Vector3[] trynew     = new Vector3[2];

        Oni.GetParticlePositions(cloth.Solver.OniSolver, positionss, cloth.positions.Length, cloth.particleIndices[0]);
        //Oni.GetParticlePositions(cloth.Solver.OniSolver, position, cloth.positions.Length, 0);
        //Debug.Log(position[0]);
        for (int i = 0; i < cloth.positions.Length; i++)
        {
            positions[i] = positionss[i];
            //Debug.Log(positions[i]);
        }
        tree = KDTree.MakeFromPoints(positions);

        if (tree == null)
        {
            Debug.Log("error_tree");
        }
    }
예제 #2
0
    void initialize_cloth_property()
    {
        // bending constraints
        ObiBendingConstraints bend = this.GetComponent <ObiBendingConstraints>();

        bend.maxBending = 0.008f;
        bend.stiffness  = 0.8f;   //general parameters
        // cancel some constraints
        ObiTetherConstraints tether = this.GetComponent <ObiTetherConstraints>();

        tether.enabled = false;
        ObiSkinConstraints skin = this.GetComponent <ObiSkinConstraints>();

        skin.enabled = false;
        ObiVolumeConstraints volume = this.GetComponent <ObiVolumeConstraints>();

        volume.enabled = false;
        ObiAerodynamicConstraints aero = this.GetComponent <ObiAerodynamicConstraints>();

        aero.enabled = false;

        ObiCloth tmp = this.GetComponent <ObiCloth>();

        tmp.SelfCollisions    = true;
        tmp.CollisionMaterial = Resources.Load("collision_material/LowFriction") as ObiCollisionMaterial;


        //tmp.runInEditMode = true;  won't destroy after playing
        //unfix particle
        //for (int i = 0; i < tmp.invMasses.Length; i++)
        //     tmp.invMasses[i]= 0;
    }
예제 #3
0
    // Use this for initialization
    void Start()
    {
        particleindexsphere[0] = new int[36];
        particleindexsphere[1] = new int[36];
        ObiCloth cloth = GetComponent <ObiCloth>();

        if (!cloth.InSolver)
        {
            Debug.Log("error");
        }
        Vector4[] positionss = new Vector4[cloth.positions.Length];
        Vector3[] positions  = new Vector3[cloth.positions.Length];
        Vector3[] trynew     = new Vector3[2];

        Oni.GetParticlePositions(cloth.Solver.OniSolver, positionss, cloth.positions.Length, cloth.particleIndices[0]);
        for (int i = 0; i < cloth.positions.Length; i++)
        {
            positions[i] = positionss[i];
            //Debug.Log(positions[i]);
        }
        tree = KDTree.MakeFromPoints(positions);

        if (tree == null)
        {
            Debug.Log("error");
        }
    }
예제 #4
0
    void rebuildtree()
    {
        ObiCloth cloth = GetComponent <ObiCloth>();

        // cloth.PullDataFromSolver(ParticleData.POSITIONS|ParticleData.VELOCITIES);
        //Debug.Log(cloth.particleIndices[0]);
        Vector4[] positionss = new Vector4[cloth.positions.Length];
        Vector3[] positions  = new Vector3[cloth.positions.Length];
        Vector3[] trynew     = new Vector3[2];

        // trynew[0] = Vector3.one; trynew[1] = Vector3.one;
        //Debug.Log(cloth.positions[0]);  // local space
        //Debug.Log(cloth.particleIndices[0]); ????   ????must fix that!  runtime will produce this
        Oni.GetParticlePositions(cloth.Solver.OniSolver, positionss, cloth.positions.Length, cloth.particleIndices[0]);
        //Oni.GetParticlePositions(cloth.Solver.OniSolver, position, cloth.positions.Length, 0);
        //Debug.Log(position[0]);
        for (int i = 0; i < cloth.positions.Length; i++)
        {
            positions[i] = positionss[i];
            //Debug.Log(positions[i]);
        }
        tree = KDTree.MakeFromPoints(positions);

        if (tree == null)
        {
            Debug.Log("error");
        }
    }
예제 #5
0
    void initialize_cloth_property()
    {
        // bending constraints
        // cancel some constraints
        ObiTetherConstraints tether = this.GetComponent <ObiTetherConstraints>();

        tether.enabled = false;
        tether.PushDataToSolver();
        ObiSkinConstraints skin = this.GetComponent <ObiSkinConstraints>();

        skin.enabled = false;
        skin.PushDataToSolver();
        ObiVolumeConstraints volume = this.GetComponent <ObiVolumeConstraints>();

        volume.enabled = false;
        volume.PushDataToSolver();
        ObiAerodynamicConstraints aero = this.GetComponent <ObiAerodynamicConstraints>();

        aero.enabled = false;
        aero.PushDataToSolver();
        ObiCloth tmp = this.GetComponent <ObiCloth>();

        tmp.SelfCollisions    = true;
        tmp.CollisionMaterial = Resources.Load("collision_material/MediumFriction") as ObiCollisionMaterial;
        tmp.PushDataToSolver();


        //tmp.runInEditMode = true;  won't destroy after playing
        //unfix particle
        //for (int i = 0; i < tmp.invMasses.Length; i++)
        //     tmp.invMasses[i]= 0;
    }
예제 #6
0
    void Start()   // although it seems need to be update, but the initial position of clothes shuold be enough to find near positions of particles
    {
        particleindexsphere[0] = new int[36];
        particleindexsphere[1] = new int[36];
        ObiCloth cloth = GetComponent <ObiCloth>();

        cloth.PinConstraints.PushDataToSolver();
        if (!cloth.InSolver)
        {
            Debug.Log("error");
        }
        // cloth.PullDataFromSolver(ParticleData.POSITIONS|ParticleData.VELOCITIES);
        //Debug.Log(cloth.particleIndices[0]);
        Vector4[] positionss = new Vector4[cloth.positions.Length];
        Vector3[] positions  = new Vector3[cloth.positions.Length];
        Vector3[] trynew     = new Vector3[2];

        // trynew[0] = Vector3.one; trynew[1] = Vector3.one;
        Oni.GetParticlePositions(cloth.Solver.OniSolver, positionss, cloth.positions.Length, cloth.particleIndices[0]);
        //Oni.GetParticlePositions(cloth.Solver.OniSolver, position, cloth.positions.Length, 0);
        //Debug.Log(position[0]);
        for (int i = 0; i < cloth.positions.Length; i++)
        {
            positions[i] = positionss[i];
            //Debug.Log(positions[i]);
        }
        tree = KDTree.MakeFromPoints(positions);

        if (tree == null)
        {
            Debug.Log("error");
        }
    }
    IEnumerator wait_bending()
    {
        yield return(new WaitForSeconds(3f));

        ObiCloth cloth = this.GetComponent <ObiCloth>();

        cloth.BendingConstraints.maxBending = 0.008f;
        cloth.BendingConstraints.PushDataToSolver();    //update your parameter for constraints
    }
예제 #8
0
    void find()
    {
        clothused = GameObject.FindWithTag("cloth");
        ObiCloth clothes = clothused.GetComponent <ObiCloth>();

        nowuse = clothused.GetComponent <particletagVR>();
        if (nowuse != null && clothes != null)
        {
            findflag = 1;
        }
    }
예제 #9
0
 void addtagscript()
 {
     if (addpickerflag == 0)
     {
         ObiCloth cloth = this.gameObject.GetComponent <ObiCloth>();
         if (cloth != null && cloth.Initialized == true)
         {
             this.gameObject.AddComponent <particletagdrag>();
             addpickerflag = 1;
         }
     }
 }
    void temporarybendingkeep()
    {
        ObiCloth cloth = this.GetComponent <ObiCloth>();

        if (cloth.Initialized == true)
        {
            cloth.BendingConstraints.maxBending = 0f;
            cloth.BendingConstraints.PushDataToSolver();
            StartCoroutine(wait_bending());
            bendingflag = 1;
        }
    }
예제 #11
0
    IEnumerator generatecloth()
    {
        here = this.gameObject;
        //Debug.Log(here.name);
        //Debug.Log(this.name);
        //ObiMeshTopology.CreateInstance("meshtopology");
        ObiMeshTopology meshtopology = ScriptableObject.CreateInstance <ObiMeshTopology>();

        meshtopology.InputMesh = here.GetComponent <MeshFilter>().sharedMesh;
        // Debug.Log(ss.InputMesh.name);
        meshtopology.Generate(); //for meshtoplogy

        GameObject solveroriginal = new GameObject();

        //get solver from the assets
        // solveroriginal.AddComponent<ObiSolver>();
        here.AddComponent <ObiCloth>();
        ObiCloth tmp = here.GetComponent <ObiCloth>();

        //tmp.Solver.RelinquishRenderablePositions();
        tmp.SelfCollisions = true;
        //set solve parameters
        // or tmp.Solver = solveroriginal.AddComponent<ObiSolver>();
        tmp.Solver = solveroriginal.AddComponent <ObiSolver>();
        tmp.Solver.maxParticles = 6000;
        tmp.Solver.volumeConstraintParameters.enabled = false;
        tmp.Solver.skinConstraintParameters.enabled   = false;

        tmp.Solver.tetherConstraintParameters.enabled = false;

        tmp.Solver.densityConstraintParameters.enabled = false;


        tmp.Solver.bendingConstraintParameters.evaluationOrder      = Oni.ConstraintParameters.EvaluationOrder.Parallel;  //sequantial to reduce iterations amount
        tmp.Solver.distanceConstraintParameters.iterations          = 5;
        tmp.Solver.bendingConstraintParameters.iterations           = 5;
        tmp.Solver.shapeMatchingConstraintParameters.iterations     = 5;
        tmp.Solver.collisionConstraintParameters.iterations         = 5;
        tmp.Solver.shapeMatchingConstraintParameters.iterations     = 5;
        tmp.Solver.stitchConstraintParameters.iterations            = 5;
        tmp.Solver.particleCollisionConstraintParameters.iterations = 5;
        tmp.Solver.pinConstraintParameters.iterations = 5; // pin constraints for particle
        tmp.Solver.substeps = 1;                           //improve substeps for a better quality than manual setting
        //  tmp.Solver.
        tmp.SharedTopology = meshtopology;



        yield return(tmp.StartCoroutine(tmp.GeneratePhysicRepresentationForMesh()));

        tmp.AddToSolver(null);   //add constraints back
    }
예제 #12
0
    public void printInfo()
    {
        // get the pin constraint information
        ObiCloth obiCloth        = GameObject.Find("clothPart").GetComponent <ObiCloth>();
        ObiPinConstraintBatch ts = obiCloth.PinConstraints.GetFirstBatch();     // only one batch in obi cloth!

        for (int i = 0; i < ts.ConstraintCount; ++i)
        {
            Debug.Log("restDarbouxVectors: " + ts.restDarbouxVectors[i]);        // (0.7,0,0,0.7)
            Debug.Log("offset: " + ts.pinOffsets[i]);
            Debug.Log("index :" + ts.pinIndices[i]);
        }
    }
예제 #13
0
        public void OnEnable()
        {
            cloth = (ObiCloth)target;

            // In case the cloth has not been initialized yet, start the initialization routine.
            if (!cloth.Initialized && !cloth.Initializing){
            CoroutineJob job = new CoroutineJob();
            routine = EditorCoroutine.StartCoroutine(job.Start(cloth.GeneratePhysicRepresentationForMesh()));
            }

            EditorApplication.update += Update;
            EditorApplication.playmodeStateChanged += OnPlayModeStateChanged;
        }
    void Start()   // although it seems need to be update, but the initial position of clothes shuold be enough to find near positions of particles
    {
        particleindexsphere[0] = new int[36];
        particleindexsphere[1] = new int[36];
        ObiCloth cloth = GetComponent <ObiCloth>();

        cloth.PinConstraints.PushDataToSolver();
        if (!cloth.InSolver)
        {
            Debug.Log("error");
        }
        // cloth.PullDataFromSolver(ParticleData.POSITIONS|ParticleData.VELOCITIES);
        //Debug.Log(cloth.particleIndices[0]);
        Vector4[] positionss = new Vector4[cloth.positions.Length];
        Vector3[] positions  = new Vector3[cloth.positions.Length];
        Vector3[] trynew     = new Vector3[2];

        // trynew[0] = Vector3.one; trynew[1] = Vector3.one;
        Oni.GetParticlePositions(cloth.Solver.OniSolver, positionss, cloth.positions.Length, cloth.particleIndices[0]);
        //Oni.GetParticlePositions(cloth.Solver.OniSolver, position, cloth.positions.Length, 0);
        //Debug.Log(position[0]);
        for (int i = 0; i < cloth.positions.Length; i++)
        {
            positions[i] = positionss[i];
            //Debug.Log(positions[i]);
        }
        tree = KDTree.MakeFromPoints(positions);

        if (tree == null)
        {
            Debug.Log("error_tree");
        }
        leftobject  = GameObject.Find("LeftController/[VRTK][AUTOGEN][Controller][CollidersContainer]/Head");
        rightobject = GameObject.Find("RightController/[VRTK][AUTOGEN][Controller][CollidersContainer]/Head");
        leftobject.AddComponent <ObiCollider>();
        rightobject.AddComponent <ObiCollider>();
        leftobject.GetComponent <ObiCollider>().Phase  = 1;
        rightobject.AddComponent <ObiCollider>().Phase = 1;
        if (leftobject && rightobject)
        {
            Debug.Log(leftobject.transform.position);
            Debug.Log(rightobject.transform.position);
        }
        else
        {
            Debug.Log("failure");
        }
        twoobject[0] = leftobject;
        twoobject[1] = rightobject;
    }
예제 #15
0
    // Use this for initialization
    void Start()
    {
        restDarboux = new Quaternion(0.7f, 0.0f, 0.0f, 0.7f);       // constant
        offset      = new Vector3(0.2f, -1.0f, -0.3f);
        offsetNeg   = new Vector3(-0.2f, -1.0f, -0.3f);

        leftController  = VRTK_DeviceFinder.GetControllerLeftHand();
        rightController = VRTK_DeviceFinder.GetControllerRightHand();
        leftHandler     = GameObject.Find("left_hand");
        rightHandler    = GameObject.Find("right_hand");
        tapeSection     = GameObject.Find("clothPart");
        obiCloth        = tapeSection.GetComponent <ObiCloth>();

        leftCollider  = leftHandler.GetComponent <ObiCollider>();
        rightCollider = rightHandler.GetComponent <ObiCollider>();

        hint = GameObject.FindGameObjectsWithTag("Hint");

        audioHint[0] = false;
        audioHint[1] = false;
        audioHint[2] = false;
        audioHint[3] = false;

        stickPos[0] = GameObject.Find("StickPos_1");
        stickPos[1] = GameObject.Find("StickPos_2");
        stickPos[2] = GameObject.Find("StickPos_3");
        stickPos[3] = GameObject.Find("StickPos_4");

        foreach (var item in hint)
        {
            ParticleSystem particleSystem = item.GetComponent <ParticleSystem>();
            if (!particleSystem.isStopped)
            {
                particleSystem.Stop();
            }
        }

        Debug.Log("current part: " + StaticData.getTargetNum());

        string leftPath = "[VRTK_SDKManager]/SDKSetups/SteamVR/[CameraRig]/Controller (left)/Model";

        rightHighlighter = GameObject.Find(leftPath).GetComponent <VRTK_ControllerHighlighter>();
        string rightPath = "[VRTK_SDKManager]/SDKSetups/SteamVR/[CameraRig]/Controller (right)/Model";

        rightHighlighter = GameObject.Find(rightPath).GetComponent <VRTK_ControllerHighlighter>();
    }
예제 #16
0
    public IEnumerator MakeCloth(Vector3 attachmentOffset)//Transform anchoredTo, Vector3 attachmentOffset
    {
        /*生成方形碰撞体*/
        myCube      = GameObject.CreatePrimitive(PrimitiveType.Cube);
        myCube.name = "myCube";
        myCube.transform.position = attachmentOffset;

        /*生成平面布料*/
        myPlane      = GameObject.CreatePrimitive(PrimitiveType.Plane);
        myPlane.name = "myPlane";
        myPlane.AddComponent <ObiCloth>();
        myPlane.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
        myPlane.transform.position   = new Vector3(attachmentOffset.x, attachmentOffset.y + 2, attachmentOffset.z);


        /*生成求解器*/
        mySolver = new GameObject("mySolver", typeof(ObiSolver));


        /*各组件绑定*/
        cloth  = myPlane.GetComponent <ObiCloth>();
        solver = mySolver.GetComponent <ObiSolver>();

        /*生成拓扑*/
        topology           = ScriptableObject.CreateInstance <ObiMeshTopology>();
        topology.InputMesh = myPlane.GetComponent <MeshCollider>().sharedMesh;
        topology.scale     = new Vector3(0.3f, 0.3f, 0.3f);
        topology.Generate();

        /*衣服组件绑定求解器和拓扑*/
        cloth.Solver         = solver;
        cloth.SharedTopology = topology;

        //不需要Init?

        //碰撞处理
        addCollision();

        //多线程
        yield return(cloth.StartCoroutine(cloth.GeneratePhysicRepresentationForMesh()));

        cloth.AddToSolver(null);
    }
예제 #17
0
    void Start()
    {
        EditorWindow currentscreen = EditorWindow.GetWindow <EditorWindow>();

        //Debug.Log(currentscreen.position.size);
        //currentscreen.position = new Rect(currentscreen.position.center, currentscreen.position.size);
        //Screen.SetResolution(1000, 600, true);
        //Debug.Log(Screen.width);
        //Debug.Log(Screen.height);
        this.gameObject.tag = "cloth";
        ObiCloth    cloth  = this.gameObject.GetComponent <ObiCloth>();
        grabcontrol picker = this.gameObject.GetComponent <grabcontrol>();

        if (cloth != null)
        {
            addclothflag = 1;
            if (picker != null)
            {
                addpickerflag = 1;
            }
        }
        addscript();
    }
예제 #18
0
 public override void OnEnable()
 {
     base.OnEnable();
     cloth = (ObiCloth)target;
 }
예제 #19
0
 // Use this for initialization
 void Start()
 {
     cloth = GetComponent <ObiCloth>();
     particle_control();
 }
예제 #20
0
    private IEnumerator GenerateSack()
    {
        Mesh mesh = GenerateSheetMesh();

        // create and give a material to both sides of the sack:
        GameObject sheet1 = new GameObject("sack_side1", typeof(MeshFilter), typeof(MeshRenderer), typeof(ObiCloth), typeof(ObiClothRenderer));

        sheet1.GetComponent <MeshRenderer>().materials = new Material[] { outsideMaterial, insideMaterial };

        GameObject sheet2 = new GameObject("sack_side2", typeof(MeshFilter), typeof(MeshRenderer), typeof(ObiCloth), typeof(ObiClothRenderer));

        sheet2.GetComponent <MeshRenderer>().materials = new Material[] { outsideMaterial, insideMaterial };

        // position both sheets around the center of this object:
        sheet1.transform.parent        = transform;
        sheet2.transform.parent        = transform;
        sheet1.transform.localPosition = Vector3.forward;
        sheet2.transform.localPosition = -Vector3.forward;

        // generate blueprint:
        var blueprint = ScriptableObject.CreateInstance <ObiClothBlueprint>();

        blueprint.inputMesh = GenerateSheetMesh();
        yield return(StartCoroutine(blueprint.Generate()));

        // generate cloth for both of them:
        ObiCloth cloth1 = sheet1.GetComponent <ObiCloth>();

        cloth1.clothBlueprint = blueprint;

        ObiCloth cloth2 = sheet2.GetComponent <ObiCloth>();

        cloth2.clothBlueprint = blueprint;

        // sew both sides together:
        ObiStitcher stitcher = gameObject.AddComponent <ObiStitcher>();

        stitcher.Actor1 = cloth1;
        stitcher.Actor2 = cloth2;

        // add stitches: top and bottom edges:
        for (int i = 1; i < resolution; ++i)
        {
            stitcher.AddStitch(i, i);
            stitcher.AddStitch((resolution + 1) * resolution + i, (resolution + 1) * resolution + i);
        }

        // sides:
        for (int i = 0; i <= (resolution + 1) * resolution; i += resolution + 1)
        {
            stitcher.AddStitch(i, i);
            stitcher.AddStitch(i + resolution, i + resolution);
        }

        stitcher.PushDataToSolver();

        // adjust bending constraints to obtain a little less rigid fabric:
        cloth1.maxBending = 0.04f;
        cloth2.maxBending = 0.04f;

        Destroy(this);
    }
예제 #21
0
    private void GenerateSack()
    {
        Mesh mesh = GenerateSheetMesh();

        // create and give a material to both sides of the sack:
        GameObject sheet1 = new GameObject("sack_side1", typeof(MeshFilter), typeof(MeshRenderer));

        sheet1.GetComponent <MeshRenderer>().materials = new Material[] { outsideMaterial, insideMaterial };

        GameObject sheet2 = new GameObject("sack_side2", typeof(MeshFilter), typeof(MeshRenderer));

        sheet2.GetComponent <MeshRenderer>().materials = new Material[] { outsideMaterial, insideMaterial };

        // position both sheets around the center of this object:
        sheet1.transform.parent        = transform;
        sheet2.transform.parent        = transform;
        sheet1.transform.localPosition = Vector3.forward;
        sheet2.transform.localPosition = -Vector3.forward;

        // generate cloth for both of them:
        RuntimeClothGenerator generator1 = sheet1.AddComponent <RuntimeClothGenerator>();

        generator1.solver   = solver;
        generator1.topology = topology;
        generator1.mesh     = mesh;

        RuntimeClothGenerator generator2 = sheet2.AddComponent <RuntimeClothGenerator>();

        generator2.solver   = solver;
        generator2.topology = topology;
        generator2.mesh     = mesh;

        // sew both sides together:
        ObiStitcher stitcher = gameObject.AddComponent <ObiStitcher>();

        stitcher.Actor1 = sheet1.GetComponent <ObiCloth>();
        stitcher.Actor2 = sheet2.GetComponent <ObiCloth>();

        // add stitches: top and bottom edges:
        for (int i = 1; i < resolution; ++i)
        {
            stitcher.AddStitch(i, i);
            stitcher.AddStitch((resolution + 1) * resolution + i, (resolution + 1) * resolution + i);
        }

        // sides:
        for (int i = 0; i <= (resolution + 1) * resolution; i += resolution + 1)
        {
            stitcher.AddStitch(i, i);
            stitcher.AddStitch(i + resolution, i + resolution);
        }

        // adjust bending constraints to obtain a little less rigid fabric:
        ObiCloth cloth1 = sheet1.GetComponent <ObiCloth>();
        ObiCloth cloth2 = sheet2.GetComponent <ObiCloth>();

        cloth1.BendingConstraints.maxBending = 0.02f;
        cloth2.BendingConstraints.maxBending = 0.02f;

        cloth1.BendingConstraints.PushDataToSolver(ParticleData.NONE);
        cloth2.BendingConstraints.PushDataToSolver(ParticleData.NONE);
    }
예제 #22
0
 public void Awake()
 {
     cloth = GetComponent <ObiCloth>();
 }