Exemple #1
0
            void Start()
            {
                IntPtr handle = new IntPtr(0);
                //SenselFrame frame = new SenselFrame();
                SenselDeviceList list        = new SenselDeviceList();
                SenselSensorInfo sensor_info = new SenselSensorInfo();

                list.num_devices = 0;
                Sensel.senselGetDeviceList(ref list);
                Debug.Log("Num Devices: " + list.num_devices);
                if (list.num_devices != 0)
                {
                    Sensel.senselOpenDeviceByID(ref handle, list.devices[0].idx);
                }
                if (handle.ToInt64() != 0)
                {
                    Sensel.senselGetSensorInfo(handle, ref sensor_info);
                    Debug.Log("Sensel Device: " + System.Text.Encoding.Default.GetString(list.devices[0].serial_num));
                    Debug.Log("Width: " + sensor_info.width + "mm");
                    Debug.Log("Height: " + sensor_info.height + "mm");
                    Debug.Log("Cols: " + sensor_info.num_cols);
                    Debug.Log("Rows: " + sensor_info.num_rows);

                    Sensel.senselClose(handle);
                }
            }
            void Awake()
            {
                SenselDeviceList list = new SenselDeviceList();

                list.num_devices = 0;
                Sensel.senselGetDeviceList(ref list);
                Debug.Log("Num Devices: " + list.num_devices);
                if (list.num_devices != 0)
                {
                    Sensel.senselOpenDeviceByID(ref _handle, list.devices[0].idx);
                }
                if (_handle != IntPtr.Zero)
                {
                    Sensel.senselGetSensorInfo(_handle, ref _sensor_info);
                    Debug.Log("Sensel Device: " + System.Text.Encoding.Default.GetString(list.devices[0].serial_num));
                    Debug.Log("Width: " + _sensor_info.width + "mm");
                    Debug.Log("Height: " + _sensor_info.height + "mm");
                    Debug.Log("Cols: " + _sensor_info.num_cols);                     // 185
                    Debug.Log("Rows: " + _sensor_info.num_rows);                     // 105
                    Sensel.senselSetFrameContent(_handle, 1);
                    Sensel.senselAllocateFrameData(_handle, _frame);
                    Sensel.senselStartScanning(_handle);

                    _forces = new float[(int)_sensor_info.num_cols * (int)_sensor_info.num_rows];

                    for (int y = 0; y < _sensor_info.num_rows; ++y)
                    {
                        var vZ = ((float)y - (float)_sensor_info.num_rows * 0.5f) * -PosScale;
                        for (int x = 0; x < _sensor_info.num_cols; ++x)
                        {
                            var vX = ((float)x - (float)_sensor_info.num_cols * 0.5f) * PosScale;
                            _tempVertices.Add(new Vector3(vX, 0.0f, vZ));
                            _tempUVs.Add(new Vector2(0.0f, 1.0f));
                        }
                    }

                    Mesh tempMesh = _AddMesh(_tempVertices, _tempUVs);

                    List <int> tempIndices = new List <int>();
                    int        vertexIndex = 0;
                    for (int y = 0; y < _sensor_info.num_rows - 1; ++y)
                    {
                        for (int x = 0; x < _sensor_info.num_cols - 1; ++x, ++vertexIndex)
                        {
                            tempIndices.Add(vertexIndex + 0);
                            tempIndices.Add(vertexIndex + 1);
                            tempIndices.Add(vertexIndex + _sensor_info.num_cols + 1);
                            tempIndices.Add(vertexIndex + _sensor_info.num_cols + 0);
                        }
                    }

                    if (tempMesh != null && tempIndices.Count > 0)
                    {
                        tempMesh.SetIndices(tempIndices.ToArray(), MeshTopology.Quads, 0);
                    }

                    foreach (var mesh in _tempMeshes)
                    {
                        mesh.RecalculateNormals();
                        mesh.RecalculateBounds();
                    }
                }
            }