скрипт морфа перевести с явы на С

Программирование на Юнити.

скрипт морфа перевести с явы на С

Сообщение KuzmaProduction 04 окт 2010, 12:09

нуно перепесать скрипт с явки на С, помогите бо завис))
Синтаксис:
Используется 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)



вот начал писать но так и не довел до конца и походу не правильно.... прошу поправить

Синтаксис:
Используется 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();
}


}
 



прошу без эмоций, экспериментировал 2 дня но без результатно...



ещо вопрос как подключится через С к яве, нашел на форуме как подключится явой в шарп а наоборот не получается...
Mayaвец.. 3д - 2д аниматор...
Аватара пользователя
KuzmaProduction
UNIт
 
Сообщения: 62
Зарегистрирован: 02 сен 2010, 11:54
  • ICQ

Re: скрипт морфа перевести с явы на С

Сообщение DbIMok 04 окт 2010, 12:35

а в чем проблема? вроде код похож на правильный.
порядок компиляции скриптов http://unity3d.com/support/documentatio ... ced29.html
отсюда вытекают и проблемы видимости.
правильный вопрос - половина ответа. учитесь формулировать вопросы понятно.
Новости > _Telegram чат @unity3d_ru (11.6k/4.8k online) > _Telegram канал @unity_news (4.7k подписчиков) > Телеграм тема > "Спасибо"
Аватара пользователя
DbIMok
Адепт
 
Сообщения: 6372
Зарегистрирован: 31 июл 2009, 14:05

Re: скрипт морфа перевести с явы на С

Сообщение KuzmaProduction 04 окт 2010, 13:40

проблема в функции SetMorph()
и ещо вопрос в ява скрипте идет преобразование массива в буилдин массив, я не понял как нащет этого в (c#) и вобще нужно ли?
Mayaвец.. 3д - 2д аниматор...
Аватара пользователя
KuzmaProduction
UNIт
 
Сообщения: 62
Зарегистрирован: 02 сен 2010, 11:54
  • ICQ

Re: скрипт морфа перевести с явы на С

Сообщение Zaicheg 04 окт 2010, 13:47

Как минимум, от ошибок компиляции вас это избавит. Работу скрипта в рантайме потестировать не могу.
Код: Выделить всё
public List<BlendShapeVertex> vertices = new List<BlendShapeVertex>();

Для этого надо было пройти на строку по ошибке из консоли и проследить, значения каких типов присваиваются объявляемой там переменной в ходе работы программы (blendShapes[i].vertices.Add(blendShapeVertex);).

P.S.: речь идёт, конечно же, о замене вашего объявления ArrayList vertices в классе BlendShape на это.
Дьяченко Роман
e-mail: _zaicheg.reg@gmail.com
skype: zaicheg12
vkontakte: _vk.com/zaichegq
Работа: _wie3.com _www.sanviz.com
Аватара пользователя
Zaicheg
Адепт
 
Сообщения: 3024
Зарегистрирован: 19 июн 2009, 15:12
Откуда: Череповец

Re: скрипт морфа перевести с явы на С

Сообщение KuzmaProduction 04 окт 2010, 16:04

спс буду пробывать дома...
Mayaвец.. 3д - 2д аниматор...
Аватара пользователя
KuzmaProduction
UNIт
 
Сообщения: 62
Зарегистрирован: 02 сен 2010, 11:54
  • ICQ


Вернуться в Скрипты

Кто сейчас на конференции

Сейчас этот форум просматривают: Yandex [Bot] и гости: 8