Skip to content

Commit

Permalink
Merge pull request #13 from Guseul/master
Browse files Browse the repository at this point in the history
Update EasyAR, Vuforia Sample
  • Loading branch information
AIRAR-JGS authored Oct 23, 2020
2 parents 8e6bba6 + d9be009 commit 08e28af
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 24 deletions.
57 changes: 46 additions & 11 deletions ColorMapping/Scripts/core/ARFoundationColorMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,58 @@ public class ARFoundationColorMapping : MonoBehaviour
public ARTrackedImageManager imageManager;
#endif

public GameObject arContents;
public GameObject drawObj;
public GameObject arPrefabs;

public int realWidth;
public int realHeight;

private GameObject arContents;
private GameObject drawObj;

private GameObject cube;

#if USE_ARFOUNDATION
void Start()
{
#if USE_ARFOUNDATION
IReferenceImageLibrary imageLibrary = imageManager.referenceLibrary;
float targetWidth = imageLibrary[0].width;
float targetHeight = imageLibrary[0].height;
imageManager.trackedImagesChanged += OnTrackedImagesChanged;
}

cube = CreateCubeForARFoundationTarget(this.gameObject, targetWidth, targetHeight);
#endif
private void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
{
ARTrackedImage trackedImage = null;

for (int i = 0; i < eventArgs.added.Count; i++)
{
trackedImage = eventArgs.added[i];
string imgName = trackedImage.referenceImage.name;

if(imgName == "sw-12")
{
arContents = Instantiate(arPrefabs, trackedImage.transform);
cube = CreateCubeForARFoundationTarget(this.gameObject, trackedImage.size.x, trackedImage.size.y, trackedImage.transform);
}
}

for (int i = 0; i < eventArgs.updated.Count; i++)
{
trackedImage = eventArgs.updated[i];

if (trackedImage.trackingState == TrackingState.Tracking)
{
arContents.SetActive(true);
}
else
{
arContents.SetActive(false);
}
}

for (int i = 0; i < eventArgs.removed.Count; i++)
{
arContents.SetActive(false);
}
}
#endif

public void Play()
{
Expand All @@ -40,6 +74,7 @@ public void Play()

AirarManager.Instance.ProcessColoredMapTexture(screenShotTex, srcValue, realWidth, realHeight, (resultTex) =>
{
drawObj = GameObject.FindGameObjectWithTag("coloring");
drawObj.GetComponent<Renderer>().material.mainTexture = resultTex;
});
}
Expand All @@ -49,12 +84,12 @@ public void Play()
/// </summary>
/// <param name="targetWidth">marker image width</param>
/// <param name="targetHeight">marker image height</param>
public GameObject CreateCubeForARFoundationTarget(GameObject parentObj, float targetWidth, float targetHeight)
public GameObject CreateCubeForARFoundationTarget(GameObject parentObj, float targetWidth, float targetHeight, Transform trans)
{
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.GetComponent<Renderer>().material = AirarManager.Instance.transparentMat;
cube.transform.SetParent(parentObj.transform);
cube.transform.localPosition = Vector3.zero;
cube.transform.SetParent(trans);
cube.transform.localPosition = trans.localPosition;
cube.transform.localScale = new Vector3(targetWidth, 0.001f, targetHeight);

return cube;
Expand Down
3 changes: 2 additions & 1 deletion ColorMapping/Scripts/core/EasyARColorMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class EasyARColorMapping : MonoBehaviour
#endif

public GameObject arContents;
public GameObject drawObj;

public int realWidth;
public int realHeight;

private GameObject drawObj;
private GameObject cube;

void Start()
Expand All @@ -43,6 +43,7 @@ public void Play()

AirarManager.Instance.ProcessColoredMapTexture(screenShotTex, srcValue, realWidth, realHeight, (resultTex) =>
{
drawObj = GameObject.FindGameObjectWithTag("coloring");
drawObj.GetComponent<Renderer>().material.mainTexture = resultTex;
});
}
Expand Down
5 changes: 3 additions & 2 deletions ColorMapping/Scripts/core/MaxstARColorMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class MaxstARColorMapping : MonoBehaviour
#endif

public GameObject arContents;
public GameObject drawObj;

public int realWidth;
public int realHeight;

private GameObject drawObj;
private GameObject cube;

void Start()
Expand All @@ -36,8 +36,9 @@ public void Play()

Texture2D screenShotTex = ScreenShot.GetScreenShot(arContents);

AirarManager.Instance.ProcessColoredMapTexture(screenShotTex, srcValue, realWidth, realHeight, (resultTex) =>
AirarManager.Instance.ProcessColoredMapTexture(screenShotTex, srcValue, realHeight, realWidth, (resultTex) =>
{
drawObj = GameObject.FindGameObjectWithTag("coloring");
drawObj.GetComponent<Renderer>().material.mainTexture = resultTex;
});
}
Expand Down
3 changes: 2 additions & 1 deletion ColorMapping/Scripts/core/VuforiaColorMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class VuforiaColorMapping : MonoBehaviour
#endif

public GameObject arContents;
public GameObject drawObj;

public int realWidth;
public int realHeight;

private GameObject drawObj;
private GameObject cube;

void Start()
Expand All @@ -39,6 +39,7 @@ public void Play()

AirarManager.Instance.ProcessColoredMapTexture(screenShotTex, srcValue, realWidth, realHeight, (resultTex) =>
{
drawObj = GameObject.FindGameObjectWithTag("coloring");
drawObj.GetComponent<Renderer>().material.mainTexture = resultTex;
});
}
Expand Down
Git LFS file not shown
3 changes: 0 additions & 3 deletions Sample/EasyARSample/ColorMappingEasyARSample.unitypackage

This file was deleted.

3 changes: 3 additions & 0 deletions Sample/EasyARSample/ColorMappingSampleWithEasyAR.unitypackage
Git LFS file not shown
3 changes: 0 additions & 3 deletions Sample/MaxstARSample/ColorMappingMaxstARSample.unitypackage

This file was deleted.

Git LFS file not shown
Git LFS file not shown
3 changes: 0 additions & 3 deletions Sample/VuforiaSample/ColorMappingVuforiaSample.unitypackage

This file was deleted.

0 comments on commit 08e28af

Please sign in to comment.