コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        this.transform.localScale = new Vector3(0.12f, 0.12f, 1.0f);

        // Calculate index
        _lastIndex++;
        int index = (int)(_lastIndex) % (_uvTieX * _uvTieY);

        if (index != _lastIndex)
        {
            // split into horizontal and vertical index
            int uIndex = index % _uvTieX;
            int vIndex = index / _uvTieY;

            // build offset
            // v coordinate is the bottom of the image in opengl so we need to invert.
            Vector2 offset = new Vector2(uIndex * _size.x,
                                         1.0f - _size.y - vIndex * _size.y);

            Texture2D subtex = MedicalImaging.cropTexture2D(texture, new Rect(offset.x, offset.y,
                                                                              200, 180));

            //_myRenderer.material.SetTextureOffset ("_MainTex", offset);
            //_myRenderer.material.SetTextureScale ("_MainTex", _size);

            _lastIndex = index;

            _myRenderer.material.SetTexture("_MainTex", subtex);
            MedicalImaging.applyQuadShader(this.gameObject, "Custom/MRI_Image_OpacityMap");
            //MedicalImaging.applyQuadShader(this.gameObject, "Custom/GLSL_basic_shader");
        }
    }
コード例 #2
0
ファイル: MedicalImaging.cs プロジェクト: raywind/DocAR
    public static void applyQuadTexture2D(GameObject q, Texture2D texture, int slice)
    {
        MeshRenderer m_renderer;
        Mesh         m_mesh;
        Material     m_material;

        m_renderer = q.GetComponent <MeshRenderer>();
        m_mesh     = q.GetComponent <MeshFilter>().mesh;
        m_material = m_renderer.material;

        int     _uvTieX = 10;
        int     _uvTieY = 10;
        Vector2 _size   = new Vector2(1.0f / _uvTieX, 1.0f / _uvTieY);

        // split into horizontal and vertical index
        int uIndex = slice % 10;
        int vIndex = slice / 10;


        // build offset
        // v coordinate is the bottom of the image in opengl so we need to invert.
        Vector2 offset = new Vector2(uIndex * _size.x,
                                     1.0f - _size.y - vIndex * _size.y);

        Texture2D subtex = MedicalImaging.cropTexture2D(texture,
                                                        new Rect(offset.x * texture.width, offset.y * texture.height,
                                                                 200, 180));


        m_material.SetTexture("_MainTex", subtex);
    }