Синтаксис:
Используется javascript
/// REMEMBER: When importing assets for use with this script, be sure to set the normal angle to 180 degrees.
/// When importing a mesh Unity automatically splits vertices based on normal creases.
/// This script requires that all meshes have the same number of vertices and that
/// those vertices are laid out in exactly the same way. It won't work if Unity autosplits vertices based on normals.
//Custom definitions to store specialized blend shape data for vertices
class BlendShapeVertex {
var originalIndex : int;
var position : Vector3;
var normal : Vector3;
}
class BlendShape {
//var vertices : BlendShapeVertex[];
var vertices = new Array();
}
var attributes : String[]; //Names for the attributes to be morphed
var sourceMesh : Mesh; //The original mesh
var defMesh : Mesh; //The def mesh
var attributeMeshes : Mesh[]; //The destination meshes for each attribute.
var attributeProgress : float[]; //Current weight for each attribute.
private var blendShapes : BlendShape[]; //Array of BlendShape objects. This will be populated in Awake().
private var workingMesh : Mesh; //Stores mesh data for the working copy of the mesh (so the original mesh doesn't get changed).
function Awake () {
//First, make sure all attributes are assigned.
for (i=0; i<attributeMeshes.length; i++) {
if (attributeMeshes[i] == null) {
Debug.Log("Attribute " + i + " has not been assigned.");
return;
}
}
//Populate the working mesh
workingMesh = sourceMesh;
//Check attribute meshes to be sure vertex count is the same.
var vertexCount = sourceMesh.vertexCount;
var defvertexCount = sourceMesh.vertexCount;
if (defMesh.vertexCount != vertexCount) {
Debug.Log("defMesh doesn't have the same number of vertices as the working mesh");
}else{
workingMesh.vertices = defMesh.vertices;
workingMesh.normals = defMesh.normals;
workingMesh.RecalculateBounds();
}
for (i=0; i<attributeMeshes.Length; i++) {
if (attributeMeshes[i].vertexCount != vertexCount) {
Debug.Log("Mesh " + i + " doesn't have the same number of vertices as the first mesh");
return;
}
}
//Build blend shapes
BuildBlendShapes();
}
//This function populates the various arrays that are used by the script later on.
function BuildBlendShapes () {
blendShapes = new BlendShape[attributes.length];
//For each attribute figure out which vertices are affected, then store their info in the blend shape object.
for (var i=0; i < attributes.length; i++) {
//Populate blendShapes array with new blend shapes
blendShapes[i] = new BlendShape();
for (var j=0; j < defMesh.vertexCount; j++) {
//If the vertex is affected, populate a blend shape vertex with that info
if (defMesh.vertices[j] != attributeMeshes[i].vertices[j]) {
//Create a blend shape vertex and populate its data.
var blendShapeVertex = new BlendShapeVertex();
blendShapeVertex.originalIndex = j;
blendShapeVertex.position = attributeMeshes[i].vertices[j] - defMesh.vertices[j];
blendShapeVertex.normal = attributeMeshes[i].normals[j] - defMesh.normals[j];
//Add new blend shape vertex to blendShape object.
blendShapes[i].vertices.Push(blendShapeVertex);
}
}
//Convert blendShapes.vertices to builtin array
blendShapes[i].vertices = blendShapes[i].vertices.ToBuiltin(BlendShapeVertex);
}
}
//This is the primary function that controls morphs. It is called from the GUI script every time one of the sliders is updated.
function SetMorph () {
//Set up working data to store mesh offset information.
var morphedVertices : Vector3[] = defMesh.vertices;
var morphedNormals : Vector3[] = defMesh.normals;
//For each attribute...
for (var j=0; j<attributes.length; j++) {
//If the weight of this attribute isn't 0
if (!Mathf.Approximately(attributeProgress[j], 0)) {
//For each vertex in this attribute's blend shape...
for (var i=0; i<blendShapes[j].vertices.length; i++) {
//...adjust the mesh according to the offset value and weight
morphedVertices[blendShapes[j].vertices[i].originalIndex] += blendShapes[j].vertices[i].position * attributeProgress[j];
//Adjust normals as well
morphedNormals[blendShapes[j].vertices[i].originalIndex] += blendShapes[j].vertices[i].normal * attributeProgress[j];
}
}
}
//Update the actual mesh with new vertex and normal information, then recalculate the mesh bounds.
workingMesh.vertices = morphedVertices;
workingMesh.normals = morphedNormals;
workingMesh.RecalculateBounds();
}
//Require that we have a mesh filter component and a mesh renderer component when assigning this script to an object.
//@script RequireComponent (MeshFilter)
//@script RequireComponent (MeshRenderer)
/// When importing a mesh Unity automatically splits vertices based on normal creases.
/// This script requires that all meshes have the same number of vertices and that
/// those vertices are laid out in exactly the same way. It won't work if Unity autosplits vertices based on normals.
//Custom definitions to store specialized blend shape data for vertices
class BlendShapeVertex {
var originalIndex : int;
var position : Vector3;
var normal : Vector3;
}
class BlendShape {
//var vertices : BlendShapeVertex[];
var vertices = new Array();
}
var attributes : String[]; //Names for the attributes to be morphed
var sourceMesh : Mesh; //The original mesh
var defMesh : Mesh; //The def mesh
var attributeMeshes : Mesh[]; //The destination meshes for each attribute.
var attributeProgress : float[]; //Current weight for each attribute.
private var blendShapes : BlendShape[]; //Array of BlendShape objects. This will be populated in Awake().
private var workingMesh : Mesh; //Stores mesh data for the working copy of the mesh (so the original mesh doesn't get changed).
function Awake () {
//First, make sure all attributes are assigned.
for (i=0; i<attributeMeshes.length; i++) {
if (attributeMeshes[i] == null) {
Debug.Log("Attribute " + i + " has not been assigned.");
return;
}
}
//Populate the working mesh
workingMesh = sourceMesh;
//Check attribute meshes to be sure vertex count is the same.
var vertexCount = sourceMesh.vertexCount;
var defvertexCount = sourceMesh.vertexCount;
if (defMesh.vertexCount != vertexCount) {
Debug.Log("defMesh doesn't have the same number of vertices as the working mesh");
}else{
workingMesh.vertices = defMesh.vertices;
workingMesh.normals = defMesh.normals;
workingMesh.RecalculateBounds();
}
for (i=0; i<attributeMeshes.Length; i++) {
if (attributeMeshes[i].vertexCount != vertexCount) {
Debug.Log("Mesh " + i + " doesn't have the same number of vertices as the first mesh");
return;
}
}
//Build blend shapes
BuildBlendShapes();
}
//This function populates the various arrays that are used by the script later on.
function BuildBlendShapes () {
blendShapes = new BlendShape[attributes.length];
//For each attribute figure out which vertices are affected, then store their info in the blend shape object.
for (var i=0; i < attributes.length; i++) {
//Populate blendShapes array with new blend shapes
blendShapes[i] = new BlendShape();
for (var j=0; j < defMesh.vertexCount; j++) {
//If the vertex is affected, populate a blend shape vertex with that info
if (defMesh.vertices[j] != attributeMeshes[i].vertices[j]) {
//Create a blend shape vertex and populate its data.
var blendShapeVertex = new BlendShapeVertex();
blendShapeVertex.originalIndex = j;
blendShapeVertex.position = attributeMeshes[i].vertices[j] - defMesh.vertices[j];
blendShapeVertex.normal = attributeMeshes[i].normals[j] - defMesh.normals[j];
//Add new blend shape vertex to blendShape object.
blendShapes[i].vertices.Push(blendShapeVertex);
}
}
//Convert blendShapes.vertices to builtin array
blendShapes[i].vertices = blendShapes[i].vertices.ToBuiltin(BlendShapeVertex);
}
}
//This is the primary function that controls morphs. It is called from the GUI script every time one of the sliders is updated.
function SetMorph () {
//Set up working data to store mesh offset information.
var morphedVertices : Vector3[] = defMesh.vertices;
var morphedNormals : Vector3[] = defMesh.normals;
//For each attribute...
for (var j=0; j<attributes.length; j++) {
//If the weight of this attribute isn't 0
if (!Mathf.Approximately(attributeProgress[j], 0)) {
//For each vertex in this attribute's blend shape...
for (var i=0; i<blendShapes[j].vertices.length; i++) {
//...adjust the mesh according to the offset value and weight
morphedVertices[blendShapes[j].vertices[i].originalIndex] += blendShapes[j].vertices[i].position * attributeProgress[j];
//Adjust normals as well
morphedNormals[blendShapes[j].vertices[i].originalIndex] += blendShapes[j].vertices[i].normal * attributeProgress[j];
}
}
}
//Update the actual mesh with new vertex and normal information, then recalculate the mesh bounds.
workingMesh.vertices = morphedVertices;
workingMesh.normals = morphedNormals;
workingMesh.RecalculateBounds();
}
//Require that we have a mesh filter component and a mesh renderer component when assigning this script to an object.
//@script RequireComponent (MeshFilter)
//@script RequireComponent (MeshRenderer)
вот начал писать но так и не довел до конца и походу не правильно.... прошу поправить
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class BlendShapeVertex {
public int originalIndex;
public Vector3 position;
public Vector3 normal;
}
public class BlendShape {
//var vertices : BlendShapeVertex[];
public ArrayList vertices ;
}
public class BlendMorph : MonoBehaviour {
public string[] attributes; //Names for the attributes to be morphed
public Mesh sourceMesh; //The original mesh
public Mesh defMesh; //The def mesh
public Mesh[] attributeMeshes; //The destination meshes for each attribute.
public float[] attributeProgress; //Current weight for each attribute.
private BlendShape[] blendShapes; //Array of BlendShape objects. This will be populated in Awake().
private Mesh workingMesh; //Stores mesh data
void Awake () {
//First, make sure all attributes are assigned.
for (int i=0; i<attributeMeshes.Length; i++) {
if (attributeMeshes[i] == null) {
Debug.Log("Attribute " + i + " has not been assigned.");
return;
}
}
//Populate the working mesh
workingMesh = sourceMesh;
//Check attribute meshes to be sure vertex count is the same.
int vertexCount = sourceMesh.vertexCount;
int defvertexCount = sourceMesh.vertexCount;
if (defMesh.vertexCount != vertexCount) {
Debug.Log("defMesh doesn't have the same number of vertices as the working mesh");
}else{
workingMesh.vertices = defMesh.vertices;
workingMesh.normals = defMesh.normals;
workingMesh.RecalculateBounds();
}
for (int i=0; i<attributeMeshes.Length; i++) {
if (attributeMeshes[i].vertexCount != vertexCount) {
Debug.Log("Mesh " + i + " doesn't have the same number of vertices as the first mesh");
return;
}
}
//Build blend shapes
BuildBlendShapes();
}
void BuildBlendShapes () {
blendShapes = new BlendShape[attributes.Length];
//For each attribute figure out which vertices are affected, then store their info in the blend shape object.
for (int i=0; i < attributes.Length; i++) {
//Populate blendShapes array with new blend shapes
blendShapes[i] = new BlendShape();
for (int j=0; j < defMesh.vertexCount; j++) {
//If the vertex is affected, populate a blend shape vertex with that info
if (defMesh.vertices[j] != attributeMeshes[i].vertices[j]) {
//Create a blend shape vertex and populate its data.
BlendShapeVertex blendShapeVertex = new BlendShapeVertex();
blendShapeVertex.originalIndex = j;
blendShapeVertex.position = attributeMeshes[i].vertices[j] - defMesh.vertices[j];
blendShapeVertex.normal = attributeMeshes[i].normals[j] - defMesh.normals[j];
//Add new blend shape vertex to blendShape object.
blendShapes[i].vertices.Add(blendShapeVertex);
}
}
}
}
//This is the primary function that controls morphs. It is called from the GUI script every time one of the sliders is updated.
void SetMorph() {
//Set up working data to store mesh offset information.
Vector3[] morphedVertices = defMesh.vertices;
Vector3[] morphedNormals = defMesh.normals;
//For each attribute...
for (int j=0; j<attributes.Length; j++) {
//If the weight of this attribute isn't 0
if (!Mathf.Approximately(attributeProgress[j], 0)) {
//For each vertex in this attribute's blend shape...
for (int i=0; i<blendShapes[j].vertices.Count; i++) {
//...adjust the mesh according to the offset value and weight
morphedVertices[blendShapes[j].vertices[i].originalIndex] += blendShapes[j].vertices[i].position * attributeProgress[j];
//Adjust normals as well
morphedNormals[blendShapes[j].vertices[i].originalIndex] += blendShapes[j].vertices[i].normal * attributeProgress[j];
}
}
}
//Update the actual mesh with new vertex and normal information, then recalculate the mesh bounds.
workingMesh.vertices = morphedVertices;
workingMesh.normals = morphedNormals;
workingMesh.RecalculateBounds();
}
}
using System.Collections;
using System.Collections.Generic;
public class BlendShapeVertex {
public int originalIndex;
public Vector3 position;
public Vector3 normal;
}
public class BlendShape {
//var vertices : BlendShapeVertex[];
public ArrayList vertices ;
}
public class BlendMorph : MonoBehaviour {
public string[] attributes; //Names for the attributes to be morphed
public Mesh sourceMesh; //The original mesh
public Mesh defMesh; //The def mesh
public Mesh[] attributeMeshes; //The destination meshes for each attribute.
public float[] attributeProgress; //Current weight for each attribute.
private BlendShape[] blendShapes; //Array of BlendShape objects. This will be populated in Awake().
private Mesh workingMesh; //Stores mesh data
void Awake () {
//First, make sure all attributes are assigned.
for (int i=0; i<attributeMeshes.Length; i++) {
if (attributeMeshes[i] == null) {
Debug.Log("Attribute " + i + " has not been assigned.");
return;
}
}
//Populate the working mesh
workingMesh = sourceMesh;
//Check attribute meshes to be sure vertex count is the same.
int vertexCount = sourceMesh.vertexCount;
int defvertexCount = sourceMesh.vertexCount;
if (defMesh.vertexCount != vertexCount) {
Debug.Log("defMesh doesn't have the same number of vertices as the working mesh");
}else{
workingMesh.vertices = defMesh.vertices;
workingMesh.normals = defMesh.normals;
workingMesh.RecalculateBounds();
}
for (int i=0; i<attributeMeshes.Length; i++) {
if (attributeMeshes[i].vertexCount != vertexCount) {
Debug.Log("Mesh " + i + " doesn't have the same number of vertices as the first mesh");
return;
}
}
//Build blend shapes
BuildBlendShapes();
}
void BuildBlendShapes () {
blendShapes = new BlendShape[attributes.Length];
//For each attribute figure out which vertices are affected, then store their info in the blend shape object.
for (int i=0; i < attributes.Length; i++) {
//Populate blendShapes array with new blend shapes
blendShapes[i] = new BlendShape();
for (int j=0; j < defMesh.vertexCount; j++) {
//If the vertex is affected, populate a blend shape vertex with that info
if (defMesh.vertices[j] != attributeMeshes[i].vertices[j]) {
//Create a blend shape vertex and populate its data.
BlendShapeVertex blendShapeVertex = new BlendShapeVertex();
blendShapeVertex.originalIndex = j;
blendShapeVertex.position = attributeMeshes[i].vertices[j] - defMesh.vertices[j];
blendShapeVertex.normal = attributeMeshes[i].normals[j] - defMesh.normals[j];
//Add new blend shape vertex to blendShape object.
blendShapes[i].vertices.Add(blendShapeVertex);
}
}
}
}
//This is the primary function that controls morphs. It is called from the GUI script every time one of the sliders is updated.
void SetMorph() {
//Set up working data to store mesh offset information.
Vector3[] morphedVertices = defMesh.vertices;
Vector3[] morphedNormals = defMesh.normals;
//For each attribute...
for (int j=0; j<attributes.Length; j++) {
//If the weight of this attribute isn't 0
if (!Mathf.Approximately(attributeProgress[j], 0)) {
//For each vertex in this attribute's blend shape...
for (int i=0; i<blendShapes[j].vertices.Count; i++) {
//...adjust the mesh according to the offset value and weight
morphedVertices[blendShapes[j].vertices[i].originalIndex] += blendShapes[j].vertices[i].position * attributeProgress[j];
//Adjust normals as well
morphedNormals[blendShapes[j].vertices[i].originalIndex] += blendShapes[j].vertices[i].normal * attributeProgress[j];
}
}
}
//Update the actual mesh with new vertex and normal information, then recalculate the mesh bounds.
workingMesh.vertices = morphedVertices;
workingMesh.normals = morphedNormals;
workingMesh.RecalculateBounds();
}
}
прошу без эмоций, экспериментировал 2 дня но без результатно...
ещо вопрос как подключится через С к яве, нашел на форуме как подключится явой в шарп а наоборот не получается...