Skip to content

Commit

Permalink
Update for .unitypackage release
Browse files Browse the repository at this point in the history
  • Loading branch information
mapluisch committed Mar 23, 2024
1 parent ba4161a commit 04763df
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 69 deletions.
8 changes: 8 additions & 0 deletions Assets/Prefabs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions Assets/Prefabs/TripoSR.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &958493935533882903
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2093829567159734765}
- component: {fileID: 3884133589274479110}
m_Layer: 0
m_Name: TripoSR
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2093829567159734765
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 958493935533882903}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &3884133589274479110
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 958493935533882903}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 017d21c0f4b3ae432a2c87dcc41f49a3, type: 3}
m_Name:
m_EditorClassIdentifier:
pythonPath: /home/martin/anaconda3/bin/python
autoAddMesh: 1
autoAddPhysicsComponents: 1
autoFixRotation: 1
moveAndRename: 1
moveAndRenamePath: Models
showDebugLogs: 1
images:
- {fileID: 2800000, guid: a31691d6a3e934626a9c7803452e0438, type: 3}
device: cuda:0
pretrainedModelNameOrPath: stabilityai/TripoSR
chunkSize: 8196
marchingCubesResolution: 256
noRemoveBg: 0
foregroundRatio: 0.85
outputDir: output/
modelSaveFormat: obj
render: 0
7 changes: 7 additions & 0 deletions Assets/Prefabs/TripoSR.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

121 changes: 58 additions & 63 deletions Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -123,68 +123,6 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &302514085
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 302514087}
- component: {fileID: 302514086}
m_Layer: 0
m_Name: TripoSR
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &302514086
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 302514085}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 017d21c0f4b3ae432a2c87dcc41f49a3, type: 3}
m_Name:
m_EditorClassIdentifier:
pythonPath: /home/martin/anaconda3/bin/python
autoAddMesh: 1
autoAddPhysicsComponents: 1
autoFixRotation: 1
moveAndRename: 1
moveAndRenamePath: Models
showDebugLogs: 1
images:
- {fileID: 2800000, guid: a31691d6a3e934626a9c7803452e0438, type: 3}
device: cuda:0
pretrainedModelNameOrPath: stabilityai/TripoSR
chunkSize: 8196
marchingCubesResolution: 256
noRemoveBg: 0
foregroundRatio: 0.85
outputDir: output/
modelSaveFormat: obj
render: 0
--- !u!4 &302514087
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 302514085}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &963194225
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -477,11 +415,68 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1001 &5756738533591745000
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 958493935533882903, guid: 0633bed2e2396b47fb15e8154b69cc2a, type: 3}
propertyPath: m_Name
value: TripoSR
objectReference: {fileID: 0}
- target: {fileID: 2093829567159734765, guid: 0633bed2e2396b47fb15e8154b69cc2a, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2093829567159734765, guid: 0633bed2e2396b47fb15e8154b69cc2a, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2093829567159734765, guid: 0633bed2e2396b47fb15e8154b69cc2a, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2093829567159734765, guid: 0633bed2e2396b47fb15e8154b69cc2a, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2093829567159734765, guid: 0633bed2e2396b47fb15e8154b69cc2a, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2093829567159734765, guid: 0633bed2e2396b47fb15e8154b69cc2a, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2093829567159734765, guid: 0633bed2e2396b47fb15e8154b69cc2a, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2093829567159734765, guid: 0633bed2e2396b47fb15e8154b69cc2a, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2093829567159734765, guid: 0633bed2e2396b47fb15e8154b69cc2a, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2093829567159734765, guid: 0633bed2e2396b47fb15e8154b69cc2a, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0633bed2e2396b47fb15e8154b69cc2a, type: 3}
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
m_Roots:
- {fileID: 963194228}
- {fileID: 2058954808}
- {fileID: 302514087}
- {fileID: 5756738533591745000}
- {fileID: 1257019522}
2 changes: 1 addition & 1 deletion Assets/Shaders/VertexColorShader.shader
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Shader "Custom/VertexColorWithNormals" {
Shader "Custom/VertexColorShader" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
}
Expand Down
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This project integrates TripoSR, a "a state-of-the-art open-source model for fas

Thus, this project enables the transformation of 2D images into textured 3D meshes within Unity (both in Editor and in Playmode), useful for various applications such as game asset creation or rapid prototyping.

The generated 3D meshes are imported using a modified vertex color importer (based on [Andrew Raphael Lukasik's importer](https://gist.github.com/andrew-raphael-lukasik/3559728d022a4c96f491924f8285e1bf)) and auto-assigned to a base Material with custom shader to utilize and display the vertex colors correctly with normal lighting.
The generated 3D meshes are imported using a modified vertex color importer (based on [Andrew Raphael Lukasik's importer](https://gist.github.com/andrew-raphael-lukasik/3559728d022a4c96f491924f8285e1bf)) and auto-assigned to a base Material with custom shader to utilize and display the vertex colors correctly (without surface normals, though).

Tested with Unity 2022.3.22f1 running on Windows 11 and Ubuntu 22.04.

Expand All @@ -26,10 +26,22 @@ https://github.com/mapluisch/TripoSR-for-Unity/assets/31780571/d6b85653-a672-495


## Setup

### Integrating the .unitypackage into your project
0. Download the latest release `.unitypackage` and import it into your project (`Assets > Import Package`).
1. `cd` into the `Assets` folder of your Unity project (using Command Prompt, Terminal, ...) and clone the latest repo of TripoSR: `git clone https://github.com/VAST-AI-Research/TripoSR.git`.
2. After cloning TripoSR, `cd` into the TripoSR folder that you just created by cloning the repo.
3. Run `pip install --upgrade setuptools`, `pip install torch` (in case you don't have PyTorch installed) and `pip install -r requirements.txt`.
3. Add the `TripoSR` Prefab (found in `Assets > Prefabs`) to your scene.
4. Configure the path to your python executable in the `TripoSR` GameObject within your scene: For Windows, run `where python` within Command Prompt. For Unix, run `which python` within Terminal.
5. Configure the other public variables in the Inspector as needed.

### Using this repo's Unity project
0. Clone this repo.
1. Ensure you have Python installed on your system.
2. Run `pip install --upgrade setuptools`, `pip install torch` (in case you don't have PyTorch installed) and `pip install -r requirements.txt` from within this project's `Assets/TripoSR` folder.
3. In Unity, create a GameObject and attach the `TripoSRForUnity` script (or simply open up my `SampleScene`).
4. Configure the path to your python executable: For Windows, run `where python` within Command Prompt. For Unix, run `which python` within Terminal.
3. In Unity, add the `TripoSR` Prefab to the scene (or simply open up my `SampleScene`).
4. Configure the path to your python executable in the `TripoSR` GameObject within your scene: For Windows, run `where python` within Command Prompt. For Unix, run `which python` within Terminal.
5. Configure the other public variables in the Inspector as needed.

## Usage
Expand All @@ -50,8 +62,10 @@ All TripoSR parameters are exposed by my script. Feel free to change them as you

I've made some of them `ReadOnly` within the Inspector, since you shouldn't really change those vars (e.g. model name, device to use). You can still change them within the script of course.

## Contributions
Contributions are welcome. Feel free to open issues for bugs/features (related to my Unity integration) or submit PRs.
## Known Issues
TripoSR `.obj`s only consist of `v`s and `f`s, surface normals are not calculated. When Unity calculates the normals upon import, they are not smoothed correctly (even when using high smoothing angles).

For now, I've disabled normal calculation - feel free to create a PR if you know how to correctly handle this issue.

## License
This project is licensed under the MIT License. See `LICENSE` for more information.
Expand Down

0 comments on commit 04763df

Please sign in to comment.