// Use this for initialization void Start() { RegisterLogCallback(log); NativePlugin.start_camera(); NativePlugin.start_algorithm(); }
void Start() { NativePlugin.add_marker(id, length); MeshRenderer meshRenderer = gameObject.GetComponent <MeshRenderer>(); meshRenderer.enabled = false; }
public void DictionaryChanged() { if (id > NativePlugin.get_dictionary_words()) { File.Delete(GetImagePath(id)); File.Delete(GetImagePath(id) + ".meta"); id = 0; } RefreshTexture(); }
public static void RegisterLogCallback(NativePlugin.LogCallback lcb) { if (lcb != null) { logCallback = lcb; logCallbackGCH = GCHandle.Alloc(logCallback); } NativePlugin.register_logger(logCallback); if (lcb == null) { logCallback = null; logCallbackGCH.Free(); } }
void LateUpdate() { transform.localScale = new Vector3(length, length, length); bool tracked = NativePlugin.get_marker_pose(id, pose); if (tracked) { Matrix4x4 matrixRaw = MatrixFromFloatArray(pose); transformationMatrix = LHMatrixFromRHMatrix(matrixRaw); transformationMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.AngleAxis(90, Vector3.right), Vector3.one) * transformationMatrix; transform.position = PositionFromMatrix(transformationMatrix); transform.rotation = QuaternionFromMatrix(transformationMatrix); } }
public void setDict(DICT _dict) { if (_dict == dict) { return; } dict = _dict; NativePlugin.set_dictionary((int)dict); ARMarker[] markers = GameObject.FindObjectsOfType <ARMarker>(); foreach (ARMarker marker in markers) { marker.DictionaryChanged(); } }
// Update is called once per frame void Update() { if (screenWidth != Screen.width || screenHeight != Screen.height) { screenWidth = Screen.width; screenHeight = Screen.height; float[] projection = new float[16]; NativePlugin.get_projection(projection, 640, 480, 0.1f, 500); Camera camera = gameObject.GetComponent <Camera>(); camera.projectionMatrix = MatrixFromFloatArray(projection); transform.position = new Vector3(0, 0, 0); transform.rotation = Quaternion.AngleAxis(90, Vector3.right); } }
public void SetID(int newid) { if (markers.Contains(newid)) { return; } if (newid >= 0 && newid <= NativePlugin.get_dictionary_words() && newid != id) { markers.Add(newid); markers.Remove(id); File.Delete(GetImagePath(id)); File.Delete(GetImagePath(id) + ".meta"); id = newid; RefreshTexture(); } }
public bool RefreshTexture() { InitTexture(); if (id < 0 || id >= NativePlugin.get_dictionary_words()) { return(false); } filepath = GetImagePath(id); NativePlugin.get_marker_texture(id, size, filepath); if (!File.Exists(filepath)) { return(false); } FileStream fileStream = new FileStream(filepath, FileMode.Open, FileAccess.Read); fileStream.Seek(0, SeekOrigin.Begin); byte[] bytes = new byte[fileStream.Length]; fileStream.Read(bytes, 0, (int)fileStream.Length); fileStream.Close(); fileStream.Dispose(); if ((object)texture == null) { return(false); } if (!texture.LoadImage(bytes)) { return(false); } return(true); }
// Update is called once per frame void Update() { if (cameraVideoData == null) { int width, height; NativePlugin.get_camera_size(out width, out height); cameraVideoData = new Color32[width * height]; cameraVideoTexture = new Texture2D(width, height, TextureFormat.ARGB32, false); cameraVideoTexture.hideFlags = HideFlags.HideAndDontSave; cameraVideoTexture.filterMode = FilterMode.Bilinear; cameraVideoTexture.wrapMode = TextureWrapMode.Clamp; cameraVideoTexture.anisoLevel = 0; Shader shaderSource = Shader.Find("VideoPlaneNoLight"); cameraVideoMaterial = new Material(shaderSource); cameraVideoMaterial.hideFlags = HideFlags.HideAndDontSave; cameraVideoMaterial.mainTexture = cameraVideoTexture; MeshRenderer meshRenderer = gameObject.GetComponent <MeshRenderer>(); MeshFilter meshFilter = gameObject.GetComponent <MeshFilter>(); meshFilter.mesh = newVideoMesh(false, true); meshRenderer.receiveShadows = false; meshRenderer.material = cameraVideoMaterial; } GCHandle handle = GCHandle.Alloc(cameraVideoData, GCHandleType.Pinned); IntPtr address = handle.AddrOfPinnedObject(); NativePlugin.update_camera_frame(address); handle.Free(); cameraVideoTexture.SetPixels32(cameraVideoData); cameraVideoTexture.Apply(false); }
public override void OnInspectorGUI() { ARMarker marker = (ARMarker)target; if (marker == null) { return; } string idlabel = String.Format("id [0,{0})", NativePlugin.get_dictionary_words()); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(idlabel); marker.SetID(EditorGUILayout.IntField(marker.id)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("length(m)"); marker.length = EditorGUILayout.FloatField(marker.length); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("use background color"); marker.SetUseBackgroundColor(EditorGUILayout.Toggle(marker.useBackgroundColor)); EditorGUILayout.EndHorizontal(); if (marker.useBackgroundColor) { marker.SetBackgroundColor(EditorGUILayout.ColorField("background color", marker.backgroundColor)); } else { EditorGUILayout.ObjectField("texture", marker.texture, typeof(Texture2D), true); } }