AIプログラムとかUnityゲーム開発について

探索や学習などを活用したAI系ゲームを作りたいと思います。

UnityTexturePaintを試す

qiita.com

上記で公開されているUnityTexturePaintを試してみた。
SDユニティちゃんにペイントしている画像もあったんで、SkinnedMeshにも対応してるのかな?と思ったんですが、
DynamicCanvasの仕様はmesh前提の模様?

とりあえずmeshで試してみましたが、meshならpaintできました。

f:id:yasu9780:20170223090006p:plain
↑なぜかサンプルを実行すると右側(mesh)の顔のテクスチャがおかしくなる
 左はSkkinedMeshなのでDynamicCanvasはAddできない。



腕はもともと左右対象テクスチャなので仕方ないですが、足はちゃんと左右別に濡れました。
このアセットは、元々のテクスチャをRenderTextureに読み込んで、meshCollider上の頂点のUVを求めて、RenderTextureにペイントするという仕組みのようです。
したがって、このRenderTexureを保存すれば、ペイントしたテクスチャが得られれるし、
もしくはこのRenderTextureを、SkinnedMeshのtextureとして使用できれば、連携できるかもしれない?


http://d2ujflorbtfzji.cloudfront.net/key-image/7b2ccc3b-b374-49f9-af36-95c302238629.jpg

https://www.assetstore.unity3d.com/jp/#!/content/61022
UVPaint買えば、SkinnedMeshにも塗れて、すべて解決なんでしょうけど、$54は高い(´・ω・`)



UnityでRenderTextureをファイルに保存 | Psychic VRラボの殴り書き


http://d2ujflorbtfzji.cloudfront.net/key-image/16ec5972-dc3c-4f23-a30e-6899b9c20b47.jpg

https://www.assetstore.unity3d.com/jp/#!/content/26286
>• 新機能スキン処理メッシュのペイント

Paint in 3Dが、SkinnedMeshに対応しているらしいが、定かではない。
なんとか確認できないかなあ。
$27かあ。

カウンタックに傷がついているが、法線マップのテクスチャに落書きする仕組み。面白い。



meshが対象だけど無料アセットがあった
https://www.assetstore.unity3d.com/jp/#!/content/33506
www.youtube.com


http://codeartist.mx/tutorials/dynamic-texture-painting/
技術解説が分かりやすい

MeshColliderの頂点にRaycastして、hit.textureCoordにUV座標がすでに入っている模様。
銃の弾痕や血のりなら、raycastで十分動きそう。

bool HitTestUVPosition(ref Vector3 uvWorldPosition){
 RaycastHit hit;
 Vector3 mousePos=Input.mousePosition;
 Vector3 cursorPos = new Vector3 (mousePos.x, mousePos.y, 0.0f);
 Ray cursorRay=sceneCamera.ScreenPointToRay (cursorPos);
  if (Physics.Raycast(cursorRay,out hit,200)){
     MeshCollider meshCollider = hit.collider as MeshCollider;
   if (meshCollider == null || meshCollider.sharedMesh == null)
       return false; 
   Vector2 pixelUV = new Vector2(hit.textureCoord.x,hit.textureCoord.y);
   uvWorldPosition.x=pixelUV.x;
   uvWorldPosition.y=pixelUV.y;
   uvWorldPosition.z=0.0f;
   return true;
  }
  else{ 
   return false;
  }
 }