Skinned Metaball Builder Manual (English)

Skinned Metaball Builder Manual

Store URL :

https://www.assetstore.unity3d.com/en/#!/content/38054

Support :

mail : nkdtr2011@gmail.com

twitter : @NKDTR (usually tweets in Japanese, but can reply in English, too)

 

What's new

ver 1.121 released(2020/12/10)

-Added a sample material with vertex color

ver 1.12 released(2020/12/09)

-Vertex color supported (with blending between nodes)

But not for "IncrementalModeling" mode yet.

f:id:nkdtr:20201208142737p:plain

 

ver 1.10 released(2015/09/17)

-new feature "IncrementalModeling" mode

 -introduction -> (http://nkdtr.hatenablog.com/entry/2015/09/19/231458)

-"Place Metaball" shortcut changed to "Shift+Ctrl(Command)+E"

  (it was "Shift+Ctrl(Command)+C" before, being the same as "Open console")



1. Introduction

 Introduction of "Skinned Metaball Builder" and quick start guide.

 

nkdtr.hatenablog.com

 

 

2. Reference

 Properties, Menu Commands, APIs.

 

nkdtr.hatenablog.com

 

3. Tips

 Tips.

 

nkdtr.hatenablog.com

 

Skinned Metaball Builder Manual -Introduction- (English)

 

Skinned Metaball Builder Manual -Introduction-

 

Brief Summary 

"Skinned Metaball Builder" is a Unity Asset that provides a functionality of Making Mesh data via metaball with features:


Works on editor and at runtime.

www.youtube.com

 

- No dependency on platforms.


- Created mesh can be saved as an asset.


- Skinned (optional) so that mesh can be animated.

www.youtube.com


- With "skeleton" objects for various use.

 

- Support simple linear-projection texture mapping

www.youtube.com

 

- Fully implemented with Unity C# script, letting you customize.

 

Quick Start

youtu.be

<Turn on "CC" for explanation.

  1. Drag and drop "Metaball/Prefabs/SkinnedSeed" into your scene.
  2. Choose "SkinnedSeed/SourceTree" in hierarchy.
  3. "Ctrl+Shift+C" or "Command+Shift+C" to create a new metaball node.
  4. Move it, modify its "base radius" as you like.
  5. Repeat 3-4 (Changing node selection to be the parent of new node).
    The hierarchy under "SourceTree" is reflected into the "skeleton" generated later.
  6. "Ctrl+Shift+R" or "Command+Shift+R" to generate mesh.
  7. Press "run" button in editor,
    select some node under "SkinnedSeed/BoneRoot",
    and rotate it to confirm that your mesh transforms.
  8. "Metaball->SavePrefab" to save full prefab
    or "Metaball->SaveMesh" to save mesh only.

Samples

Three samples within package.

Each implementation is quite simple and easy,
but introduces well about this asset.

 

1.Dungeon

www.youtube.com

"Dungeon" sample shows how to modify mesh at runtime.

You can walk and dig through metaball-modeled dungeon.

 

Controls:

A,W,S,D to move

Space to "dig"

Mouse move to look around 

 

2.Animations

f:id:nkdtr:20150603172052p:plain

"Animation" sample shows how to animate skinned mesh.

Two objects are contained:

-"Golem" : Unity animation

-"Tentacle" : Physics (joint)

3.Models

Various objects :)

 

 

Technical Introduction

Knowing about the algorithm helps you to find good parameter values.

Creating a metaball surface

 

1. Calcurate and fill scalar field by metaballs information (center, radius and density).

2. Create mesh data from the scalar field via "marching cubes" algorithm( Marching cubes - Wikipedia, the free encyclopedia ).

 

 

 

Limitations

  • Numbers of grid cells and vertices are limited (1000000/300000 by default).
    These are defined in MetaballBuilder.cs.
    Search "_maxGridCellCount", "_maxVertexCount".
    Be careful : building mesh with too large values may Freeze your system.
  • Rebuilding mesh may take long time depending largely on the grid size.
    Per-frame rebuild is not recommended (excluding cases that you require low-resolution metaball or you suppose your application to run on a monster PC).
  • Only one material can be applied per mesh.
  • Texture mapping is supported but simple linear-projection only.

 

Skinned Metaball Builder Manual -Reference- (English)

Skinned Metaball Builder Manual -Reference-

 

0. Menu Commands

 

f:id:nkdtr:20150604194340p:plain

 

Save Prefab :

 Enabled only when a GameObject under MetaballSeed is selected.

 Saves selected metaball structure as a prefab.

 (If you drag & drop it to the project view (normal process of creating prefab), mesh data will not be set on the prefab because the mesh data is not asset but belongs to scene).

Save Mesh :

 Enabled only when a GameObject under MetaballSeed is selected.

 Saves mesh data only as an asset.

 The mesh data can be used for mesh filter, mesh collider and so on.

RebuildMesh :

 Enabled only when a GameObject under MetaballSeed is selected.

 Builds mesh by the metaball nodes.

CreateChild :

 Enabled only when a GameObject under MetaballNode is selected.

 Adds a GameObject with MetaballNode component under the selected GameObject.

 

1. SkinnedMetaballSeed / StaticMetaballSeed component

 Component to build a metaball mesh.

There are Skinned and Static MetaballSeed component.

Skinned doubles as Static except that building mesh costs a little bit higher (in memory usage and calculation time).

 

Properties

 If you use prefab (two prefabs are contained in folder "Metaball/Prefabs"), all the properties required for just making your mesh are set.

But this document will help you adjust properties for your application.

f:id:nkdtr:20150604160409p:plain

Bone Root :

 Node under which "skeleton" objects are automatically constructed by this tool.

 Also used for SkinnedMeshRenderer's "RootBone".

Source Root :

 Node under which metaball data is defined by user (or application script).

Every GameObject under this is supposed to have "MetaballNode" component.

 Shortcut command "Ctrl(Command) + Shift + C" (create child metaball node) is enabled when a GameObject under this is selected.

Cell Obj Prefab :

 Prefab for nodes under constructed "skeleton".

 Component "MetaballCellObject" is required to be attached.

 This can be null if you don't need special behavior of your metaball at all.

Grid Size :

 Size of cells in grid (refer http://en.wikipedia.org/wiki/Marching_cubes for details).

 Small size means, high-def mesh and high-processing cost,

and large size vice versa.

Auto Grid Size (Ver1.02~)

 Ignoring "Grid Size", use automatically decided grid size by "Auto Grid Quality".

Auto Grid Quality (Ver1.02~)

 Parameter to define grid size (if Auto Grid Size is checked).

Higher value means higher resolution of mesh (small grid size).

UV Project Node :

 Guide node for texture coordinates.

 Wired cube is displayed as a gizmo to show how the texture is applied.

 Using non-repeat ("wrap mode"=clamp) texture is easy way to confirm how this works.

Power Threshold :

 Value to determine "inside" points from scalar field calculated via metaball.

 Smaller threshold means larger area becomes inside ( larger mesh created ).

Base Radius :

 This is just for editor.

 Radius of created metaball node is set to this value by default.

B Reverse :

 If true, create mesh become reverse-surfaced.

 Useful to create dungeons (see "Dungeon" sample).

B Use Fixed Bounds :

 If true, following property "Fixed Bounds" is enabled,

so that marching cubes grid area is fixed.

 If false, bounds are automatically calcurated by metaballs info.

 This is useful if you want your mesh to be stable (otherwise, change of bounding box have a slight effect on each vertex position).

 But be careful, mesh will be cut off at the bounds.

Fixed Bounds :

 See "B Use Fixed Bounds".

B Use Color :
 If true, created mesh contains vertex colors.

Each color is interpolated between MetaballNodes.

 

SkinnedMesh (SkinnedMetaballSeed) :

 Renderer to receive the created mesh.

MeshFilter (StaticMetaballSeed) :

 Mesh filter to receive the created mesh.

 

 

APIs

void CreateMesh();

 Recreate mesh by metaballs information.

Same effect as menu command "Rebuild Mesh".

 

Mesh Mesh { get; set; } 

 Get or set current mesh data.

 

2. Metaball Node component

 

 

f:id:nkdtr:20150604203818p:plain

Properties

Base Radius 

 Radius of metaball.

Be careful that metaball radius is not affected by scale of transform.

B Subtract

 If true, metaball become subtractive.

Base Color

 Color of node, applied to vertex colors if the MetaballSeed is checked with "B Use Color"

【UE4】 マテリアルエディタのシェーダーコード生成についてちょっとね

# 結論
* Customノードは関数、頑張れば別のCustomノードで呼び出して使える
* MaterialFunctionは展開される。Customノードからの呼び出しはできない

 

# 実験
1. Customノードを関数として呼び出してみる

以下の条件を満たすときこれが可能。
* 呼び出されるCustom関数が実際に使われている(使われていないとコードから除外される)
* 呼び出されるCustom関数が呼び出し部分より手前で定義されている

f:id:nkdtr:20141216003142p:plain

こんなのを作った。

sin_custom の中身

sin(x)

test_customの中身

CustomExpression0(Parameters, x)


sin_customには0を入力しているので出力も0.

それをAddに使っているので実際には何の効力もないが、

無理やりにでも使っておかないとコードが生成されないのでこんな感じにした。

test_customの中身が今回のミソで、

Customノードがシェーダーコードに変換されるとき、

* CustomExpressionX(Xには0から順に整数が割り当てられる)という名前の関数になる

* Parametersという名前の引数が最初に付加される

ということを反映している。

実際のコードはWindow->HLSL Code で見ることができ、

今回のsin_customについては以下のようなコードに変換されていた。

 

MaterialFloat3 CustomExpression0(FMaterialPixelParameters Parameters,MaterialFloat x)
{
return sin(x);
}

 

関数名につく数字はシェーダーコードが生成されるたびに割り当てなおされるので、

マテリアルをいじると変わる場合がある。

したがってこの呼び出し方はよほどの事情がない限り行わない方がよい。

 

なお、WorldPositionOffsetなど頂点シェーダーとして解釈される部分についてはParametersの型が異なってくるため、ピクセルシェーダー側との互換性が無い。

 

2. MaterialFunctionノードによるシェーダーコードの検証

f:id:nkdtr:20141216004612p:plain

こんなのを作った。

コードを見つけやすいように0.12345という変な値を入れておいた。

出てきたシェーダーコードがこれ。

half3 GetMaterialEmissiveRaw(FMaterialPixelParameters Parameters)
{
MaterialFloat Local0 = (MaterialFloat2(0.00000000,0.00000000).r * MaterialFloat2(0.12345000,0.00000000).r);
MaterialFloat Local1 = (MaterialFloat2(0.00000000,0.00000000).g * MaterialFloat2(0.12345000,0.00000000).g);
MaterialFloat Local2 = (Local0 - Local1);
MaterialFloat Local3 = (MaterialFloat2(0.00000000,0.00000000).r * MaterialFloat2(0.12345000,0.00000000).g);
MaterialFloat Local4 = (MaterialFloat2(0.00000000,0.00000000).g * MaterialFloat2(0.12345000,0.00000000).r);
MaterialFloat Local5 = (Local3 + Local4);
MaterialFloat3 Local6 = (MaterialFloat3(MaterialFloat2(Local2,Local5),0) + Material.VectorExpressions[0].rgb);
return Local6;;
}

どう見ても展開されている。

MF_MultComplex はVector2を複素数と見なして乗算した結果を返すもので、

一応載せておくと下のようなもの。

f:id:nkdtr:20141216004836p:plain

実装内容によって展開されないこともあるのかもしれないが、

試した限りではこういう結果になった。