MaxstARSDK  3.5.0
AbstractMarkerTrackableBehaviour.cs
1 /*==============================================================================
2 Copyright 2017 Maxst, Inc. All Rights Reserved.
3 ==============================================================================*/
4 
5 using UnityEngine;
6 using System.IO;
7 using JsonFx.Json;
8 using System.Collections;
9 using System.Collections.Generic;
10 using System.Collections.Specialized;
11 using System.Text;
12 using UnityEngine.Rendering;
13 
14 namespace maxstAR
15 {
20  {
21  void Start()
22  {
23  Renderer myRenderer = GetComponent<Renderer>();
24  myRenderer.enabled = false;
25  Destroy(myRenderer);
26  }
27 
31  public readonly string[] TrackableList = new string[10]
32  {
33  "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
34  };
35 
40  protected override void OnTrackerDataFileChanged(string trackerFileName)
41  {
42  Debug.Log("OnTrackerDataFileChanged : " + trackerFileName);
43  }
44 
45  private void SetTargetTexture(string textureName)
46  {
47  if (File.Exists(textureName))
48  {
49  StartCoroutine(MaxstUtil.loadImageFromFileWithSizeAndTexture(Application.streamingAssetsPath + "/../../" + textureName, (width, height, texture) => {
50  Texture2D localTexture = texture;
51  if (localTexture)
52  {
53 
54  MeshFilter imagePlaneMeshFilter = gameObject.GetComponent<MeshFilter>();
55  if (imagePlaneMeshFilter.sharedMesh == null)
56  {
57  imagePlaneMeshFilter.sharedMesh = new Mesh();
58  imagePlaneMeshFilter.sharedMesh.name = "ImagePlane";
59  }
60 
61  float localWidth = (float)width * 0.5f;
62  float localHeight = (float)height * 0.5f;
63  imagePlaneMeshFilter.sharedMesh.vertices = new Vector3[]
64  {
65  new Vector3(-localWidth, -localHeight, 0.0f),
66  new Vector3(-localWidth, localHeight, 0.0f),
67  new Vector3(localWidth, -localHeight, 0.0f),
68  new Vector3(localWidth, localHeight, 0.0f)
69  };
70 
71  imagePlaneMeshFilter.sharedMesh.triangles = new int[] { 0, 1, 2, 2, 1, 3 };
72  imagePlaneMeshFilter.sharedMesh.uv = new Vector2[]
73  {
74  new Vector2(0, 0),
75  new Vector2(0, 1),
76  new Vector2(1, 0),
77  new Vector2(1, 1),
78  };
79 
80  if (gameObject.GetComponent<MeshRenderer>().sharedMaterial == null)
81  {
82  gameObject.GetComponent<MeshRenderer>().sharedMaterial = new Material(Shader.Find("Unlit/Texture"));
83  }
84 
85  gameObject.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_MainTex", texture);
86  }
87  }));
88  }
89  }
90 
91  //public void SetTrackableIndex(int index)
92  //{
93  // trackableIndex = index;
94  // trackableId = TrackableList[trackableIndex];
95 
96  // string textureFileName = MaxstARUtils.MarkerTargetTexturePath + "/" +
97  // "Marker" + trackableId + ".jpg";
98 
99  // SetTargetTexture(textureFileName);
100  //}
101  }
102 }
Serve frame marker tracking. This is not working current version!
readonly string [] TrackableList
Marker name list in temporary
Parent class of all TrackableBehaviour. Save tracking file&#39;s id (uuid), name, path etc...
override void OnTrackerDataFileChanged(string trackerFileName)
Notify tracking file changed and change target image texture