Unity3D Mesh.bindposes
来源:互联网 发布:达内科技 设计网络营 编辑:程序博客网 时间:2024/06/06 16:27
//The Bind Pose Matrices allow a raw vertex of the mesh (in local coordinates) to be transformed into world-space
// and then to each bone's local coordinate space, after which each bone's animation can be applied to the vertex in question
// (under the influence of the weighting value). The mesh's bind pose takes the vertex from local space to world-space,
// and then each bone's inverse bind pose takes the mesh vertex from world-space to the local space of that bone.
// Once in the bone's local space, the bone's current animated transformation matrix is used to transform (deform)
// the vertex's location. After all the bone influences have been taken into account, the vertex ends up in world-space
// in its final deformed location. In other words, these bind pose matrices relate the location of a vertex in its local mesh space
// to the same location of the vertex relative to each bones' local coordinate systems.
// The mesh's Bind Pose Matrix takes its vertices into world-space, to the location at the time of binding,
// and each bones' Bind Pose Matrix takes the bones from local space to world-space at the time of binding.
function Start ()
{
gameObject.AddComponent(SkinnedMeshRenderer);
var renderer : SkinnedMeshRenderer = GetComponent(SkinnedMeshRenderer);
// Build basic mesh
var mesh : Mesh = new Mesh ();
mesh.vertices = [ Vector3(-1, 0, 0),
Vector3(1, 0, 0),
Vector3(-1, 5, 0),
Vector3(1, 5, 0)
];
mesh.uv = [ Vector2(0, 0),
Vector2(1, 0),
Vector2(0, 1),
Vector2(1, 1)
];
mesh.triangles = [ 0, 1, 2,
1, 3, 2,
2, 1, 0,
2, 3, 1
];
mesh.RecalculateNormals();
// Assign mesh to mesh filter renderer
renderer.material = new Material (Shader.Find(" Diffuse"));
// BoneWeight[4] : 4 = vertices 0 to 3
// weights[0] : first (0) vertice
// boneIndex0 : 0 = first bone
// weight0 = 1 : 1 = how much influence this bone has on the vertice
var weights = new BoneWeight[4];
weights[0].boneIndex0 = 0;
weights[0].weight0 = 1;
weights[1].boneIndex0 = 0;
weights[1].weight0 = 1;
weights[2].boneIndex0 = 0;
weights[2].weight0 = 1;
weights[3].boneIndex0 = 0;
weights[3].weight0 = 1;
mesh.boneWeights = weights;
// Create 1 Bone Transform and 1 Bind pose
var bones : Transform[] = new Transform[1];
var bindPoses : Matrix4x4[] = new Matrix4x4[1];
// Create a new gameObject
bones[0] = new GameObject ("Lower").transform;
// Make this gameObject's transform the parent of the bone
bones[0].parent = transform;
// Set the position/rotation of the bone
bones[0].localRotation = Quaternion.identity;
bones[0].localPosition = Vector3.zero;
// bones[0] is a Transform mapped to world space. We map it to the local space of its parent,
// which is the transform "bones[0].worldToLocalMatrix" and afterwards
// we map it again in world space, keeping the relation child - parent with "* transform.localToWorldMatrix;",
// thus allowing us 1. to move/rotate/scale it freely in space but also
// 2. make all move/rotate/scaling operations on its parent affect it too
bindPoses[0] = bones[0].worldToLocalMatrix * transform.localToWorldMatrix;
// Apply bindPoses to the mesh
mesh.bindposes = bindPoses;
// Assign bones and bind poses to the SkinnedMeshRenderer
renderer.bones = bones;
renderer.sharedMesh = mesh;
}
// and then to each bone's local coordinate space, after which each bone's animation can be applied to the vertex in question
// (under the influence of the weighting value). The mesh's bind pose takes the vertex from local space to world-space,
// and then each bone's inverse bind pose takes the mesh vertex from world-space to the local space of that bone.
// Once in the bone's local space, the bone's current animated transformation matrix is used to transform (deform)
// the vertex's location. After all the bone influences have been taken into account, the vertex ends up in world-space
// in its final deformed location. In other words, these bind pose matrices relate the location of a vertex in its local mesh space
// to the same location of the vertex relative to each bones' local coordinate systems.
// The mesh's Bind Pose Matrix takes its vertices into world-space, to the location at the time of binding,
// and each bones' Bind Pose Matrix takes the bones from local space to world-space at the time of binding.
function Start ()
{
gameObject.AddComponent(SkinnedMeshRenderer);
var renderer : SkinnedMeshRenderer = GetComponent(SkinnedMeshRenderer);
// Build basic mesh
var mesh : Mesh = new Mesh ();
mesh.vertices = [ Vector3(-1, 0, 0),
Vector3(1, 0, 0),
Vector3(-1, 5, 0),
Vector3(1, 5, 0)
];
mesh.uv = [ Vector2(0, 0),
Vector2(1, 0),
Vector2(0, 1),
Vector2(1, 1)
];
mesh.triangles = [ 0, 1, 2,
1, 3, 2,
2, 1, 0,
2, 3, 1
];
mesh.RecalculateNormals();
// Assign mesh to mesh filter renderer
renderer.material = new Material (Shader.Find(" Diffuse"));
// BoneWeight[4] : 4 = vertices 0 to 3
// weights[0] : first (0) vertice
// boneIndex0 : 0 = first bone
// weight0 = 1 : 1 = how much influence this bone has on the vertice
var weights = new BoneWeight[4];
weights[0].boneIndex0 = 0;
weights[0].weight0 = 1;
weights[1].boneIndex0 = 0;
weights[1].weight0 = 1;
weights[2].boneIndex0 = 0;
weights[2].weight0 = 1;
weights[3].boneIndex0 = 0;
weights[3].weight0 = 1;
mesh.boneWeights = weights;
// Create 1 Bone Transform and 1 Bind pose
var bones : Transform[] = new Transform[1];
var bindPoses : Matrix4x4[] = new Matrix4x4[1];
// Create a new gameObject
bones[0] = new GameObject ("Lower").transform;
// Make this gameObject's transform the parent of the bone
bones[0].parent = transform;
// Set the position/rotation of the bone
bones[0].localRotation = Quaternion.identity;
bones[0].localPosition = Vector3.zero;
// bones[0] is a Transform mapped to world space. We map it to the local space of its parent,
// which is the transform "bones[0].worldToLocalMatrix" and afterwards
// we map it again in world space, keeping the relation child - parent with "* transform.localToWorldMatrix;",
// thus allowing us 1. to move/rotate/scale it freely in space but also
// 2. make all move/rotate/scaling operations on its parent affect it too
bindPoses[0] = bones[0].worldToLocalMatrix * transform.localToWorldMatrix;
// Apply bindPoses to the mesh
mesh.bindposes = bindPoses;
// Assign bones and bind poses to the SkinnedMeshRenderer
renderer.bones = bones;
renderer.sharedMesh = mesh;
}
0 0
- Unity3D Mesh.bindposes
- 【Unity3D】Mesh
- unity3d 更换装备mesh
- 【边玩边学Unity3d】Mesh属性
- 【边玩边学Unity3d】Mesh属性
- Unity3D-Mesh创建
- 【边玩边学Unity3d】Mesh属性
- Unity3D中的Mesh
- UNITY3D 自定义Mesh
- Unity3D 动态创建Mesh
- unity3d Mesh合并
- Unity3d生成Mesh
- Unity3d Nav Mesh 自带寻路
- Unity3D开发之创建mesh
- Unity3d mesh Filter和mesh Render双生双克
- Unity3D的Mesh与MeshFilter的使用
- Unity3d 利用Mesh绘制几何图形实现
- unity3D研究之Skinned Mesh原理解析
- 【IOS】仿QQ侧滑菜单
- Intel 8086处理器
- 【Windows 10 IoT - 3】Windows 10 RTM安装及新特性(树莓派 Pi2)
- 关于ExpandableListView用法的一个简单小例子
- Java中调用python的几种方式
- Unity3D Mesh.bindposes
- Index For TechShare
- angular.js笔记 ---关于Tabs切换
- ViewPager
- 【flash】pv3d制作3d模型查看器
- DTD语法详解
- C++中类定义的细节
- Android OpenGL ES 2.0之开发流程
- Linux新手安装完全教程