/******************************************************************************************************************************************************************/ public void SetHapticGeometry() { //Get array of all object with tag "Touchable" GameObject[] myObjects = GameObject.FindGameObjectsWithTag("Touchable") as GameObject[]; for (int ObjId = 0; ObjId < myObjects.Length; ObjId++) { /***************************************************************/ //Set the Transformation Matric of the Object /***************************************************************/ //Get the Transformation matrix from object Matrix4x4 m = new Matrix4x4(); //Build a transform Matrix from the translation/rotation and Scale parameters fo the object - Local Matrix //m.SetTRS(myObjects[ObjId].transform.position,myObjects[ObjId].transform.rotation,myObjects[ObjId].transform.localScale); //Build a transform Matrix from the translation/rotation and Scale parameters fo the object - Glabal Matrix m = myObjects[ObjId].transform.localToWorldMatrix; //Convert Matrix4x4 to double16 double[] matrix = ConverterClass.ConvertMatrix4x4ToDouble16(m); //Convert Double16 To IntPtr IntPtr dstDoublePtr = ConverterClass.ConvertDouble16ToIntPtr(matrix); //Convert String to Byte[] (char* in C++) and Byte[] to IntPtr IntPtr dstCharPtr = ConverterClass.ConvertStringToByteToIntPtr(myObjects[ObjId].name); //Send the transformation Matrix of the object PluginImport.SetObjectTransform(ObjId, dstCharPtr, dstDoublePtr); /***************************************************************/ /***************************************************************/ //Set the Mesh of the Object /***************************************************************/ //Get Mesh of Object Mesh mesh = myObjects[ObjId].GetComponent <MeshFilter>().mesh; Vector3[] vertices = mesh.vertices; int[] triangles = mesh.triangles; //Reorganize the Array float[] verticesToSend = ConverterClass.ConvertVector3ArrayToFloatArray(vertices); //Allocate Memory according to needed space for float* (3*4) IntPtr dstVerticesArrayPtr = Marshal.AllocCoTaskMem(vertices.Length * 3 * Marshal.SizeOf(typeof(float))); //Copy to dstPtr Marshal.Copy(verticesToSend, 0, dstVerticesArrayPtr, vertices.Length * 3); //Convert Int[] to IntPtr IntPtr dstTrianglesArrayPtr = ConverterClass.ConvertIntArrayToIntPtr(triangles); //Send the Raw Mesh of the object - transformation are not applied on the Mesh vertices PluginImport.SetObjectMesh(ObjId, dstVerticesArrayPtr, dstTrianglesArrayPtr, vertices.Length, triangles.Length); /***************************************************************/ /***************************************************************/ //Get the haptic parameter configuration /***************************************************************/ ReadHapticProperties(ObjId, myObjects[ObjId]); /***************************************************************/ } }