8 using System.Runtime.InteropServices;
11 using System.Collections.Generic;
12 using System.Collections.Specialized;
24 private string textureDir = null;
27 private float targetWidth = 0;
30 private float targetHeight = 0;
37 get {
return targetWidth; }
45 get {
return targetHeight; }
50 Renderer myRenderer = GetComponent<Renderer>();
51 myRenderer.enabled =
false;
62 TrackableName = Path.GetFileNameWithoutExtension(trackerFileName);
63 int startIdx = trackerFileName.LastIndexOf(
"/") + 1;
64 int endIdx = trackerFileName.LastIndexOf(
".");
65 string fileName = trackerFileName.Substring(startIdx, endIdx - startIdx);
67 textureDir = Path.GetFileName(Path.GetDirectoryName(trackerFileName));
69 string textureFileName =
MaxstARUtils.ImageTargetTexturePath +
"/" +
70 textureDir +
"/" + fileName +
"_resized.jpg";
72 if (Application.platform == RuntimePlatform.WindowsEditor ||
73 Application.platform == RuntimePlatform.OSXEditor)
75 Stream fs = File.OpenRead(Application.streamingAssetsPath +
"/" + trackerFileName);
76 if (!fs.CanSeek)
throw new ArgumentException(
"Stream must be seekable");
78 byte[] buf =
new byte[4];
81 ChangeObjectProperty(textureFileName, BitConverter.ToSingle(buf, 0));
86 private void ChangeObjectProperty(
string textureName,
float scale)
88 Debug.Log(
"scale : " + scale);
90 if (File.Exists(textureName))
92 StartCoroutine(
MaxstUtil.loadImageFromFileWithSizeAndTexture(Application.streamingAssetsPath +
"/../../" + textureName, (width, height, texture) => {
93 Texture2D localTexture = texture;
96 MeshFilter imagePlaneMeshFilter = gameObject.GetComponent<MeshFilter>();
97 if (imagePlaneMeshFilter.sharedMesh == null)
99 imagePlaneMeshFilter.sharedMesh = new Mesh();
100 imagePlaneMeshFilter.sharedMesh.name =
"ImagePlane";
104 float imageH = (float)height / (float)width;
106 float vertexWidth = imageW * 0.5f * scale;
107 float vertexHeight = imageH * 0.5f * scale;
108 imagePlaneMeshFilter.sharedMesh.vertices = new Vector3[]
110 new Vector3(-vertexWidth, 0.0f, -vertexHeight),
111 new Vector3(-vertexWidth, 0.0f, vertexHeight),
112 new Vector3(vertexWidth, 0.0f, -vertexHeight),
113 new Vector3(vertexWidth, 0.0f, vertexHeight)
116 targetWidth = imageW * scale;
117 targetHeight = imageH * scale;
119 imagePlaneMeshFilter.sharedMesh.triangles = new int[] { 0, 1, 2, 2, 1, 3 };
120 imagePlaneMeshFilter.sharedMesh.uv = new Vector2[]
128 if (gameObject.GetComponent<MeshRenderer>().sharedMaterial == null)
130 gameObject.GetComponent<MeshRenderer>().sharedMaterial = new Material(Shader.Find(
"Unlit/Texture"));
133 gameObject.GetComponent<MeshRenderer>().sharedMaterial.SetTexture(
"_MainTex", texture);
float TargetWidth
Image target real width
string TrackableName
Tracking file name only without extention.
string TrackableId
Tracking file uuid. This value is addressed in tracking file.
Handle tracking file definition in editor and runtime target image visibility
Parent class of all TrackableBehaviour. Save tracking file's id (uuid), name, path etc...
override void OnTrackerDataFileChanged(string trackerFileName)
Notify tracking file changed and change target image texture and scale, etc.
float TargetHeight
Image target real height