{"id":23511012,"url":"https://github.com/pome-ta/pystametalstudy","last_synced_at":"2025-04-18T15:03:10.012Z","repository":{"id":112764238,"uuid":"375750745","full_name":"pome-ta/pystaMetalStudy","owner":"pome-ta","description":null,"archived":false,"fork":false,"pushed_at":"2023-11-06T15:09:11.000Z","size":5205,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T06:23:11.902Z","etag":null,"topics":["ios","metal","objcective-c","python3","pythonista","pythonista-ios","pythonista3","shader","swift"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pome-ta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-06-10T15:45:27.000Z","updated_at":"2023-05-05T17:34:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"2bccea23-03dd-4dbf-a839-893b248ba302","html_url":"https://github.com/pome-ta/pystaMetalStudy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pome-ta%2FpystaMetalStudy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pome-ta%2FpystaMetalStudy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pome-ta%2FpystaMetalStudy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pome-ta%2FpystaMetalStudy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pome-ta","download_url":"https://codeload.github.com/pome-ta/pystaMetalStudy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249509275,"owners_count":21283557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","metal","objcective-c","python3","pythonista","pythonista-ios","pythonista3","shader","swift"],"created_at":"2024-12-25T12:13:01.670Z","updated_at":"2025-04-18T15:03:09.989Z","avatar_url":"https://github.com/pome-ta.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pystaMetalStudy\n\n[Pythonista 3](http://omz-software.com/pythonista/) でMetal をチャレンジするリポリトリ\n\nさまざまなサイトを参照しているので、参照URL などは、各ディレクトリ内に明記予定\n\n\n以下列記は、実装日誌的なメモ\n\n\n# 📝 2023/10/19\n\n\n過去の困りを確認しようとしても、困ってるお気持ちしか書いてないので、キャッチアップできない\n\n\n困りのコードと、期待値と結果程度は残すようにしたい\n\n\n\n## [src/everythingAboutTheMetalAPI/chapter04/sandbox/231019_0004.py](https://github.com/pome-ta/pystaMetalStudy/blob/main/src/everythingAboutTheMetalAPI/chapter04/sandbox/231019_0004.py)\n\n\nnumpy で構造体を書いてみてる\n\nサイズの取り方とか、どうかなぁ、、、\n\n\n[NumPy - Structured arrays](https://runebook.dev/ja/docs/numpy/user/basics.rec#numpy.lib.recfunctions.repack_fields)\n\n\n\n## ヘッダーファイルの取り込み\n\n目算がついていない\n\n\n`.metal` に直書きにするとしても、cpu 側でのパスすることを確認しなければ、、、\n\n\n[[Metal]metalファイルをプリコンパイルしつつ実機でもコンパイルする #iOS - Qiita](https://qiita.com/noppefoxwolf/items/ddfec339f6002a33bc3b)\n\n[[Metal]MTLLibraryをランタイムでコンパイルする #iOS - Qiita](https://qiita.com/noppefoxwolf/items/fe6ea83f0e0e9703033c)\n\n\n[User defined. What I typically do is 1) add some sensible defaults to the top of my shader code so that I can use a precompiled library if I choose: #ifndef THREADS_PER_THREADGROUP #define... - Matthew Kieber-Emmons - Medium](https://kieber-emmons.medium.com/user-defined-3767eb5bfee4)\n\n\n# 📝 2023/10/10\n\n## `ui` モジュール依存を剥がす\n\nちまちまと、やってく\n\n## 📝 2022/10/07\n\nsimd 調査？\n\n\n## 📝 2022/04/22\n\n```\nn0\tsimd::float3\t(-0, -0.707106649, -0, -0)\t\n[0]\tfloat\t-0\n[1]\tfloat\t-0.707106649\n[2]\tfloat\t-0\n[3]\tfloat\t-0\nv0\tsimd::float3\t(-0.25, 1.99000001, -0.25, 1)\t\n[0]\tfloat\t-0.25\n[1]\tfloat\t1.99000001\n[2]\tfloat\t-0.25\n[3]\tfloat\t1\nv1\tsimd::float3\t(-0.25, 1.99000001, 0.25, 1)\t\n[0]\tfloat\t-0.25\n[1]\tfloat\t1.99000001\n[2]\tfloat\t0.25\n[3]\tfloat\t1\nv2\tsimd::float3\t(0.25, 1.99000001, 0.25, 1)\t\n[0]\tfloat\t0.25\n[1]\tfloat\t1.99000001\n[2]\tfloat\t0.25\n[3]\tfloat\t1\nn1\tsimd::float3\t(-0, -0.707106649, -0, -0)\t\n[0]\tfloat\t-0\n[1]\tfloat\t-0.707106649\n[2]\tfloat\t-0\n[3]\tfloat\t-0\nv3\tsimd::float3\t(0.25, 1.99000001, -0.25, 1)\t\n[0]\tfloat\t0.25\n[1]\tfloat\t1.99000001\n[2]\tfloat\t-0.25\n[3]\tfloat\t1\n```\n\n```\nvertices\tstd::vector\u003cfloat __attribute__((ext_vector_type(3))), std::allocator\u003cfloat __attribute__((ext_vector_type(3)))\u003e \u003e \u0026\tsize=6\t0x00000001083dce80\n[0]\tfloat __attribute__((ext_vector_type(3)))\t(-0.25, 1.99000001, -0.25, 1)\t\n[1]\tfloat __attribute__((ext_vector_type(3)))\t(-0.25, 1.99000001, 0.25, 1)\t\n[2]\tfloat __attribute__((ext_vector_type(3)))\t(0.25, 1.99000001, 0.25, 1)\t\n[3]\tfloat __attribute__((ext_vector_type(3)))\t(-0.25, 1.99000001, -0.25, 1)\t\n[4]\tfloat __attribute__((ext_vector_type(3)))\t(0.25, 1.99000001, 0.25, 1)\t\n[5]\tfloat __attribute__((ext_vector_type(3)))\t(0.25, 1.99000001, -0.25, 1)\t\n```\n\n\n\n\n```\nnormals\tstd::vector\u003cfloat __attribute__((ext_vector_type(3))), std::allocator\u003cfloat __attribute__((ext_vector_type(3)))\u003e \u003e \u0026\tsize=6\t0x00000001045c6e98\n\n\n[0]\tfloat __attribute__((ext_vector_type(3)))\t(-0, -0.707106649, -0, -0)\t\n[1]\tfloat __attribute__((ext_vector_type(3)))\t(-0, -0.707106649, -0, -0)\t\n[2]\tfloat __attribute__((ext_vector_type(3)))\t(-0, -0.707106649, -0, -0)\t\n[3]\tfloat __attribute__((ext_vector_type(3)))\t(-0, -0.707106649, -0, -0)\t\n[4]\tfloat __attribute__((ext_vector_type(3)))\t(-0, -0.707106649, -0, -0)\t\n[5]\tfloat __attribute__((ext_vector_type(3)))\t(-0, -0.707106649, -0, -0)\t\n\n```\n\n```\ncolors\tstd::vector\u003cfloat __attribute__((ext_vector_type(3))), std::allocator\u003cfloat __attribute__((ext_vector_type(3)))\u003e \u003e \u0026\tsize=6\t0x00000001045c6eb0\n[0]\tfloat __attribute__((ext_vector_type(3)))\t(1, 1, 1, 0)\t\n[1]\tfloat __attribute__((ext_vector_type(3)))\t(1, 1, 1, 0)\t\n[2]\tfloat __attribute__((ext_vector_type(3)))\t(1, 1, 1, 0)\t\n[3]\tfloat __attribute__((ext_vector_type(3)))\t(1, 1, 1, 0)\t\n[4]\tfloat __attribute__((ext_vector_type(3)))\t(1, 1, 1, 0)\t\n[5]\tfloat __attribute__((ext_vector_type(3)))\t(1, 1, 1, 0)\t\n```\n\n```\ncolor\tsimd::float3\t(1, 1, 1, 0)\t\n```\n\n\n## 📝 2021/12/11\n\n### delegate\n\n`__main__.py` での`addSubview_` は、class 定義したview を呼び出す\n\n\n\n```.py\nself.objc_instance.addSubview_({classのview})\n```\n\n\n### simd の演算\n\nobjc\n\n```\ncubeVertices\tsimd::float3 [8]\t\n  [0]\tsimd::float3\t(-0.25, 0.00999999046, -0.25, 1)\t\n  [1]\tsimd::float3\t(0.25, 0.00999999046, -0.25, 1)\t\n  [2]\tsimd::float3\t(-0.25, 1.99000001, -0.25, 1)\t\n  [3]\tsimd::float3\t(0.25, 1.99000001, -0.25, 1)\t\n  [4]\tsimd::float3\t(-0.25, 0.00999999046, 0.25, 1)\t\n  [5]\tsimd::float3\t(0.25, 0.00999999046, 0.25, 1)\t\n  [6]\tsimd::float3\t(-0.25, 1.99000001, 0.25, 1)\t\n  [7]\tsimd::float3\t(0.5, 0.5, 0.5, 0)\t\n\n```\n\n\n```\ntransform: Matrix4:\n  [0.5000, 0.0000, 0.0000, 0.0000]\n  [0.0000, 1.9800, 0.0000, 0.0000]\n  [0.0000, 0.0000, 0.5000, 0.0000]\n  [0.0000, 1.0000, 0.0000, 1.0000]\ntransformedVertex: Vector4:\n  [-0.5000, -0.5000, -0.5000, 1.0000]\nmatrixMULvertex: Vector4:\n  [-0.2500, -0.9900, -0.2500, 0.5000]\n\ntransform: Matrix4:\n  [0.5000, 0.0000, 0.0000, 0.0000]\n  [0.0000, 1.9800, 0.0000, 0.0000]\n  [0.0000, 0.0000, 0.5000, 0.0000]\n  [0.0000, 1.0000, 0.0000, 1.0000]\ntransformedVertex: Vector4:\n  [0.5000, -0.5000, -0.5000, 1.0000]\nmatrixMULvertex: Vector4:\n  [0.2500, -0.9900, -0.2500, 0.5000]\n\ntransform: Matrix4:\n  [0.5000, 0.0000, 0.0000, 0.0000]\n  [0.0000, 1.9800, 0.0000, 0.0000]\n  [0.0000, 0.0000, 0.5000, 0.0000]\n  [0.0000, 1.0000, 0.0000, 1.0000]\ntransformedVertex: Vector4:\n  [-0.5000, 0.5000, -0.5000, 1.0000]\nmatrixMULvertex: Vector4:\n  [-0.2500, 0.9900, -0.2500, 1.5000]\n\ntransform: Matrix4:\n  [0.5000, 0.0000, 0.0000, 0.0000]\n  [0.0000, 1.9800, 0.0000, 0.0000]\n  [0.0000, 0.0000, 0.5000, 0.0000]\n  [0.0000, 1.0000, 0.0000, 1.0000]\ntransformedVertex: Vector4:\n  [0.5000, 0.5000, -0.5000, 1.0000]\nmatrixMULvertex: Vector4:\n  [0.2500, 0.9900, -0.2500, 1.5000]\n\ntransform: Matrix4:\n  [0.5000, 0.0000, 0.0000, 0.0000]\n  [0.0000, 1.9800, 0.0000, 0.0000]\n  [0.0000, 0.0000, 0.5000, 0.0000]\n  [0.0000, 1.0000, 0.0000, 1.0000]\ntransformedVertex: Vector4:\n  [-0.5000, -0.5000, 0.5000, 1.0000]\nmatrixMULvertex: Vector4:\n  [-0.2500, -0.9900, 0.2500, 0.5000]\n\ntransform: Matrix4:\n  [0.5000, 0.0000, 0.0000, 0.0000]\n  [0.0000, 1.9800, 0.0000, 0.0000]\n  [0.0000, 0.0000, 0.5000, 0.0000]\n  [0.0000, 1.0000, 0.0000, 1.0000]\ntransformedVertex: Vector4:\n  [0.5000, -0.5000, 0.5000, 1.0000]\nmatrixMULvertex: Vector4:\n  [0.2500, -0.9900, 0.2500, 0.5000]\n\ntransform: Matrix4:\n  [0.5000, 0.0000, 0.0000, 0.0000]\n  [0.0000, 1.9800, 0.0000, 0.0000]\n  [0.0000, 0.0000, 0.5000, 0.0000]\n  [0.0000, 1.0000, 0.0000, 1.0000]\ntransformedVertex: Vector4:\n  [-0.5000, 0.5000, 0.5000, 1.0000]\nmatrixMULvertex: Vector4:\n  [-0.2500, 0.9900, 0.2500, 1.5000]\n\ntransform: Matrix4:\n  [0.5000, 0.0000, 0.0000, 0.0000]\n  [0.0000, 1.9800, 0.0000, 0.0000]\n  [0.0000, 0.0000, 0.5000, 0.0000]\n  [0.0000, 1.0000, 0.0000, 1.0000]\ntransformedVertex: Vector4:\n  [0.5000, 0.5000, 0.5000, 1.0000]\nmatrixMULvertex: Vector4:\n  [0.2500, 0.9900, 0.2500, 1.5000]\n\n```\n\n\n\n\n## 📝 2021/12/06\n\n前回のmatrix の素材をうまく生かしながら\n\n実装をしていく予定！\n\n\nローテート関係が、ちょっと手こずりそう？\n\n\n### ray tracing チャレンジ\n\n数値のlog 取り\n\n\n#### `testTransform`\n\n``` .mm\nfloat4x4 testTransform = matrix4x4_translation(0.3275f, 0.3f, 0.3725f);\n```\n\n```\nPrinting description of testTransform:\n(simd::float4x4) testTransform = {\n  simd_float4x4 = {\n    columns = {\n      [0] = (1, 0, 0, 0)\n      [1] = (0, 1, 0, 0)\n      [2] = (0, 0, 1, 0)\n      [3] = (0.327499986, 0.300000012, 0.372500002, 1)\n    }\n  }\n}\n```\n\n\n#### `testScale`\n\n``` .mm\nfloat4x4 testScale = matrix4x4_scale(0.6f, 0.6f, 0.6f);\n```\n\n\n```\nPrinting description of testScale:\n(simd::float4x4) testScale = {\n  simd_float4x4 = {\n    columns = {\n      [0] = (0.600000024, 0, 0, 0)\n      [1] = (0, 0.600000024, 0, 0)\n      [2] = (0, 0, 0.600000024, 0)\n      [3] = (0, 0, 0, 1)\n    }\n  }\n}\n```\n\n#### `testRotation`\n\n``` .mm\nfloat4x4 testRotation = matrix4x4_rotation(-0.3f, vector3(0.0f, 1.0f, 0.0f));\n```\n\n```\nPrinting description of testRotation:\n(simd::float4x4) testRotation = {\n  simd_float4x4 = {\n    columns = {\n      [0] = (0.955336511, 0, 0.295520186, 0)\n      [1] = (0, 1, 0, 0)\n      [2] = (-0.295520186, 0, 0.955336511, 0)\n      [3] = (0, 0, 0, 1)\n    }\n  }\n}\n```\n\n\n#### `transform`\n\n``` .mm\ntransform = matrix4x4_translation(0.3275f, 0.3f, 0.3725f) *\n            matrix4x4_rotation(-0.3f, vector3(0.0f, 1.0f, 0.0f)) *\n            matrix4x4_scale(0.6f, 0.6f, 0.6f);\n```\n\n```\nPrinting description of transform:\n(simd::float4x4) transform = {\n  simd_float4x4 = {\n    columns = {\n      [0] = (0.573201954, 0, 0.177312121, 0)\n      [1] = (0, 0.600000024, 0, 0)\n      [2] = (-0.177312121, 0, 0.573201954, 0)\n      [3] = (0.327499986, 0.300000012, 0.372500002, 1)\n    }\n  }\n}\n```\n\n\n\n\n``` .mm\n    float4x4 transform = matrix4x4_translation(0.0f, 1.0f, 0.0f) *\n                         matrix4x4_scale(0.5f, 1.98f, 0.5f);\n```\n\n```\nPrinting description of transform:\n(simd::float4x4) transform = {\n  simd_float4x4 = {\n    columns = {\n      [0] = (0.5, 0, 0, 0)\n      [1] = (0, 1.98000002, 0, 0)\n      [2] = (0, 0, 0.5, 0)\n      [3] = (0, 1, 0, 1)\n    }\n  }\n}\n```\n\n``` .mm\n    transform = matrix4x4_translation(0.0f, 1.0f, 0.0f) * matrix4x4_scale(2.0f, 2.0f, 2.0f);\n```\n\n```\nPrinting description of transform:\n(simd::float4x4) transform = {\n  simd_float4x4 = {\n    columns = {\n      [0] = (2, 0, 0, 0)\n      [1] = (0, 2, 0, 0)\n      [2] = (0, 0, 2, 0)\n      [3] = (0, 1, 0, 1)\n    }\n  }\n}\n```\n\n\n\n\n\n## 📝 2021/12/01\n\n### 構造体をShader に投げると、メモリ（？）がズレる問題\n\n\nShaderコードを直接イジる\n\n\n- `float3`\n- `float`\n- `float3`\n- `float`\n\n\nの構造を、\n\n\n\n\n``` .metal\nstruct Light {\n  float3 color;\n  float ambientIntensity;\n  float diffuseIntensity;\n  float3 direction;\n};\n```\n\n- `float4`\n  - `float3` + `float`\n- `float4`\n  - `float3` + `float`\n\n\nと、まとめて`Shader.metal` 上で、分解する\n\n\n\n``` .metal\nfloat3 light_color = float3(light.color.x, light.color.y, light.color.z);\nfloat light_ambientIntensity = float(light.color.w);\nfloat3 ambientColor = light_color * light_ambientIntensity;\n  \n```\n\n\n\n## 📝 2021/11/29\n\n### `Light` の構造体が、`Shader.metal` で読めてない件\n\n\n`color` は読めているが、`ambientIntensity` に参照できていない\n\n``` .py\nclass Light(ctypes.Structure):\n  _fields_ = [\n    ('color', Float3),\n    ('ambientIntensity', (ctypes.c_float))\n  ]\n```\n\n``` .metal\nfragment half4 fragment_color(VertexOut vertexIn [[ stage_in ]]) {\n  return half4(vertexIn.materialColor);\n}\n\nfragment half4 lit_textured_fragment(VertexOut vertexIn [[ stage_in ]],\n                                 sampler sampler2d [[ sampler(0) ]],\n                                 constant Light \u0026light [[ buffer(3) ]],\n                                 texture2d\u003cfloat\u003e texture [[ texture(0) ]] ) {\n  float4 color = texture.sample(sampler2d, vertexIn.textureCoordinates);\n  color = color * vertexIn.materialColor;\n  \n  // Ambient\n  float3 ambientColor = light.color * light.ambientIntensity;\n  \n  // `light.ambientIntensity` が通らない\n  \n  color = color * float4(ambientColor, 1);\n  if (color.a == 0.0)\n    discard_fragment();\n  return half4(color.r, color.g, color.b, 1);\n}\n```\n\n### `mScene.py` での読み取り\n\nどうも、関数での読み取りの際に、サイズ(int) での指定がうまくいっていないっぽい\n\n`stride` の部分がキモっぽい\n\n#### Python で私が書いているコード\n\n``` .py\n    commandEncoder.setFragmentBytes_length_atIndex_(\n      ctypes.byref(self.light),\n      ctypes.sizeof(Light), 3)\n```\n\n#### 参照先のSwift のコード\n\n\n``` .swift\n// 関数が古いのは無視で\ncommandEncoder.setFragmentBytes(\u0026light, length: MemoryLayout\u003cLight\u003e.stride, at: 3)\n```\n\n### log とり\n\n疑似的なコードから、数値を抜き出す\n\n\n``` .swift\nlight.color = float3(0,0,1)\nlight.ambientIntensity = 0.5\ndump(light)\nprint(\"light ---\")\nprint(MemoryLayout\u003cLight\u003e.stride)\nprint(MemoryLayout\u003cLight\u003e.size)\nprint(MemoryLayout\u003cLight\u003e.alignment)\nprint(\"float3 ---\")\nprint(MemoryLayout\u003cfloat3\u003e.stride)\nprint(MemoryLayout\u003cfloat3\u003e.size)\nprint(MemoryLayout\u003cfloat3\u003e.alignment)\nprint(\"Float ---\")\nprint(MemoryLayout\u003cFloat\u003e.stride)\nprint(MemoryLayout\u003cFloat\u003e.size)\nprint(MemoryLayout\u003cFloat\u003e.alignment)\n```\n\n出た、log\n\n```\n▿ simdFullTest.Light\n  ▿ color: SIMD3\u003cFloat\u003e(0.0, 0.0, 1.0)\n    ▿ _storage: Swift.Float.SIMD4Storage\n      - _value: (Opaque Value)\n  - ambientIntensity: 0.5\nlight ---\n32    //stride\n20    // size\n16    // alignment\nfloat3 ---\n16    // stride\n16    // size\n16    // alignment\nFloat ---\n4   // stride\n4   // size\n4   // alignment\n```\n\n\n\n```\nself\tsimdFullTest.ContentView\t\n  light\tsimdFullTest.Light\t\n    color\tSIMD3\u003cFloat\u003e\t(0, 0, 1)\t\n      _storage\tFloat.SIMD4Storage\t\n        _value\tBuiltin.Vec4xFPIEEE32\t\n    ambientIntensity\tFloat\t0b00111111000000000000000000000000\n```\n\n`float32` ということ。。。？\n\n[1/11 数値計算(3), パターン認識(1)](https://lecture.ecc.u-tokyo.ac.jp/~ktanaka/is11/0111.html)\n```\ndecode_float32(0b00111111000000000000000000000000)\n=\u003e 0.5\n```\n\n### float の値の変化\n\n```\n0.1\nambientIntensity\tFloat\t0b00111101110011001100110011001101\n\n0.2\nambientIntensity\tFloat\t0b00111110010011001100110011001101\n\n0.4\nambientIntensity\tFloat\t0b00111110110011001100110011001101\n\n0.5\nambientIntensity\tFloat\t0b00111111000000000000000000000000\n\n0.6\nambientIntensity\tFloat\t0b00111111000110011001100110011010\n\n0.9\nambientIntensity\tFloat\t0b00111111011001100110011001100110\n\n1.0\nambientIntensity\tFloat\t0b00111111100000000000000000000000\n\n```\n\n\n\n## 📝 2021/11/27\n\n\nどうもfloat のみ数値が通ってないようなきがする\n\n\n## 📝 2021/11/23\n\n### `node` の`modelMatrix`\n\n`self.get_modelMatrix` とインスタンスメソッドで`modelMatrix` を呼び出していたが、要素のインスタンス変数変更後(`self.position` や`self.rotation` など) に、参照をする手立てがなかった\n\n\n``` .py\nclass Node:\n  def __init__(self):\n    self.modelMatrix: 'matrix'\n    self.position = float3(0.0, 0.0, 0.0)\n    self.rotation = float3(0.0, 0.0, 0.0)\n    self.scale = float3(1.0, 1.0, 1.0)\n    self.modeMatrix = self.get_modelMatrix()\n\n  def get_modelMatrix(self):\n    matrix = matrix_float4x4.translation_x_y_z_(\n      self.position.x, self.position.y, self.position.z)\n    matrix = matrix.rotatedBy_angle_x_y_z_(\n      self.rotation.x, 1.0, 0.0, 0.0)\n    matrix = matrix.rotatedBy_angle_x_y_z_(\n      self.rotation.y, 0.0, 1.0, 0.0)\n    matrix = matrix.rotatedBy_angle_x_y_z_(\n      self.rotation.z, 0.0, 0.0, 1.0)\n    matrix = matrix.scaledBy_x_y_z_(\n      self.scale.x, self.scale.y, self.scale.z)\n    return matrix\n\n```\n\n`modelMatrix` を`@property` として、要素のインスタンス変数変更後に、`modelMatrix` 参照をすると、要素のインスタンス変数の値を反映した情報を受け渡せるようにした\n\n\n``` .py\nclass Node:\n  def __init__(self):\n    self.modelMatrix: 'matrix'\n    self.position = float3(0.0, 0.0, 0.0)\n    self.rotation = float3(0.0, 0.0, 0.0)\n    self.scale = float3(1.0, 1.0, 1.0)\n\n  @property\n  def modelMatrix(self):\n    return self.__get_modelMatrix()\n\n  def __get_modelMatrix(self):\n    matrix = matrix_float4x4.translation_x_y_z_(\n      self.position.x, self.position.y, self.position.z)\n    matrix = matrix.rotatedBy_angle_x_y_z_(\n      self.rotation.x, 1.0, 0.0, 0.0)\n    matrix = matrix.rotatedBy_angle_x_y_z_(\n      self.rotation.y, 0.0, 1.0, 0.0)\n    matrix = matrix.rotatedBy_angle_x_y_z_(\n      self.rotation.z, 0.0, 0.0, 1.0)\n    matrix = matrix.scaledBy_x_y_z_(\n      self.scale.x, self.scale.y, self.scale.z)\n    return matrix\n\n```\n`instanceScene.py` で、要素を変更した際に、`node` の`add_childNode` 内を `render_commandEncoder_parentModelViewMatrix_` しなくても、`modelMatrix` の値更新ができるようになった\n\n\n### このpyMetal のまとめ\n\n現在も、構造として適宜変更が必要。解説として01 から書き始めた場合に、各章で色々なデータを書き直す必要が出てきそう。\n\n\n最終章まで(いくことができれば) 終えることができた時に、再度コードを調整・整形をしつつ、整理として解説の記事を書いていくことですすめてみたいと思う\n\n\n#### テストのドラフトの記事\n\nテストとしてかんたんな記事化については、[pome-ta / draftPythonistaScripts](https://github.com/pome-ta/draftPythonistaScripts/blob/main/articles/metal/draft.md) に記載済み\n\n\n画像や、図式での解説方法などは今後に考えておくことにする\n\n\n### GitHub への`push`\n\n[Working Copy](https://workingcopyapp.com/) では、[GitHub Desktop](https://desktop.github.com/) で`push` すると、アイコンが謎になるので\n\n今回この`push` は、Terminal から実行してみる\n\n\n他のリポジトリでは、気軽にbranch がうまく切れなかったりした。というのもあり\n\n\n\n### PyCharm\n\nインデントをスペース2つという、邪教の設定をして\n\nコードの整形を一気におこなった\n\n\n\n## 📝 2021/11/22\n\n`newBufferWithLength` で生成した、Buffer をどうやってがっちゃんこして、格納するかが鍵\n\n\n`Node` の`modelMatrix` が、想定挙動してくれないな、、、\n\n\n## 📝 2021/11/17\n\n### 画像取得を途中で割り込みすると読めなくなる\n\n解決した😤\n\n\n`renderable.py` 内で、`.metal`(シェーダーコード) を読み込む時に\n\n\n``` .py\nsource = shader_path.read_text('utf-8')\nMTLCompileOptions = ObjCClass('MTLCompileOptions')\noptions = MTLCompileOptions.new()\nlibrary = device.newLibraryWithSource_options_error_(\n      source, options, err_ptr)\n```\n\nと、`MTLCompileOptions.new()` option を入れることで解決\n\n\n以前は、`err_ptr` (`= ctypes.c_void_p()`) をニュルッと差し込んでた。\n\n\nエラーで、library の配列がどうたら（エラーログが見つからない）と怒られてたから\n\nそれをうまいように処理してくれてるのだと思う\n\n\n\n\n## 📝 2021/11/16\n\n### `texturable.py`\n\n画像取得を途中で割り込みすると読めなくなる\n\n\n### `renderable.py`\n\n``` .py\nsource = shader_path.read_text('utf-8')\n\nlibrary = device.newLibraryWithSource_options_error_(\n      source, err_ptr, err_ptr)\n```\n\n\nこの読み込みが、同期で読んでるから？\n\n\n\n\n## 📝 2021/11/15\n\nswift の`do try` をPythonista(Python) `try` でキャッチできない問題\n\n\n### `texturable` のエラー処理\n\ntexture データの`null` を返すオブジェクトを確認して\n\nこちらで手動生成を試みる\n\n\n\n## 📝 2021/11/14\n\n### Swift 適当理解(間違いあり) まとめ\n\niOS Deploument Target: iOS 14.4\n\nSwift Language Version: Swift 4\n\n\n#### `!` と `?`\n\n[Swift初心者向け ?と!の意味](https://qiita.com/Keech/items/2d3824091a83d2c205d3)\n\n\nとりあえず、`?` をつけて、指摘があった部分を`fix` のやつで、なんとか逃げる\n\n\n\nもしかしたら、ここらへんの雑`fix` が原因的なところがあるかもしれん\n\n\n\n#### `at:` -\u003e `index:`\n\n言われるがままに`fix` を連打\n\n\n#### `if #available(iOS 10.0, *)`\n\n`if` での分岐を排除し、\n\n##### 変更前\n\n\n``` before.swift\n    let textureLoader = MTKTextureLoader(device: device)\n    var texture: MTLTexture? = nil\n    let textureLoaderOptions: [String: NSObject]\n    if #available(iOS 10.0, *) {\n      let origin = NSString(string: MTKTextureLoaderOriginBottomLeft)\n      textureLoaderOptions = [MTKTextureLoaderOptionOrigin : origin]\n    } else {\n      textureLoaderOptions = [:]\n    }\n```\n\n##### 変更後\n\n``` after.swift\n    let textureLoader = MTKTextureLoader(device: device)\n    var texture: MTLTexture? = nil\n//    let textureLoaderOptions: [String: NSObject]\n    let origin = NSString(string: MTKTextureLoader.Origin.bottomLeft.rawValue)\n    let textureLoaderOptions = [MTKTextureLoader.Option.origin : origin]\n```\n\n#### `Type of expression is ambiguous without more context` のエラー\n\n\n[Swift MetalKit unknknown return type MTKMesh.newMeshes](https://stackoverflow.com/questions/50224108/swift-metalkit-unknknown-return-type-mtkmesh-newmeshes)\n\n[参照先: Writing a Modern Metal App from Scratch: Part 1](https://metalbyexample.com/modern-metal-1/)\n\nこのやつ\n\n``` .swift\ndo {\n      meshes = try MTKMesh.newMeshes(from: asset,\n                                     device: device,\n                                     sourceMeshes: nil)\n    } catch {\n      print(\"mesh error\")\n    }\n```\n\n\n事前に用意するものを変更して\n\n``` .swift\nvar meshes: [MTKMesh] = []\n```\n\nこんな感じで呼び出す？\n\n``` .swift\n    do {\n      (_, meshes) = try MTKMesh.newMeshes(asset: asset,\n                                     device: device)\n    } catch {\n      print(\"mesh error\")\n    }\n```\n\n#### `Thread 1: signal SIGABRT` のエラー\n\n多分Storyboard が明確に設定されていない？\n\n過去の動くものまで、戻して違いを確認するしかなさそう。。。\n\n\n\n\n\n## 📝 2021/11/13\n\ntexture がうまく反映されんのよな\n\n変な形状での描画はできたけど、色々と確認する部分は多い。。。\n\n### `MDLAsset`\n\nしれっと、何かしらの巻き添いで、呼べてたが\n\n~~ 本来は、`load_framework('ModelIO')` が必要 ~~\n\n↑ 違う、巻き添い呼び出しで問題なさそう\n\n\n\n### Obj ファイル\n\n\n検証用、確認用ファイルの参照先\n\n[9. Model I/O: `mushroom`](https://www.raywenderlich.com/3537-beginning-metal/lessons/9)\n\n\n[29. Textures: `train`](https://www.raywenderlich.com/1258241-3d-graphics-with-metal/lessons/29)\n\n\n参考サイト: [Objファイル基礎](https://yttm-work.jp/model_render/model_render_0001.html)\n\n\n- `.obj`\n  - 頂点\n  - 法線\n\n- `.mtl`\n  - モデル色\n  - テクスチャ\n\n`.mtl` がなくても、`.obj` があればモデル形状を描画が可能\n\n\n### 参照Log\n\nとりあえず走るものとして、\n\n\n[29. Textures: `train`](https://www.raywenderlich.com/1258241-3d-graphics-with-metal/lessons/29)\n\n\n`MDLVertexAttributePosition` = `position`\n\n\n`MDLVertexAttributeNormal` = `normal`\n\n\n\nなどなど、突っ込んだらそれなりな通常な変数にになるかも\n\n```\nvertexDescriptor ---\n\u003cMDLVertexDescriptor: 0x60000024b460 attributes:(\n    \"\u003cMDLVertexAttribute: 0x60000175d9c0 name=position format=Float3 bufferIndex=0 offset=0\u003e\",\n    \"\u003cMDLVertexAttribute: 0x60000175da40 name=normal format=Float3 bufferIndex=0 offset=16\u003e\",\n    \"\u003cMDLVertexAttribute: 0x60000175da80 name=textureCoordinate format=Float2 bufferIndex=0 offset=32\u003e\"\n) layouts:{\n    0 = \"\u003cMDLVertexBufferLayout: 0x600000011030 stride=40\u003e\";\n}\u003e\nvertexDescriptor ---\n\u003cMDLVertexDescriptor: 0x600000254ec0 attributes:(\n    \"\u003cMDLVertexAttribute: 0x60000174b840 name=position format=Float3 bufferIndex=0 offset=0\u003e\",\n    \"\u003cMDLVertexAttribute: 0x60000174b1c0 name=normal format=Float3 bufferIndex=0 offset=16\u003e\",\n    \"\u003cMDLVertexAttribute: 0x60000174b200 name=textureCoordinate format=Float2 bufferIndex=0 offset=32\u003e\"\n) layouts:{\n    0 = \"\u003cMDLVertexBufferLayout: 0x600000008dc0 stride=40\u003e\";\n}\u003e\n```\n\n\n\n### MTLVertexDescriptor\n\n```\nMTLVertexDescriptor ---\n- \u003cMTLVertexDescriptorInternal: 0x600000255440\u003e\n    Buffer 0:\n        stepFunction = MTLVertexStepFunctionPerVertex\n        stride = 40\n        Attribute 0:\n            offset = 0\n            format = MTLAttributeFormatFloat3\n        Attribute 1:\n            offset = 16\n            format = MTLAttributeFormatFloat3\n        Attribute 2:\n            offset = 32\n            format = MTLAttributeFormatFloat2 #0\n  - super: MTLVertexDescriptor\n    - super: NSObject\n    --- --- ---\n```\n\n### MDLVertexDescriptor\n\n\n```\nMDLVertexDescriptor ---\n- \u003cMDLVertexDescriptor: 0x600000258560 attributes:(\n    \"\u003cMDLVertexAttribute: 0x600001767280 name=position format=Float3 bufferIndex=0 offset=0\u003e\",\n    \"\u003cMDLVertexAttribute: 0x600001767300 name=normal format=Float3 bufferIndex=0 offset=16\u003e\",\n    \"\u003cMDLVertexAttribute: 0x600001767340 name=textureCoordinate format=Float2 bufferIndex=0 offset=32\u003e\"\n) layouts:{\n    0 = \"\u003cMDLVertexBufferLayout: 0x600000004c90 stride=40\u003e\";\n}\u003e #0\n  - super: NSObject\n    --- --- ---\n```\n\n\n#### 全体\n\n```\nMTLVertexDescriptor ---\n- \u003cMTLVertexDescriptorInternal: 0x600000255440\u003e\n    Buffer 0:\n        stepFunction = MTLVertexStepFunctionPerVertex\n        stride = 40\n        Attribute 0:\n            offset = 0\n            format = MTLAttributeFormatFloat3\n        Attribute 1:\n            offset = 16\n            format = MTLAttributeFormatFloat3\n        Attribute 2:\n            offset = 32\n            format = MTLAttributeFormatFloat2 #0\n  - super: MTLVertexDescriptor\n    - super: NSObject\n    --- --- ---\nMTLVertexDescriptor ---\n- \u003cMTLVertexDescriptorInternal: 0x6000002584a0\u003e\n    Buffer 0:\n        stepFunction = MTLVertexStepFunctionPerVertex\n        stride = 40\n        Attribute 0:\n            offset = 0\n            format = MTLAttributeFormatFloat3\n        Attribute 1:\n            offset = 16\n            format = MTLAttributeFormatFloat3\n        Attribute 2:\n            offset = 32\n            format = MTLAttributeFormatFloat2 #0\n  - super: MTLVertexDescriptor\n    - super: NSObject\n    --- --- ---\nMDLVertexDescriptor ---\n- \u003cMDLVertexDescriptor: 0x600000258560 attributes:(\n    \"\u003cMDLVertexAttribute: 0x600001767280 name=position format=Float3 bufferIndex=0 offset=0\u003e\",\n    \"\u003cMDLVertexAttribute: 0x600001767300 name=normal format=Float3 bufferIndex=0 offset=16\u003e\",\n    \"\u003cMDLVertexAttribute: 0x600001767340 name=textureCoordinate format=Float2 bufferIndex=0 offset=32\u003e\"\n) layouts:{\n    0 = \"\u003cMDLVertexBufferLayout: 0x600000004c90 stride=40\u003e\";\n}\u003e #0\n  - super: NSObject\n    --- --- ---\nMTLVertexDescriptor ---\n- \u003cMTLVertexDescriptorInternal: 0x600000258560\u003e\n    Buffer 0:\n        stepFunction = MTLVertexStepFunctionPerVertex\n        stride = 40\n        Attribute 0:\n            offset = 0\n            format = MTLAttributeFormatFloat3\n        Attribute 1:\n            offset = 16\n            format = MTLAttributeFormatFloat3\n        Attribute 2:\n            offset = 32\n            format = MTLAttributeFormatFloat2 #0\n  - super: MTLVertexDescriptor\n    - super: NSObject\n    --- --- ---\nMDLVertexDescriptor ---\n- \u003cMDLVertexDescriptor: 0x600000258500 attributes:(\n    \"\u003cMDLVertexAttribute: 0x60000176c340 name=position format=Float3 bufferIndex=0 offset=0\u003e\",\n    \"\u003cMDLVertexAttribute: 0x60000176c380 name=normal format=Float3 bufferIndex=0 offset=16\u003e\",\n    \"\u003cMDLVertexAttribute: 0x60000176c3c0 name=textureCoordinate format=Float2 bufferIndex=0 offset=32\u003e\"\n) layouts:{\n    0 = \"\u003cMDLVertexBufferLayout: 0x600000004ae0 stride=40\u003e\";\n}\u003e #0\n  - super: NSObject\n    --- --- ---\n```\n\n\n## 📝 2021/10/05\n\n\nobj を読んでエクスポートすると、足りない情報ありそう\n\n先によみこんだりするのか？\n\n\n\n`Bundle = ObjCClass('NSBundle')`\n\nでbundle に突っ込んでみる作戦\n\n\n## 📝 2021/10/04\n\n\n`MDLVertexAttributePosition` あたりのを`position` で読む感じになってる\n\n\nずっと **Metal I/O** だと思ってたら **Model I/O** だった😇\n\n\n何にせよ呼び出せない、、、\n\n\n\n\n\n## 📝 2021/09/30\n\n違うサンプルで、mesh 読み込みの仕組みをみる\n\n\n\n\n\n## 📝 2021/09/25\n\n描画できない理由を探るのが難しいな\n\n\n\n## 📝 2021/09/23\n\n\n`objectAtIndexedSubscript_` ? `objectAtIndex`\n\n\n\n\n\n## 📝 2021/09/21\n\n`MTKModelIOVertexDescriptorFromMetal` らへんの呼び出しな面倒\n\n\n\n\n## 📝 2021/09/19\n\ncamera で試行錯誤をしてきたが\n\n\n一度コードを整理してみる\n\n\n### 座標系\n\n- Metal, DirectX\n  - 左手座標系\n\nOpenGL, WebGL\n  - 右手座標系\n\n\n### マシンログ出し\n\n- gameScene\n  - scale なしと、指定の時\n\nそもそも、Shader のコードが違ってた\n\n本機で試してみたところ、端末により描画が違ってた\n\n\n## 📝 2021/09/14\n\n### 原因\n\n`node` の`self.modelMatrix` が値更新されてなかった\n\n\n毎回読み直す処理にしたけど、もう少し手軽にできんかな？\n\n## 📝 2021/09/13\n\n全然呼び出せない\n\n### 実行の順番の整理\n\n- `view`\n  - `GameScene`\n    - `Plane`\n      - ひとつづつの書き出しやる\n  - `Renderer` に、`GameScene` 入れる\n\n\n### 書き換え\n\nクソでかclass になってないか？\n\n\n\n\n## 📝 2021/09/12\n\n差分という卑怯な手を使う\n\n### gameScene\n\n``` .swift\nlet quad2 = Plane(device: device,\nimageName: \"picture.png\")\nquad2.scale = float3(0.5)\nquad2.position.y = 1.5\nquad.add(childNode: quad2)\n  }\noverride func update(deltaTime: Float) {\nquad.rotation.y += deltaTime\n}\n\n```\n\n### Node\n\n``` .swift\nvar position = float3(0)\nvar rotation = float3(0)\nvar scale = float3(1)\nvar modelMatrix: matrix_float4x4 {\nvar matrix = matrix_float4x4(translationX: position.x,\ny: position.y, z: position.z)\nmatrix = matrix.rotatedBy(rotationAngle: rotation.x,\nx: 1, y: 0, z: 0)\nmatrix = matrix.rotatedBy(rotationAngle: rotation.y,\nx: 0, y: 1, z: 0)\nmatrix = matrix.rotatedBy(rotationAngle: rotation.z,\nx: 0, y: 0, z: 1)\nmatrix = matrix.scaledBy(x: scale.x, y: scale.y, z: scale.z)\nreturn matrix\n}\n\n```\n\n``` .swift\nparentModelViewMatrix: matrix_float4x4) {\nfor child in children {\tlet modelViewMatrix = matrix_multiply(parentModelViewMatrix,\nmodelMatrix)\n\n\nparentModelViewMatrix: modelViewMatrix)\n}\nif let renderable = self as? Renderable {\ncommandEncoder.pushDebugGroup(name)\nrenderable.doRender(commandEncoder: commandEncoder,\nmodelViewMatrix: modelViewMatrix)\ncommandEncoder.popDebugGroup()\n\n\n```\n### Plane\n\n``` .swift\nextension Plane: Renderable {\nfunc doRender(commandEncoder: MTLRenderCommandEncoder, modelViewMatrix: matrix_float4x4) {\n```\n\n\n### Renderable\n\n``` .swift\nvar modelConstants: ModelConstants { get set }\nfunc doRender(commandEncoder: MTLRenderCommandEncoder,\nmodelViewMatrix: matrix_float4x4)\n}\t}\n```\n\n### Scene\n\n``` .swift\nfunc update(deltaTime: Float) {}\nfunc render(commandEncoder: MTLRenderCommandEncoder,\ndeltaTime: Float) {\nupdate(deltaTime: deltaTime)\nlet viewMatrix = matrix_float4x4(translationX: 0, y: 0, z: -4)\nfor child in children {\nchild.render(commandEncoder: commandEncoder,\nparentModelViewMatrix: viewMatrix)\n}\n}\n```\n\n\n\n## 📝 2021/09/10\n\n[OpenGLES-Pythonista](https://github.com/Cethric/OpenGLES-Pythonista) は偉大😭\n\n\nまるっと、行列計算お借りした\n\n### モジュール\n\n`ctypes` で呼んでるものたちを分けるか？\n\n\n\n\n\n\n## 📝 2021/09/09\n\n### gl で作ったやつ\n\n```\nGLKMatrix4 {\n{2.439, -0.764, 0.000, 0.000}\n{1.359, 1.371, 0.000, 0.000}\n{0.000, 0.000, -1.001, -1.000}\n{0.000, 0.000, 3.904, 4.000}\n}\n```\n勝った🎉\n\n\n### numpy\n\n\nん？ matrix の私の考え方が間違えているのか\n\n行列の計算だと期待結果が出ないんだが。。。\n\n\nテストで喰わせた結果で一番近そうなのが\n\n\n```.py\nimport numpy as np\n\n\nprojectionMatrix = np.array([\n  [2.7919474, 0.0, 0.0, 0.0],\n  [0.0, 1.5696856, 0.0, 0.0],\n  [0.0, 0.0, -1.001001, -1.0],\n  [0.0, 0.0, -0.1001001, 0.0]])\n\nmodelViewMatrix = np.array([\n  [0.8735571, -0.48672166, 0.0, 0.0],\n  [0.48672166, 0.8735571, 0.0, 0.0],\n  [0.0, 0.0, 1.0, 0.0],\n  [0.0, 0.0, -4.0, 1.0]])\n\n\nmatrix_multiply = np.dot(projectionMatrix, modelViewMatrix)\n'''\n[[ 2.43892547 -1.35890127  0.          0.        ]\n [ 0.76399998  1.37121     0.          0.        ]\n [ 0.          0.          2.998999   -1.        ]\n [ 0.          0.         -0.1001001   0.        ]]\n'''\n\nmatrix_multiply = projectionMatrix * modelViewMatrix\n'''\n[[ 2.43892547 -0.          0.          0.        ]\n [ 0.          1.37121     0.          0.        ]\n [ 0.          0.         -1.001001   -0.        ]\n [ 0.          0.          0.4004004   0.        ]]\n'''\n\nmatrix_multiply = np.multiply(projectionMatrix, modelViewMatrix)\n'''\n[[ 2.43892547 -0.          0.          0.        ]\n [ 0.          1.37121     0.          0.        ]\n [ 0.          0.         -1.001001   -0.        ]\n [ 0.          0.          0.4004004   0.        ]]\n'''\n\n\n```\n\n\n## 📝 2021/09/08\n\n\n```\nrotationMatrix ---\n▿ simd_float4x4([[0.8735571, -0.48672166, 0.0, 0.0], [0.48672166, 0.8735571, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n  -  : \" 0.8736 -0.4867  0.0000  0.0000\"\n  -  : \" 0.4867  0.8736  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000  0.0000  1.0000\"\nviewMatrix ---\n▿ simd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n  -  : \" 1.0000  0.0000  0.0000  0.0000\"\n  -  : \" 0.0000  1.0000  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -4.0000  1.0000\"\nmatrix_multiply ---\n▿ simd_float4x4([[0.8735571, -0.48672166, 0.0, 0.0], [0.48672166, 0.8735571, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n  -  : \" 0.8736 -0.4867  0.0000  0.0000\"\n  -  : \" 0.4867  0.8736  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -4.0000  1.0000\"\n\n```\n\n\n```\nprojectionMatrix ---\n▿ simd_float4x4([[2.7919474, 0.0, 0.0, 0.0], [0.0, 1.5696856, 0.0, 0.0], [0.0, 0.0, -1.001001, -1.0], [0.0, 0.0, -0.1001001, 0.0]])\n  -  : \" 2.7919  0.0000  0.0000  0.0000\"\n  -  : \" 0.0000  1.5697  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -1.0010 -1.0000\"\n  -  : \" 0.0000  0.0000 -0.1001  0.0000\"\nmodelViewMatrix ---\n▿ simd_float4x4([[0.8735571, -0.48672166, 0.0, 0.0], [0.48672166, 0.8735571, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n  -  : \" 0.8736 -0.4867  0.0000  0.0000\"\n  -  : \" 0.4867  0.8736  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -4.0000  1.0000\"\nmatrix_multiply ---\n▿ simd_float4x4([[2.4389255, -0.764, 0.0, 0.0], [1.3589013, 1.37121, 0.0, 0.0], [0.0, 0.0, -1.001001, -1.0], [0.0, 0.0, 3.903904, 4.0]])\n  -  : \" 2.4389 -0.7640  0.0000  0.0000\"\n  -  : \" 1.3589  1.3712  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -1.0010 -1.0000\"\n  -  : \" 0.0000  0.0000  3.9039  4.0000\"\n\n```\n\n\n\n\n`animateBy` の数値をとらないけないから\n\n06 に戻り、時間を取得\n\n```\n|animateBy         |time              |\n|------------------|------------------|\n|0.5083329475362225|0.0166666666666667|\n|0.5166635804183768|0.0333333333333333|\n|0.5249895846353392|0.0500000000000000|\n|0.5333086474616965|0.0666666666666667|\n\n~ 中略 ~\n\n|0.9987527233157389|7.7833333333333110|\n|0.9992716726873019|7.7999999999999776|\n|0.9996519386934261|7.8166666666666442|\n|0.9998934157071104|7.8333333333333108|\n|0.9999960366529593|7.8499999999999774| * top\n|0.9999597730258144|7.8666666666666440|\n|0.9997846348986723|7.8833333333333107|\n|0.9994706709198866|7.8999999999999773|\n|0.9990179682996547|7.9166666666666439|\n\n~ 中略 ~\n\n|0.0009681714824467|10.9333333333334561|\n|0.0005191640530888|10.9500000000001236|\n|0.0002088980887302|10.9666666666667911|\n|0.0000374597723661|10.9833333333334586|\n|0.0000048967246485|11.0000000000001261| * bottom\n|0.0001112179906593|11.0166666666667936|\n|0.0003563940373971|11.0333333333334611|\n|0.0007403567619808|11.0500000000001286|\n|0.0012629995105669|11.0666666666667961|\n\n```\n\n## 📝 2021/09/07\n\n恒例のlog check ⏰\n\n### Swift のバージョン違い\n\n\nsample が、3.0 みたいで、4.0 以上にせないけんし\n\niOS も、面倒回避でバージョン調整をした\n\n\n調整とはいえ、エラーに対して`fix` をポチーして、それでダメなら無理矢理インスタンスを作る作戦\n\n\nmatrix の`print` やら、`dump` やら\n\n```.swift\n    let rotationMatrix = matrix_float4x4(rotationAngle: animateBy,\n                                         x: 0, y: 0, z: 1)\n```\n\n```\nsimd_float4x4([[0.8735571, -0.48672166, 0.0, 0.0], [0.48672166, 0.8735571, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n▿ simd_float4x4([[0.8735571, -0.48672166, 0.0, 0.0], [0.48672166, 0.8735571, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n  -  : \" 0.8736 -0.4867  0.0000  0.0000\"\n  -  : \" 0.4867  0.8736  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000  0.0000  1.0000\"\nsimd_float4x4([[0.86947215, -0.49398196, 0.0, 0.0], [0.49398196, 0.86947215, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n▿ simd_float4x4([[0.86947215, -0.49398196, 0.0, 0.0], [0.49398196, 0.86947215, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n  -  : \" 0.8695 -0.4940  0.0000  0.0000\"\n  -  : \" 0.4940  0.8695  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000  0.0000  1.0000\"\nsimd_float4x4([[0.86532915, -0.501204, 0.0, 0.0], [0.501204, 0.86532915, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n▿ simd_float4x4([[0.86532915, -0.501204, 0.0, 0.0], [0.501204, 0.86532915, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n  -  : \" 0.8653 -0.5012  0.0000  0.0000\"\n  -  : \" 0.5012  0.8653  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000  0.0000  1.0000\"\nsimd_float4x4([[0.8611297, -0.5083853, 0.0, 0.0], [0.5083853, 0.8611297, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n▿ simd_float4x4([[0.8611297, -0.5083853, 0.0, 0.0], [0.5083853, 0.8611297, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n  -  : \" 0.8611 -0.5084  0.0000  0.0000\"\n  -  : \" 0.5084  0.8611  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000  0.0000  1.0000\"\nsimd_float4x4([[0.8568754, -0.5155235, 0.0, 0.0], [0.5155235, 0.8568754, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n▿ simd_float4x4([[0.8568754, -0.5155235, 0.0, 0.0], [0.5155235, 0.8568754, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n  -  : \" 0.8569 -0.5155  0.0000  0.0000\"\n  -  : \" 0.5155  0.8569  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000  0.0000  1.0000\"\nsimd_float4x4([[0.8525681, -0.5226162, 0.0, 0.0], [0.5226162, 0.8525681, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n```\n\n\n\n```.swift\n    let viewMatrix = matrix_float4x4(translationX: 0, y: 0, z: -4)\n```\n\n```\nsimd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n▿ simd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n  -  : \" 1.0000  0.0000  0.0000  0.0000\"\n  -  : \" 0.0000  1.0000  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -4.0000  1.0000\"\nsimd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n▿ simd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n  -  : \" 1.0000  0.0000  0.0000  0.0000\"\n  -  : \" 0.0000  1.0000  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -4.0000  1.0000\"\nsimd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n▿ simd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n  -  : \" 1.0000  0.0000  0.0000  0.0000\"\n  -  : \" 0.0000  1.0000  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -4.0000  1.0000\"\nsimd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n▿ simd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n  -  : \" 1.0000  0.0000  0.0000  0.0000\"\n  -  : \" 0.0000  1.0000  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -4.0000  1.0000\"\nsimd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n▿ simd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n  -  : \" 1.0000  0.0000  0.0000  0.0000\"\n  -  : \" 0.0000  1.0000  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -4.0000  1.0000\"\nsimd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n▿ simd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n  -  : \" 1.0000  0.0000  0.0000  0.0000\"\n  -  : \" 0.0000  1.0000  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -4.0000  1.0000\"\nsimd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n▿ simd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n  -  : \" 1.0000  0.0000  0.0000  0.0000\"\n  -  : \" 0.0000  1.0000  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -4.0000  1.0000\"\nsimd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n```\n\n```.swift\n    let modelViewMatrix = matrix_multiply(rotationMatrix, viewMatrix)\n```\n\n```\nsimd_float4x4([[0.8735571, -0.48672166, 0.0, 0.0], [0.48672166, 0.8735571, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n▿ simd_float4x4([[0.8735571, -0.48672166, 0.0, 0.0], [0.48672166, 0.8735571, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n  -  : \" 0.8736 -0.4867  0.0000  0.0000\"\n  -  : \" 0.4867  0.8736  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -4.0000  1.0000\"\nsimd_float4x4([[0.86947215, -0.49398196, 0.0, 0.0], [0.49398196, 0.86947215, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n▿ simd_float4x4([[0.86947215, -0.49398196, 0.0, 0.0], [0.49398196, 0.86947215, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n  -  : \" 0.8695 -0.4940  0.0000  0.0000\"\n  -  : \" 0.4940  0.8695  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -4.0000  1.0000\"\nsimd_float4x4([[0.86532915, -0.501204, 0.0, 0.0], [0.501204, 0.86532915, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n▿ simd_float4x4([[0.86532915, -0.501204, 0.0, 0.0], [0.501204, 0.86532915, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n  -  : \" 0.8653 -0.5012  0.0000  0.0000\"\n  -  : \" 0.5012  0.8653  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -4.0000  1.0000\"\nsimd_float4x4([[0.8611297, -0.5083853, 0.0, 0.0], [0.5083853, 0.8611297, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n▿ simd_float4x4([[0.8611297, -0.5083853, 0.0, 0.0], [0.5083853, 0.8611297, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n  -  : \" 0.8611 -0.5084  0.0000  0.0000\"\n  -  : \" 0.5084  0.8611  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -4.0000  1.0000\"\nsimd_float4x4([[0.8568754, -0.5155235, 0.0, 0.0], [0.5155235, 0.8568754, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n▿ simd_float4x4([[0.8568754, -0.5155235, 0.0, 0.0], [0.5155235, 0.8568754, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n  -  : \" 0.8569 -0.5155  0.0000  0.0000\"\n  -  : \" 0.5155  0.8569  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -4.0000  1.0000\"\nsimd_float4x4([[0.8525681, -0.5226162, 0.0, 0.0], [0.5226162, 0.8525681, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n▿ simd_float4x4([[0.8525681, -0.5226162, 0.0, 0.0], [0.5226162, 0.8525681, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n  -  : \" 0.8526 -0.5226  0.0000  0.0000\"\n  -  : \" 0.5226  0.8526  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  0.0000 -4.0000  1.0000\"\nsimd_float4x4([[0.8482093, -0.5296612, 0.0, 0.0], [0.5296612, 0.8482093, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, -4.0, 1.0]])\n```\n\n### Challenge の方だけど\n\nなぜか、スケールだけ取れる\n\n```.swift\n  func scaledBy(x: Float, y: Float, z: Float) -\u003e matrix_float4x4 {\n    let scaledMatrix = matrix_float4x4(scaleX: x, y: y, z: z)\n    dump(self)\n    print(self)\n    return matrix_multiply(self, scaledMatrix)\n  }\n\n```\n\n\n同じのが、飛んでいっているかな？\n\n```\n▿ simd_float4x4([[0.9998611, 0.0, 0.016665896, 0.0], [0.0, 1.0, 0.0, 0.0], [-0.016665896, 0.0, 0.9998611, 0.0], [0.0, 0.0, 0.0, 1.0]])\n  -  : \" 0.9999  0.0000  0.0167  0.0000\"\n  -  : \" 0.0000  1.0000  0.0000  0.0000\"\n  -  : \"-0.0167  0.0000  0.9999  0.0000\"\n  -  : \" 0.0000  0.0000  0.0000  1.0000\"\nsimd_float4x4([[0.9998611, 0.0, 0.016665896, 0.0], [0.0, 1.0, 0.0, 0.0], [-0.016665896, 0.0, 0.9998611, 0.0], [0.0, 0.0, 0.0, 1.0]])\n▿ simd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 1.5, 0.0, 1.0]])\n  -  : \" 1.0000  0.0000  0.0000  0.0000\"\n  -  : \" 0.0000  1.0000  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  1.5000  0.0000  1.0000\"\nsimd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 1.5, 0.0, 1.0]])\n▿ simd_float4x4([[0.9994445, 0.0, 0.033327162, 0.0], [0.0, 1.0, 0.0, 0.0], [-0.033327162, 0.0, 0.9994445, 0.0], [0.0, 0.0, 0.0, 1.0]])\n  -  : \" 0.9994  0.0000  0.0333  0.0000\"\n  -  : \" 0.0000  1.0000  0.0000  0.0000\"\n  -  : \"-0.0333  0.0000  0.9994  0.0000\"\n  -  : \" 0.0000  0.0000  0.0000  1.0000\"\nsimd_float4x4([[0.9994445, 0.0, 0.033327162, 0.0], [0.0, 1.0, 0.0, 0.0], [-0.033327162, 0.0, 0.9994445, 0.0], [0.0, 0.0, 0.0, 1.0]])\n▿ simd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 1.5, 0.0, 1.0]])\n  -  : \" 1.0000  0.0000  0.0000  0.0000\"\n  -  : \" 0.0000  1.0000  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  1.5000  0.0000  1.0000\"\nsimd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 1.5, 0.0, 1.0]])\n▿ simd_float4x4([[0.99875027, 0.0, 0.049979173, 0.0], [0.0, 1.0, 0.0, 0.0], [-0.049979173, 0.0, 0.99875027, 0.0], [0.0, 0.0, 0.0, 1.0]])\n  -  : \" 0.9988  0.0000  0.0500  0.0000\"\n  -  : \" 0.0000  1.0000  0.0000  0.0000\"\n  -  : \"-0.0500  0.0000  0.9988  0.0000\"\n  -  : \" 0.0000  0.0000  0.0000  1.0000\"\nsimd_float4x4([[0.99875027, 0.0, 0.049979173, 0.0], [0.0, 1.0, 0.0, 0.0], [-0.049979173, 0.0, 0.99875027, 0.0], [0.0, 0.0, 0.0, 1.0]])\n▿ simd_float4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 1.5, 0.0, 1.0]])\n  -  : \" 1.0000  0.0000  0.0000  0.0000\"\n  -  : \" 0.0000  1.0000  0.0000  0.0000\"\n  -  : \" 0.0000  0.0000  1.0000  0.0000\"\n  -  : \" 0.0000  1.5000  0.0000  1.0000\"\n\n```\n\n```\nself\tsimd_float4x4\t\\n[ [5.948225e-01, 0.000000e+00, -8.038571e-01, 0.000000e+00],\\n  [0.000000e+00, 1.000000e+00, 0.000000e+00, 0.000000e+00],\\n  [8.038571e-01, 0.000000e+00, 5.948225e-01, 0.000000e+00],\\n  [0.000000e+00, 0.000000e+00, 0.000000e+00, 1.000000e+00] ]\\n\n```\n\n### ディレクトリ構造\n\nPythonista と xcode だと見え方違う？\n\n\n- Nodes\n  - Node\n  - Plane\n  - Renderable\n  - Texurable\n\n- Scenes\n  - Scene\n  - GameScene\n\n\n## 📝 2021/09/05\n\nswift やobjective-c の構造体や関数。それでいて、swift の`extension` など\n\n\n無駄に頭で考えてしまって、進捗が悪い\n\n\nクラスメソッドでいくのだろうけど、、、？\n\n\n### `ctypes`\n\n- 構造体 (`Structure`)\n- 共用体 (`Union`)\n\n\n型が同じであれば構造体、違う型でつくるなら共用体\n\n\n初期の数値ってどうなるのだろうか？と小一時間\n\n\n\n\n## 📝 2021/09/04\n\nmatrix 実装がめんどいよぉ、、、\n\n\n## 📝 2021/09/02\n\n\n7 のMatrices に入るにあたり、計算ゴリゴリ書きそうだったので、一時休止\n\n\n\n### 6 のTexture 関係\n\n呼び出しや、mask は完了\n\n#### `texture` を2種類ほど呼び出し\n\nmask をするにあたり、ベースの`texture` の時にはmask を呼び出さない事もあり、そのハンドリングに悩んでいたが\n\n\n`Plane` の`__init__` に、先に定義することで解決\n\n``` .py\nself.texture = None\nself.maskTexture = None\n```\n\n\n#### `__init__` の定義と、class変数\n\n\n見本コードでは、`init` 外の定義も`__init__` で定義させている\n\n色々調べるに、class変数には、あまりメリットなし？な印象があるので\n\nインスタンス変数として、処理していることになる\n\n\nこの書き方で、ええのだろうか？\n\n\n### モジュールわけわけ\n\n7 のMatrices 前にモジュールを分けてしまおうという魂胆\n\n\n\n[[初心者向け] Pythonのパッケージを自作して、パッケージとモジュールへの理解を深めてみる](https://dev.classmethod.jp/articles/python-create-package/)\n\n[Python命名規則一覧](https://qiita.com/naomi7325/items/4eb1d2a40277361e898b)\n\n\n\n`__init__.py` 内の定義とか、ファイル名にドキドキしながら\n\n実装ちう\n\n\n`objc_util` モジュールを書きまくりそうだから調べたら、ダメって書いてあった\n\n\n[自作パッケージ配下の各モジュールに同じモジュールを一括でインポートしたい。](https://teratail.com/questions/217084)\n\n\n\n\n\n## 📝 2021/08/29\n\nbeginningMetal もTexture の章となり、いつもの実装とは違う難しさがでてきた\n\n\n通常(?) のiOS 開発であると、`Assets` に必要なものをガバっと入れて、ゴリッと呼び出すのであろうが(実際そうであるかは知らん)\n\nPythonista では、`path` 定義をしたり、データなのか`URL` なのか？みたいなことなど、自動的に処理してくれそうな部分のケアまで必要であったり(実際がそうであるかは知らん)\n\n\nサンプルコードを丸写しで実行完了ができないので、面倒な部分ではある\n\n\nPythonista でやっている以上、それが必要な作業であると理解をしているが\nどうも、画像処理となると自分の興味のフィールドから少し離れてしまうので\n重い腰となってしまうことがある\n\n\n## 📝 2021/08/24\n\n[mtlvertexformat](https://developer.apple.com/documentation/metal/mtlvertexformat)\n\n\n`.float3` って`ctypes` のでいいのかな、、、\n\n\nまぁ動いてるからヨシ\n\n\n\n\n\n問題なく描画した後に、ちょっと書き換えて実行すると落ちるなぁ\n\n\n## 📝 2021/08/23\n\n恒例ログ取り\n\n\n`swift` サンプルコードの数値確認\n\n\n``` .swift\n// 16\nprint(MemoryLayout\u003cfloat3\u003e.stride)\n\n// float2 = 8\n// float3 = 16\n// float4 = 16\n\ndump(MemoryLayout\u003cfloat2\u003e.size) //  8\ndump(MemoryLayout\u003cfloat3\u003e.size) //  16\ndump(MemoryLayout\u003cfloat4\u003e.size) //  16\n\n// 32\nprint(MemoryLayout\u003cVertex\u003e.stride)\n// .size =\u003e 32\n\n\n\n\nprint(vertices.count)   // 4\n    print(MemoryLayout\u003cVertex\u003e.stride)  //32\n    print(vertices.count *\n            MemoryLayout\u003cVertex\u003e.stride)  // 128\n```\n\n\n## 📝 2021/08/21\n\nサンプルコードに寄せ、コードの構造を変えている\n\n`objc_util` が、エラー = 即落ちなので\n\n\nなかなか、ログが取れずかなり時間を溶かした\n\n\n落ちる瞬間に、エラーのウィンドウが出れば、携帯で動画キャプチャをして、一時停止しながらエラーメッセージを読む（ウィンドウが出ればの話）\n\n\nPython 側のエラーでもマルっと落ちてしまうのがネック\n\n\n### 今回の凡ミス\n\n``` .py\nclass Plane(Node):\n  def __init__(self, device):\n    super().__init__()\n    self.vertices = (ctypes.c_float * 12)(\n      -1.0,  1.0, 0.0,    # v0\n      -1.0, -1.0, 0.0,    # v1\n       1.0, -1.0, 0.0,    # v2\n       1.0,  1.0, 0.0,)   # v3\n    # 色々処理\n    self.buildBuffers(device)\n\n  def buildBuffers(self, device):\n    self.vertexBuffer = device.newBufferWithBytes_length_options_(\n      self.vertices, self.vertices.__len__() * ctypes.sizeof(self.vertices), 0)\n    # 色々処理\n\n  def render_commandEncoder_deltaTime_(commandEncoder, deltaTime):\n  # ↑ `self` 抜けてる\n    super().render_commandEncoder_deltaTime_(commandEncoder, deltaTime)\n\n    self.time += deltaTime\n    animateBy = abs(sin(self.time) / 2 + 0.5)\n    self.constants.animateBy = animateBy\n\n```\n\n\n継承(`Node`) したクラスのオーバーライド時に、`Plane` クラスの関数引数に`self` を入れ忘れてた\n\n\n\n\n\n\n## 📝 2021/08/18\n\n### ディレクトリ整理\n\nディレクトリが散漫しすぎて、ひどいけど`_old` を作ってぶち込んだ\n\n\n\n### beginning metal シリーズ！\n\n\n`setVertexBytes_` 問題がどうにもならず\n\n適当にYoutube 見てたら、御用達サイトの一つ[raywenderlich.com](https://www.raywenderlich.com/) のチャンネルを見つけた\n\n\n[Beginning Metal](https://www.raywenderlich.com/3537-beginning-metal) の[YouTube 動画](https://youtu.be/Gqj2lP7qlAM) (Part が散らかってるので探すのがめんどう) は見れた \u0026 iOS8 swift3 のプロジェクトであったらダウンロードができたので\n\n\n再度一から入門としてやってみる\n\n\n\n\n\n\n## 📝 2021/08/14\n\n\n`setVertexBytes_length_atIndex_` と`setVertexBuffer_offset_atIndex_`\n\n\n`setVertexBytes_` がうまく渡せていない？\n\n\n\n\n\n## 📝 2021/08/13\n\n[Using a Render Pipeline to Render Primitives](https://developer.apple.com/documentation/metal/using_a_render_pipeline_to_render_primitives?language=objc) の、`AAPLShaderTypes.h` 扱い問題\n\n\nそもそも、何かしらの呼び出しがだめかもしれん\n\nうまいログだし方法を考えないといけない\n\n\n\n\n## 📝 2021/08/08\n\n\n[Moving from OpenGL to Metal | raywenderlich.com](https://www.raywenderlich.com/9211-moving-from-opengl-to-metal)\n\n\n\nこれを、[移植してみた](https://github.com/pome-ta/pystaMetalStudy/tree/main/src/matrix/GLKitMath)\n\n\n\nGLKit のmatrix 計算をまるっと\n\n\n[OpenGLES-Pythonista | Cethric](https://github.com/Cethric/OpenGLES-Pythonista)\n\n\nお借りしたけど、3系とかにいつか書き換えたいねー\n\n\n## 📝 2021/08/07\n\n\n頂点のやつ\n\n\n[MTLResourceOptions Enum](https://docs.microsoft.com/en-us/dotnet/api/metal.mtlresourceoptions?view=xamarin-ios-sdk-12)\n\nこれか？\n\n\n## 📝 2021/08/05\n\n### todo\n\nここのreadme.md を整理せな、、、\n\n\n\n### viewのサイズ\n\n\n`-(-float // float)` で小数点切り捨てしてるけど`int(float)` でよかった？\n\n\n\n\n## 📝 2021/08/04\n\n\n### ~~スレッドが一つしか走ってない？~~\n\n\n呼び出すコードまちがえてますた 😇\n\n``` .py\n# 正解\n\ndispatchThreadgroups_threadsPerThreadgroup_()\n```\n\n\n``` .py\n# 間違え\n\ndispatchThreads_threadsPerThreadgroup_()\n```\n\nしかし、そうなると、画面サイズ変わるん？\n\n\n割り算で`int` するし、、、\n\n\n\n\n\n[【Swift Metal】dispatchThreadgroupsの最適化ついて解説](https://hirauchi-genta.com/swift-metal-dispatchthreadgroups/)\n\n[【Swift Metal】thread_position_in_grid等の属性について解説](https://hirauchi-genta.com/swift-metal-attribute/)\n\n\n### Shader 拡張子\n\n\nPythonista で毎回見づらいから、`.js` にした\n\n\n普通に動いてるぽから、よかった\n\n\n\n\n## 📝 2021/08/03\n\n\n### translationMatrix\n\n```\ntranslationMatrix simd_float4x4(\n  [[1.0, 0.0, 0.0, 0.0],\n  [0.0, 1.0, 0.0, 0.0],\n  [0.0, 0.0, 1.0, 0.0],\n  [0.0, 0.0, -3.0, 1.0]]\n)\n```\n\n### scalingMatrix\n\n```\nscalingMatrix simd_float4x4(\n  [[0.5, 0.0, 0.0, 0.0],\n  [0.0, 0.5, 0.0, 0.0],\n  [0.0, 0.0, 0.5, 0.0],\n  [0.0, 0.0, 0.0, 1.0]]\n)\n```\n\n### rotationMatrix\n\n```\nrotationMatrix simd_float4x4(\n  [[1.0, 0.0, 0.0, 0.0],\n  [0.0, 0.7071068, -0.70710677, 0.0],\n  [0.0, 0.70710677, 0.7071068, 0.0],\n  [0.0, 0.0, 0.0, 1.0]]\n)\n```\n\n### projectionMatrix\n\n```\nprojectionMatrix simd_float4x4(\n  [[1.8304877, 0.0, 0.0, 0.0],\n  [0.0, 1.8304877, 0.0, 0.0],\n  [0.0, 0.0, -1.0, -1.0],\n  [0.0, 0.0, -0.0, 0.0]]\n)\n```\n\n\n### size 関係\n\n```\nMemoryLayout\u003cVertex\u003e.size * vertexData.count:  256\nMemoryLayout\u003cUInt16\u003e.size * indexData.count:  72\nMemoryLayout\u003cmatrix_float4x4\u003e.size:  64\nMemoryLayout\u003cUniforms\u003e.size:  64\nindexCount:  36\n--- indexBuffer.length:  72\n--- MemoryLayout\u003cUInt16\u003e.size:  2\n```\n\n```\n# fastMathEnabled: true\n    # 131075  version2_3\n    # case version1_0 = 65536\n    # case version1_1 = 65537\n    # case version1_2 = 65538\n    # case version2_0 = 131072\n    # case version2_1 = 131073\n    # case version2_2 = 131074\n    # case version2_4 = 131076\n```\n\n\n## 📝 2021/08/02\n\n```\n\u003e\u003e\u003e import numpy as np\n\u003e\u003e\u003e np.__version__\n'1.8.0'\n\n```\n\n\nmatrix が雰囲気により、描画がガバガバである😇\n\n\n\n## 📝 2021/07/31\n\n\nndarray \u003c-\u003e ctypes で進めてるけど\n\n変数作るところ(？) で、値が変わる\n\n## 📝 2021/07/29\n\n### 教訓\n\n`int` は`int` で入れる😡\n\n\n特に除算は、`float` になるで、Python に毒されすぎ(言い過ぎ、自分の凡ミス)\n\n\n## 📝 2021/07/28\n\n### matrix\n\nコードの記述はできた。view が正方形でないので三角形が歪だが、スクエアのview だと見本と同じになってる\n\n### メモリコピー\n\n`memcpy` ここの流れを脳を殺し、`Vertex` と同様の投げ方をしてる\n\n\n\n\n\n## 📝 2021/07/27\n\n構造体の作りを、ただの配列にした\n\n\n`ctypes.byref(vertexData)` と呼ばずに直で呼び出せるけど、キモい関数作るデメリットしか感じられん😇\n\n\nNumpy でガチャーっとできるのかしら？そっちの方が有益かもしらん\n\n\n\n\n正直、ポインタ渡すとか意味わからんて、、、、\n\n\n\n## 📝 2021/07/26\n\nまーた、チュートリアルサイト参考先を変える\n\n\n[このリポジトリ](https://github.com/MetalKit/metal)\n\n\n\n\u003e There are two ways we can prepare our class for drawing: either conform to the MTKViewDelegate protocol and implement its drawInView(:) method, or subclass MTKView and override its drawRect(:)method.\n\n\n\u003e We choose the latter, so go ahead and change the class type from NSView to MTKView, and create a new method named render() that has the following content:\n\n\u003e 後者(`drawRect(:)`)を選択するので、先に進んでクラスタイプをNSViewからMTKViewに変更し、次の内容を持つrender（）という名前の新しいメソッドを作成します。\n\n\n\n\noverride はキモいので、`MTKViewDelegate` から、`drawInView(:)` でやる\n\n\n### お、、、\n\nリポジトリと記事にズレあり？とりま、脳内補完で進む\n\n\nmetal 使ったkodelife やりたいなー\n\n\n\n## 📝 2021/07/25\n\n### 構造体からの`length` 確認 その2\n\n\n\u003e `ctypes.sizeof` で良さそう\n\nよくない🙅‍♂️\n\n\n\n#### (多分) `ctypes` の場合は\n\n`ctypes.c_float` が`4` ぽい\n\n指定の型を変えれば良きようになりそうだけど\n\n\n(その数値が何を指してるか\nは調べてない)\n\n\n#### 原因\n\n要素が4つあったので`4` で出したときに\n\n4 * 4 = 16 スタートの\n\nいい感じで`ctypes.sizeof` が、`length` の数値とマッチしたっぽい\n\n\n要素が3だと出したいものが出せない\n\n```\n🙆‍♂️: 96 = (4 * 4) * (3 * 2)\n```\n\n```\n🙅‍♂️: 48 = (4 * 3) * (4)\n↑ 本当は`64` が欲しい\n```\n\n\n\n\n\n\n\n## 📝 2021/07/24\n\n```\nvertices Optional([MetalDay1.Vertex(position: SIMD3\u003cFloat\u003e(-1.0, -1.0, 0.0)),\n                   MetalDay1.Vertex(position: SIMD3\u003cFloat\u003e(1.0, -1.0, 0.0)),\n                   MetalDay1.Vertex(position: SIMD3\u003cFloat\u003e(-1.0, 1.0, 0.0)),\n                   MetalDay1.Vertex(position: SIMD3\u003cFloat\u003e(1.0, 1.0, 0.0))])\n\n▿ Optional([MetalDay1.Vertex(position: SIMD3\u003cFloat\u003e(-1.0, -1.0, 0.0)),\n            MetalDay1.Vertex(position: SIMD3\u003cFloat\u003e(1.0, -1.0, 0.0)),\n            MetalDay1.Vertex(position: SIMD3\u003cFloat\u003e(-1.0, 1.0, 0.0)),\n            MetalDay1.Vertex(position: SIMD3\u003cFloat\u003e(1.0, 1.0, 0.0))])\n\n  ▿ some: 4 elements\n    ▿ MetalDay1.Vertex\n      ▿ position: SIMD3\u003cFloat\u003e(-1.0, -1.0, 0.0)\n        ▿ _storage: Swift.Float.SIMD4Storage\n          - _value: (Opaque Value)\n    ▿ MetalDay1.Vertex\n      ▿ position: SIMD3\u003cFloat\u003e(1.0, -1.0, 0.0)\n        ▿ _storage: Swift.Float.SIMD4Storage\n          - _value: (Opaque Value)\n    ▿ MetalDay1.Vertex\n      ▿ position: SIMD3\u003cFloat\u003e(-1.0, 1.0, 0.0)\n        ▿ _storage: Swift.Float.SIMD4Storage\n          - _value: (Opaque Value)\n    ▿ MetalDay1.Vertex\n      ▿ position: SIMD3\u003cFloat\u003e(1.0, 1.0, 0.0)\n        ▿ _storage: Swift.Float.SIMD4Storage\n          - _value: (Opaque Value)\n---\nindices Optional([0, 1, 2, 1, 2, 3])\n\n▿ Optional([0, 1, 2, 1, 2, 3])\n  ▿ some: 6 elements\n    - 0\n    - 1\n    - 2\n    - 1\n    - 2\n    - 3\n```\n\n\n実機でのプリントデバック\n\n\n``` .swift\nprivate func buildBuffer() {\n    vertexBuffer = mtlDevice.makeBuffer(bytes: vertices, length: vertices.count*MemoryLayout\u003cVertex\u003e.stride, options: [])\n    indexBuffer = mtlDevice.makeBuffer(bytes: indices, length: indices.count*MemoryLayout\u003cUInt16\u003e.stride, options: [])\n\n    print(\"vertexBuffer\", vertices.count*MemoryLayout\u003cVertex\u003e.stride)\n    //  64\n\n    print(\"indexBuffer\", indices.count*MemoryLayout\u003cUInt16\u003e.stride)\n    //  12\n}\n\n```\n\n``` .swift\ncommandEncoder?.setVertexBuffer(vertexBuffer, offset: 0, index: 0)\ncommandEncoder?.setVertexBytes(\u0026uniforms, length: MemoryLayout\u003cUniforms\u003e.stride, index: 1)\nprint(\"Uniforms\", MemoryLayout\u003cUniforms\u003e.stride)\n//  16\ncommandEncoder?.drawIndexedPrimitives(type: .triangle, indexCount: indices.count, indexType: .uint16, indexBuffer: indexBuffer, indexBufferOffset: 0)\nprint(\"indices.count\", indices.count)\n// 6\n\n```\n\n\n\n## 📝 2021/07/23\n\n\n参照コードが点在しすぎだから、そろそろ調整していかないと\n\n\n### 構造体からの`length` 確認\n\n[Using a Render Pipeline to Render Primitives](https://developer.apple.com/documentation/metal/using_a_render_pipeline_to_render_primitives?language=objc) のコード\n\n\n``` objc\n// Pass in the parameter data.\nNSLog(@\"triangleVertices %lu\", sizeof(triangleVertices));\n//  96\n[renderEncoder setVertexBytes:triangleVertices\n                       length:sizeof(triangleVertices)\n                      atIndex:AAPLVertexInputIndexVertices];\n\nNSLog(@\"_viewportSize %lu\", sizeof(_viewportSize));\n//  8\n[renderEncoder setVertexBytes:\u0026_viewportSize\n                       length:sizeof(_viewportSize)\n                      atIndex:AAPLVertexInputIndexViewportSize];\n```\n\n\n\n\nあと、過去のswift で取得した参照のLog とり\n\n``` .swift\nvertices.count\n//  3\n\nMemoryLayout\u003cVertex\u003e.stride\n//  32\n\nlength = vertices.count * MemoryLayout\u003cVertex\u003e.stride\n//96\n\n```\n\n``` .python\nclass Position(ctypes.Structure):\n  _fields_ = [('x', ctypes.c_float), ('y', ctypes.c_float),\n              ('z', ctypes.c_float), ('w', ctypes.c_float)]\n\n\nclass Color(ctypes.Structure):\n  _fields_ = [('r', ctypes.c_float), ('g', ctypes.c_float),\n              ('b', ctypes.c_float), ('a', ctypes.c_float)]\n\n\nclass Vertex(ctypes.Structure):\n  _fields_ = [('position', Position), ('color', Color)]\n\n\nclass PyVertex(ctypes.Structure):\n  _fields_ = [('x', Vertex), ('y', Vertex), ('z', Vertex)]\n\n\nvertexData = PyVertex(\n  Vertex(Position(-0.8, -0.8,  0.0,  1.0), Color(1.0, 0.0, 0.0, 1.0)),\n  Vertex(Position( 0.8, -0.8,  0.0,  1.0), Color(0.0, 1.0, 0.0, 1.0)),\n  Vertex(Position( 0.0,  0.8,  0.0,  1.0), Color(0.0, 0.0, 1.0, 1.0)))\n\n\ndataSize = ctypes.sizeof(vertexData)\n# 96\n```\n\n`ctypes.sizeof` で良さそう\n\n\n\n## 📝 2021/07/21\n\nサイズの取得があやしい\n\nSwift で確認の必要あり？\n\n\n\n\n\n## 📝 2021/07/20\n\n- 色々と参照したサイトの書き方がmix されてるから、整理したい\n- class の書くところがバラバラだから、うまく調整したい\n\n\n## 📝 2021/07/19\n\n実際のSwift 実行での、状況確認\n\n\n頂点の構造体指定の部分\n\n``` .swift\nlet vertices = [Vertex(color: [1, 0, 0, 1], pos: [-1, -1]),\n                Vertex(color: [0, 1, 0, 1], pos: [0, 1]),\n                Vertex(color: [0, 0, 1, 1], pos: [1, -1])]\n```\n\n### log\n\n以下、状況で取得し吐き出し\n\n\n- `dump` でなんか色々と出力するやつ\n\n``` .swift\ndump(vertices)\n```\n\n```\n▿ 3 elements\n  ▿ __C.Vertex\n    ▿ color: SIMD4\u003cFloat\u003e(1.0, 0.0, 0.0, 1.0)\n      ▿ _storage: Swift.Float.SIMD4Storage\n        - _value: (Opaque Value)\n    ▿ pos: SIMD2\u003cFloat\u003e(-1.0, -1.0)\n      ▿ _storage: Swift.Float.SIMD2Storage\n        - _value: (Opaque Value)\n  ▿ __C.Vertex\n    ▿ color: SIMD4\u003cFloat\u003e(0.0, 1.0, 0.0, 1.0)\n      ▿ _storage: Swift.Float.SIMD4Storage\n        - _value: (Opaque Value)\n    ▿ pos: SIMD2\u003cFloat\u003e(0.0, 1.0)\n      ▿ _storage: Swift.Float.SIMD2Storage\n        - _value: (Opaque Value)\n  ▿ __C.Vertex\n    ▿ color: SIMD4\u003cFloat\u003e(0.0, 0.0, 1.0, 1.0)\n      ▿ _storage: Swift.Float.SIMD4Storage\n        - _value: (Opaque Value)\n    ▿ pos: SIMD2\u003cFloat\u003e(1.0, -1.0)\n      ▿ _storage: Swift.Float.SIMD2Storage\n        - _value: (Opaque Value)\n```\n\n\n\n- `print` でざっくり吐き出し\n\n``` .swift\nprint(vertices)\n```\n\n\n```\n[__C.Vertex(color: SIMD4\u003cFloat\u003e(1.0, 0.0, 0.0, 1.0), pos: SIMD2\u003cFloat\u003e(-1.0, -1.0)), __C.Vertex(color: SIMD4\u003cFloat\u003e(0.0, 1.0, 0.0, 1.0), pos: SIMD2\u003cFloat\u003e(0.0, 1.0)), __C.Vertex(color: SIMD4\u003cFloat\u003e(0.0, 0.0, 1.0, 1.0), pos: SIMD2\u003cFloat\u003e(1.0, -1.0))]\n```\n\n\n- 型確認\n\n```\nprint(type(of: vertices))\n```\n\n```\nArray\u003cVertex\u003e\n```\n\n\n\n## 📝 2021/07/04\n\n三角形ハロワ挑戦中\n\n\n\n`vertex` 定義を`ctypes` で問題がないのか悩みつつ、色々なリファレンスを調査中\n\n\nxcode 上で定義するもの(呼び出す？)もあり、まだ整理できていない\n\n\n\n## 📝 2021/07/03\n\nシェーダー描画用として関数分けて書いた方が良さそう\n\n## 📝 2021/07/02\n\n```\ncommandBuffer = commandQueue.commandBuffer()\nAttributeError: 'NoneType' object has no attribute 'commandBuffer'\n\n```\n\n\ndelegate のinitialize で、`commandQueue` を持たせる方法が見つからなかったので\n\n\nview でdelegate をセットする前に\n\n\n```\nrenderer = pyRenderer.alloc().init()\nrenderer.commandQueue = self.mtkView.device().newCommandQueue()\nself.mtkView.setDelegate_(renderer)\n\n```\n\nとして、delegate内のメソッドでも呼べるようにしてみた\n\n\n\n\n\nずっと、呼んでるかもで、いきなり落ちる時はある、、、\n\n\n## 📝 2021/07/01\n\n### delegate まわり\n\n`drawInMTKView_` の呼び出し\n\n\n\n\n```\nrenderEncoder = commandBuffer.renderCommandEncoderWithDescriptor_(\n    renderPassDescriptor)\n\nrenderEncoder.endEncoding()\ncommandBuffer.presentDrawable_(view.currentDrawable())\ncommandBuffer.commit()\n```\n\nここは、一括で処理しないと落ちた\n\n`renderEncoder` 格納のみ書いてて、だめだと思って`commit()` までだーっと書いたら行けた\n\n\n#### `commandBuffer`\n\n初回呼び出しの数秒後(5秒くらい)と、2回目以降の呼び出し直後で以下エラー吐き出し\n\n```\ncommandBuffer = commandQueue.commandBuffer()\nAttributeError: 'NoneType' object has no attribute 'commandBuffer'\n\n```\n\n\nPython 側ではなくobjc-util 側だから取り回しがめんどう\n\n\n## 📝 2021/06/30\n\n`CAMetalLayer` がもやっとするので、`MTKView` かなぁと\n\n\n[Metal 3D Graphics Part 1: Basic Rendering](https://donaldpinckney.com/metal/2018/07/05/metal-intro-1.html) これ参考にしてる\n\n順番にフォルダ作ってやってみる\n\n\n### 方針\n\n\nいつもほぼ、一緒だけど\n\n\nなるべく、`objc_util` を避けつつ実装\n\nui モジュールで行けるなら行ける的な\n\n\n`View` classがクソでかになりそうだけども、ビジュアル系(?) って往々にしてそうなりがちな気がしてるから今の所そのまま\n\n\n`setなんたら_(なにか)` で呼べるものは、`set` で呼ぶ\n\n\n\n## 📝 2021/06/29\n\nProtocol の `MTLDevice`\n\n```\nMTLCreateSystemDefaultDevice = c.MTLCreateSystemDefaultDevice\n\nMTLCreateSystemDefaultDevice.argtypes = []\nMTLCreateSystemDefaultDevice.restype = ctypes.c_void_p\ndevice = ObjCInstance(MTLCreateSystemDefaultDevice())\n\n```\n\n`MTLBuffer`\n\n```\nlet dataSize = vertexData.count * MemoryLayout.size(ofValue: vertexData[0])\nvertexBuffer = device.makeBuffer(bytes: vertexData, length: dataSize, options: [])\n```\n```\ndataSize = len(vertexData) * 16\nvertexBuffer = device.newBufferWithBytes_length_options_(ns(vertexData), dataSize, 0)\n```\n`float` だから16 やろ！という安直な考え\n\n\nループの処理の部分で無理しそうと感じてる\n\n\n\n\n## 📝 2021/06/13\n\n\n``` .py\nfrom objc_util import *\nfrom pprint import pprint\n\npprint(dir())\n\n'''\n['CGAffineTransform',\n 'CGFloat',\n 'CGPoint',\n 'CGRect',\n 'CGSize',\n 'CGVector',\n 'LP64',\n 'NSArray',\n 'NSBundle',\n 'NSData',\n 'NSDictionary',\n 'NSEnumerator',\n 'NSInteger',\n 'NSMutableArray',\n 'NSMutableData',\n 'NSMutableDictionary',\n 'NSMutableSet',\n 'NSMutableString',\n 'NSNotFound',\n 'NSNumber',\n 'NSObject',\n 'NSRange',\n 'NSSet',\n 'NSString',\n 'NSThread',\n 'NSUInteger',\n 'NSURL',\n 'NSUTF8StringEncoding',\n 'NS_UTF8',\n 'ObjCBlock',\n 'ObjCClass',\n 'ObjCClassMethod',\n 'ObjCInstance',\n 'ObjCInstanceMethod',\n 'POINTER',\n 'Structure',\n 'UIApplication',\n 'UIBezierPath',\n 'UIColor',\n 'UIEdgeInsets',\n 'UIImage',\n 'UIView',\n '__annotations__',\n '__builtins__',\n '__cached__',\n '__doc__',\n '__file__',\n '__loader__',\n '__name__',\n '__package__',\n '__spec__',\n 'byref',\n 'c',\n 'c_bool',\n 'c_byte',\n 'c_char',\n 'c_char_p',\n 'c_double',\n 'c_float',\n 'c_int',\n 'c_int32',\n 'c_long',\n 'c_longlong',\n 'c_short',\n 'c_ubyte',\n 'c_uint',\n 'c_ulong',\n 'c_ulonglong',\n 'c_ushort',\n 'c_void_p',\n 'create_objc_class',\n 'load_framework',\n 'ns',\n 'nsdata_to_bytes',\n 'nsurl',\n 'on_main_thread',\n 'pointer',\n 'pprint',\n 'release_global',\n 'retain_global',\n 'sel',\n 'sizeof',\n 'uiimage_to_png']\n\n'''\n\n```\n\n\n## 📝 2021/06/11\n\n\n`objc-util` と`ctypes` を使う\n\n\n```\nMTLCreateSystemDefaultDevice = c.MTLCreateSystemDefaultDevice\nMTLCreateSystemDefaultDevice.argtypes = []\nMTLCreateSystemDefaultDevice.restype = c_void_p\n\n```\n\n`CAMetalLayer` ではなく、`MTKView` かなぁ\n\n- `class`\n- `InstanceMethod`\n\t- `()` で呼ぶ\n- `function`\n\t- `c.` で呼び出す\n\n\n\n- [Is it possible to use MetalKit with objc_util | forum.omz-software.com](https://forum.omz-software.com/topic/6646/is-it-possible-to-use-metalkit-with-objc_util)\n\n- [Metal を使って10万個のパーティクルを描画しよう](https://qiita.com/naru-jpn/items/9f4f1624495f3e72d6f9)\n\t- [naru-jpn / 100000-particles](https://github.com/naru-jpn/100000-particles)\n- [Metal Tutorial: Getting Started | raywenderlich.com](https://www.raywenderlich.com/7475-metal-tutorial-getting-started)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpome-ta%2Fpystametalstudy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpome-ta%2Fpystametalstudy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpome-ta%2Fpystametalstudy/lists"}