예제 #1
0
    void Start()
    {
        this.clayxel             = this.gameObject.GetComponent <Clayxels.ClayContainer>();
        this.clayxel.forceUpdate = true;
        this.clayxel.init();

        this.solids         = this.clayxel.getSolids();
        this.preAddedSolids = this.solids.Count; // remember if user added solids before particles

        this.updateParticleCount();
    }
예제 #2
0
    // Start is called before the first frame update
    void Start()
    {
        if (!Clayxels.ClayContainer.isCacheEnabled())
        {
            Debug.Log("To run this example you need to set CLAYXELS_CACHEON to 1 inside claySDF.compute");

            return;
        }

        Clayxels.ClayContainer container = this.gameObject.GetComponent <Clayxels.ClayContainer>();
        container.init();
        container.clearCachedClay();
    }
예제 #3
0
    void Start()
    {
        // Here we initialize the clay container and we add the relevant components

        this.clayxel = this.GetComponent <Clayxels.ClayContainer>();
        this.clayxel.init();

        this.gameObject.AddComponent <MeshFilter>();
        this.gameObject.AddComponent <MeshRenderer>();
        this.gameObject.AddComponent <MeshCollider>();

        this.gameObject.GetComponent <MeshRenderer>().material = new Material(Shader.Find("Clayxels/ClayxelBuiltInMeshShader"));

        // we'll disable the container update so that we can manually compute clay when we need it, once per frame
        this.clayxel.enabled = false;
    }
예제 #4
0
    void Start()
    {
        // Here we initialize the clay container and we add the relevant components

        this.clayxel = this.GetComponent <Clayxels.ClayContainer>();
        this.clayxel.init();

        this.gameObject.AddComponent <MeshFilter>();
        this.gameObject.AddComponent <MeshRenderer>();
        this.gameObject.AddComponent <MeshCollider>();

        this.gameObject.GetComponent <MeshRenderer>().material = new Material(Shader.Find("Clayxels/ClayxelBuiltInMeshShader"));

        // we'll disable the container to only render the mesh and we'll update the clay manually
        this.clayxel.enabled = false;
    }
예제 #5
0
    // Start is called before the first frame update
    void Start()
    {
        this.clayxel = this.gameObject.GetComponent <Clayxels.ClayContainer>();
        this.clayxel.init();

        List <Clayxels.Solid> solids = this.clayxel.getSolids();

        for (int i = 0; i < 128; ++i)
        {
            Clayxels.Solid newSolid = new Clayxels.Solid();

            newSolid.position.x = UnityEngine.Random.Range(-1.0f, 1.0f);
            newSolid.position.y = UnityEngine.Random.Range(-1.0f, 1.0f);
            newSolid.position.z = UnityEngine.Random.Range(-1.0f, 1.0f);

            solids.Add(newSolid);
        }

        this.clayxel.updatedSolidCount();
    }
예제 #6
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (!Clayxels.ClayContainer.isCacheEnabled())
        {
            this.textObj.text = "To run this example you need to set CLAYXELS_CACHEON to 1 inside claySDF.compute";

            return;
        }

        this.textObj.text = "FPS " + this.fps + " \nSolids: " + this.solids;

        this.transform.localEulerAngles = this.transform.localEulerAngles + new Vector3(0.0f, 1.0f, 0.0f);

        Transform childTrn = this.transform.GetChild(0);

        Clayxels.ClayObject clayObj = childTrn.gameObject.GetComponent <Clayxels.ClayObject>();

        clayObj.primitiveType = UnityEngine.Random.Range(0, 6);

        if (UnityEngine.Random.Range(0, 100) > 20)
        {
            clayObj.blend = 0.1f;
        }
        else
        {
            clayObj.blend = -0.5f;
        }

        Color col = clayObj.color;

        clayObj.color = col + new Color(
            UnityEngine.Random.Range(-0.1f, 0.1f),
            UnityEngine.Random.Range(-0.1f, 0.1f),
            UnityEngine.Random.Range(-0.1f, 0.1f),
            1.0f);

        if (clayObj.color.r < 0.0f)
        {
            clayObj.color.r = 0.0f;
        }
        else if (clayObj.color.r > 1.0f)
        {
            clayObj.color.r = 1.0f;
        }

        if (clayObj.color.g < 0.0f)
        {
            clayObj.color.g = 0.0f;
        }
        else if (clayObj.color.g > 1.0f)
        {
            clayObj.color.g = 1.0f;
        }

        if (clayObj.color.b < 0.0f)
        {
            clayObj.color.b = 0.0f;
        }
        else if (clayObj.color.b > 1.0f)
        {
            clayObj.color.b = 1.0f;
        }

        childTrn.localEulerAngles = childTrn.localEulerAngles + new Vector3(
            UnityEngine.Random.Range(-10.0f, 10.0f),
            UnityEngine.Random.Range(-10.0f, 10.0f),
            UnityEngine.Random.Range(-10.0f, 10.0f));

        Vector3 newPos = childTrn.localPosition + new Vector3(
            UnityEngine.Random.Range(-0.5f, 0.5f),
            UnityEngine.Random.Range(-0.5f, 0.5f),
            UnityEngine.Random.Range(-0.5f, 0.5f));

        if (newPos.x > 3.0f)
        {
            newPos.x = 3.0f;
        }
        else if (newPos.x < -3.0f)
        {
            newPos.x = -3.0f;
        }

        if (newPos.y > 3.0f)
        {
            newPos.y = 3.0f;
        }
        else if (newPos.y < -3.0f)
        {
            newPos.y = -3.0f;
        }

        if (newPos.z > 3.0f)
        {
            newPos.z = 3.0f;
        }
        else if (newPos.z < -3.0f)
        {
            newPos.z = -3.0f;
        }

        childTrn.localPosition = newPos;

        this.solids += 1;

        Clayxels.ClayContainer container = this.gameObject.GetComponent <Clayxels.ClayContainer>();
        container.computeClay();
        container.cacheClay();
    }