Slide 1

Slide 1 text

Tutorial: Creating Stamp-AR with OpenCV

Slide 2

Slide 2 text

Download and Installation ①Sample Data for the Tutorial http://arfukuoka.lolipop.jp/stampar/Sample.zip ②ARCoreSDK(v1.8.0) https://github.com/google-ar/arcore-unity-sdk/releases/tag/v1.8.0 ③Unity2017.4.15f1 or later https://unity3d.com/jp/unity/qa/lts-releases?version=2017.4 ④Android SDK https://developer.android.com/studio ※Please finish setting up Android build on Unity before hand.

Slide 3

Slide 3 text

Goal of The Tutorial https://youtu.be/a8o1ieL01_w

Slide 4

Slide 4 text

ARCore New marker-less AR platform which can available for Android devices. 【Features】 (1) Motion Tracking based on SLAM (2) Environmental Understanding (3) Light Estimation (4) Augmented Image (5) Cloud Anchor (6) Augmented Faces

Slide 5

Slide 5 text

OpenCV Plus Unity  Unity asset of image processing based on OpenCV3.  OpenCVSharp was adapted to Unity environment.  Available on Windows/Mac/Android/iOS.

Slide 6

Slide 6 text

Procedure Binarization capture Add Alpha Channel Coloring 2D→3D GOAL!

Slide 7

Slide 7 text

Getting Started with Unity

Slide 8

Slide 8 text

Creation of a Unity Project New

Slide 9

Slide 9 text

Creation of a Unity Project Create Project Name of a Project Save Directory

Slide 10

Slide 10 text

Addin a 3D Object ①Right Click ②3D Object ③Quad

Slide 11

Slide 11 text

How to Play Click Play Button Click Play Button to Stop View of the Camera

Slide 12

Slide 12 text

Modification of View Point of Scene [←] [→] Move to Right/Left [↑][↓] Zoom In/Out [Alt]+Drag Rotation +Drag Move to ↑↓←→

Slide 13

Slide 13 text

Modification of Game Object Click to Select Translation Rotation Scaling

Slide 14

Slide 14 text

Numerical Modification of Game Object  Detailed information is shown in the Inspector Tab  For instance, you can translate object by changing Position ②Change Position parameter to 0 0 0 ① Quad

Slide 15

Slide 15 text

Applying a Texture to Material Change the appearance by applying texture image to 3D model

Slide 16

Slide 16 text

Creation of a Material File ①Assets ②空白を右クリック

Slide 17

Slide 17 text

Creation of a Material File ①Create ②Material

Slide 18

Slide 18 text

Creation of a Material File ①Click Quad ②Open Materials ※Click▼button

Slide 19

Slide 19 text

Applying a Texture Image ①Find NewMaterial ※Do NOT click! ②Drag & Drop into Element0 of Materials

Slide 20

Slide 20 text

Applying a Texture Image ①Click Quad ②Open NewMaterial ※▼をクリック

Slide 21

Slide 21 text

Applying a Texture Image Open Shader List

Slide 22

Slide 22 text

Applying a Texture Image ①Unlit ②Transparent

Slide 23

Slide 23 text

Applying a Texture Image Texture image will be assigned from here

Slide 24

Slide 24 text

Importing Texture Image ①Assets ②ImportNewAsset...

Slide 25

Slide 25 text

Importing Texture Image ①Sample Folder ②Select logo.png ③Import

Slide 26

Slide 26 text

Assigning Texture to Material ①Click Quad

Slide 27

Slide 27 text

Assigning Texture to Material ①Find logo file ②Drag&Drop into texture area

Slide 28

Slide 28 text

Assigning Texture to Material

Slide 29

Slide 29 text

Check Point & Idea for StampAR 【Check Point】 Appearance can be set just by assigning texture file if a material to use texture was applied to3D model. 【Idea】  Make a image which has alpha channel.  Change color of opaque pixels by using script.  Generate plane which is attached this image.

Slide 30

Slide 30 text

Save the Scene ①File ②Save Scene as...

Slide 31

Slide 31 text

Save the Secne ①Write the name of this scene ②Save Please save the scene frequently with ctrl+s after this procedure

Slide 32

Slide 32 text

Installation of ARCore SDK ①Assets ②Import Package ③Open SDK from Custom Package arcore-unity-sdk-v1.8.0.unitypackage

Slide 33

Slide 33 text

Installation of ARCore SDK Import

Slide 34

Slide 34 text

Installation of ARCore SDK GoogleARCore will appear

Slide 35

Slide 35 text

Setting Up Camera for AR Delete Main Camera

Slide 36

Slide 36 text

Setting Up Camera for AR Assets→GoogleARCore→Prefabs

Slide 37

Slide 37 text

Setting Up Camera for AR ①ARCore Device ②Drag & Drop into Hierarchy

Slide 38

Slide 38 text

Setting Up Camera for AR ①ARCore Device ②Double Click DefaultSessionConfig

Slide 39

Slide 39 text

Setting Up Camera for AR Switch Camera Focus Mode to Auto

Slide 40

Slide 40 text

Modification of Position & Scale of a CG Click Quad

Slide 41

Slide 41 text

Modification of Position & Scale of a CG Position: 0, 0, 0.5 Scale: All 0.1

Slide 42

Slide 42 text

Modification of Position & Scale of a CG Double Click Quad Since Quad object is very smaller than default size, make the view point close to the object.

Slide 43

Slide 43 text

Saving the Scene Ctrl/Command + S

Slide 44

Slide 44 text

Build Setting ①File ②Build Settings...

Slide 45

Slide 45 text

Build Setting ①Android ②Switch Platform

Slide 46

Slide 46 text

Build Setting ①Internal ②Player Settings

Slide 47

Slide 47 text

Build Setting ①Resolution and Presentation ②Select Portrait as Default Orientation

Slide 48

Slide 48 text

Build Setting ①Other Settings ②Turn Off Multithreaded Rendering

Slide 49

Slide 49 text

Build Setting ①Set original PackageName 例)com.fukuoka.test ②Set Minimum API Level as Andrid 7.0

Slide 50

Slide 50 text

Build Setting (for Unity2018) Set Allow unsafe Code Checked

Slide 51

Slide 51 text

Build Setting ①XR Settings ②Setting ARCore Supported Checked

Slide 52

Slide 52 text

Saving the Scene Ctrl/Command+S

Slide 53

Slide 53 text

Installation App Into Smartphone ①File ②Build & Run

Slide 54

Slide 54 text

Installation App Into Smartphone ②Save ①Set a name of installer(.apk)

Slide 55

Slide 55 text

Run 3D object will be fixed the real space.

Slide 56

Slide 56 text

From Next Slide… Preparation for Getting Started with Image Processing

Slide 57

Slide 57 text

Installation of OpenCV Plus Unity ①Window ②Asset Store

Slide 58

Slide 58 text

Installation of OpenCV Plus Unity Search “OpenCV Plus”

Slide 59

Slide 59 text

Installation of OpenCV Plus Unity Click OpenCV Plus Unity

Slide 60

Slide 60 text

Installation of OpenCV Plus Unity Download

Slide 61

Slide 61 text

Installation of OpenCV Plus Unity Import

Slide 62

Slide 62 text

Installation of OpenCV Plus Unity Import

Slide 63

Slide 63 text

Installation of OpenCV Plus Unity OpenCV + Unity will appear

Slide 64

Slide 64 text

Setting Up the View of Unity Editor Game This operation means making your modification of UI layout of application comfortable in Unity Editor.

Slide 65

Slide 65 text

Setting Up the View of Unity Editor ①Click Free Aspect ②Click+ This operation means making your modification of UI layout of application comfortable in Unity Editor.

Slide 66

Slide 66 text

Setting Up the View of Unity Editor ①Put Name ②800 × 1280 It’s not necessary to match actual resolution of your smartphone in this tutorial.

Slide 67

Slide 67 text

Importing Sample UI ②Import Package ①Assets ③Custom Package...

Slide 68

Slide 68 text

Importing Sample UI ②Open ①StampUI.unitypackage

Slide 69

Slide 69 text

Importing Sample UI Import

Slide 70

Slide 70 text

Importing Sample UI Scene

Slide 71

Slide 71 text

Importing Sample UI ①Assets ②Canvas will be added

Slide 72

Slide 72 text

Using Sample UI ①Canvas ②Drag&Drop into Hierarchy

Slide 73

Slide 73 text

Using Sample UI UI will appear in the Scene UI might not be visible the view point which you using know. But it’s not problem! Please see next page.

Slide 74

Slide 74 text

Using Sample UI ①Double Click Canvas ②You can see whole UI

Slide 75

Slide 75 text

Using Sample UI ②Modify view point to make UI to be facing to you ①Click x or z

Slide 76

Slide 76 text

Role of UI Start capture Change color Put stamp into the space Vewer of captured or processed image

Slide 77

Slide 77 text

Applying Alpha Texture to Viewer ①Open Canvas ②Click Assets

Slide 78

Slide 78 text

Applying Alpha Texture to Viewer ①RawImage ②Find Material

Slide 79

Slide 79 text

Applying Alpha Texture to Viewer ①Find NewMaterial ※Do NOT click ②Drag&Drop into Material

Slide 80

Slide 80 text

Applying Alpha Texture to Viewer Viewer became to be able to show alpha channel image

Slide 81

Slide 81 text

Preparation of Writing C# Script Write click on the blank of Hierarchy

Slide 82

Slide 82 text

Preparation of Writing C# Script Create Empty

Slide 83

Slide 83 text

Preparation of Writing C# Script ①Game Object ②Add Component

Slide 84

Slide 84 text

Preparation of Writing C# Script ①New Script ②Name of Script (ex. StampScript) ③Create and Add

Slide 85

Slide 85 text

Preparation of Writing C# Script ①Game Object ②ColoringScript will be added

Slide 86

Slide 86 text

Preparation of Writing C# Script Double Click

Slide 87

Slide 87 text

Importing OpenCV and UnityEngine.UI using UnityEngine; using UnityEngine.UI; using OpenCvSharp; using OpenCvSharp.Demo; public class StampScript : MonoBehaviour { // Start関数は初期化のために一度だけ実行される void Start () { cg = GameObject.Find ("Robot Kyle"); } // Update関数は毎フレーム実行される void Update () { } }

Slide 88

Slide 88 text

canvas Declaration of Variables //Canvas which involves UI parts public GameObject canvas; //Viewer of image. public RawImage preview; //Region of screen shot. UnityEngine.Rect capRect; //Texture of screen shot image. Texture2D capTexture; void Start () { } void Update () { } preview

Slide 89

Slide 89 text

Linking Objects and Variables ①Click GameObject ②Canvas & Preview will be added

Slide 90

Slide 90 text

Linking Objects and Variables Find Canvas Drag & Drop into Canvas of StampScript

Slide 91

Slide 91 text

Linking Objects and Variables See RawImage Drag& Drop into Previewof StampScript

Slide 92

Slide 92 text

Procedure Binarization capture Add Alpha Channel Coloring 2D→3D GOAL!

Slide 93

Slide 93 text

Procedure Binarization Add Alpha Channel Coloring 2D→3D GOAL! capture

Slide 94

Slide 94 text

Preaparation of Screen Capture //Canvas which involves UI parts public GameObject canvas; //Viewer of image. public RawImage preview; //Region of screen shot. UnityEngine.Rect capRect; //Texture of screen shot image. Texture2D capTexture; void Start () { int w = Screen.width; int h = Screen.height; //Definition of capture region as (0,0) to (w,h). capRect = new UnityEngine.Rect(0, 0, w, h); //Creating texture image of the size of capRect. capTexture = new Texture2D(w, h, TextureFormat.RGBA32, false); //Applying capTexture as texture of preview area. preview.material.mainTexture = capTexture; } width height (0,0)

Slide 95

Slide 95 text

Making Function of Image Processing void Start () { /*Code was omitted in the slide.*/ } IEnumerator ImageProcessing() { canvas.SetActive(false);//Making UIs invisible yield return new WaitForEndOfFrame(); capTexture.ReadPixels(capRect, 0, 0);//Starting capture capTexture.Apply();//Apply captured image. canvas.SetActive(true);//Making UIs visible } public void StartCV() { StartCoroutine(ImageProcessing());//Calling coroutine } Write!

Slide 96

Slide 96 text

Calling StartCV() From UI ①Click CaptureBtn ②Find Button ③Click + laying on bottom of OnClick()

Slide 97

Slide 97 text

Calling StartCV() From UI Find GameObject Drag & Drop into the area written None, of OnClick()

Slide 98

Slide 98 text

Calling StartCV() From UI ①Click No Function ②StampScript

Slide 99

Slide 99 text

Calling StartCV() From UI StartCV()

Slide 100

Slide 100 text

Ctrl/Command + S

Slide 101

Slide 101 text

Build & Run!

Slide 102

Slide 102 text

Run Captured image appears Capture

Slide 103

Slide 103 text

Another Way to Test Play

Slide 104

Slide 104 text

Another Way to Test Click Play again to STOP

Slide 105

Slide 105 text

Refactoring(1/2) IEnumerator ImageProcessing() { canvas.SetActive(false); yield return new WaitForEndOfFrame(); capTexture.ReadPixels(capRect, 0, 0); capTexture.Apply(); canvas.SetActive(true); } void CreateImages() { /* Cut & Paste Code of Image Creation */ } Image Creation Make CreateImages function since amount of source code for image creation will be increased later.

Slide 106

Slide 106 text

Refactoring(2/2) IEnumerator ImageProcessing() { canvas.SetActive(false); yield return new WaitForEndOfFrame(); CreateImages(); //画像の生成 canvas.SetActive(true); } void CreateImages() { capTexture.ReadPixels(capRect, 0, 0); capTexture.Apply(); } Do not forget to call CreateImages() from ImageProcessing()

Slide 107

Slide 107 text

Procedure Binarization Add Alpha Channel Coloring 2D→3D GOAL! capture

Slide 108

Slide 108 text

Procedure Add Alpha Channel Coloring 2D→3D GOAL! capture Binarization

Slide 109

Slide 109 text

From now on, we use OpenCV!

Slide 110

Slide 110 text

Binarization of Gray Scale Image 0 255 0 255 Binarization means splitting grayscale(0~255) into 0 or 255 by threshold. It’s very important technique to define pixels which should be processed.

Slide 111

Slide 111 text

Preparation of Using Image with OpenCV UnityEngine.Rect capRect; //Texture to store captured image. Texture2D capTexture; //Mat:Format of image for OpenCV //bgraMat is for color image with alpha channel. //binMat is for binarized image. Mat bgraMat, binMat; void Start () { int w = Screen.width; int h = Screen.height; //Definition of capture region as (0,0) to (w,h). capRect = new UnityEngine.Rect(0, 0, w, h); //Creating texture image of the size of capRect. capTexture = new Texture2D(w, h, TextureFormat.RGBA32, false); //Applying capTexture as texture of preview area. preview.material.mainTexture = capTexture; }

Slide 112

Slide 112 text

Binarization void CreateImage() { capTexture.ReadPixels(capRect, 0, 0); capTexture.Apply(); //Conversion Texure2D to Mat bgraMat = OpenCvSharp.Unity.TextureToMat(capTexture); //Conversion Color Image to Gray Scale Image binMat = bgraMat.CvtColor(ColorConversionCodes.BGRA2GRAY); //Binarization of image with Otsu’s method. binMat = binMat.Threshold(100, 255, ThresholdTypes.Otsu); //Conversion Gray Scale to BGRA to change its color later. bgraMat = binMat.CvtColor(ColorConversionCodes.GRAY2BGRA); } bgraMat binMat(GrayScale) binMat (Binarized) bgraMat (B=G=R)

Slide 113

Slide 113 text

Visualization of a Result of Binarization IEnumerator ImageProcessing() { canvas.SetActive(false); yield return new WaitForEndOfFrame(); CreateImages();//Creating Image SetColor(capTexture);//Setting color to capTexture canvas.SetActive(true); } //Setting color information of bgraMat to texture. void SetColor(Texture2D texture) { OpenCvSharp.Unity.MatToTexture(bgraMat, texture); }

Slide 114

Slide 114 text

Run ①Capture ②Binalized Image

Slide 115

Slide 115 text

Releasing Memories Allocated for Mat IEnumerator ImageProcessing() { canvas.SetActive(false); //Releasing Memories allocated for two Mats if (bgraMat != null) { bgraMat.Release(); } if (binMat != null) { binMat.Release(); } yield return new WaitForEndOfFrame(); CreateImages(); SetColor(capTexture); canvas.SetActive(true); }

Slide 116

Slide 116 text

Procedure Add Alpha Channel Coloring 2D→3D GOAL! capture Binarization

Slide 117

Slide 117 text

capture Binarization Procedure Coloring 2D→3D GOAL! Add Alpha Channel

Slide 118

Slide 118 text

Make White Pixels to Transparent (1/2) void SetColor(Texture2D texture) { //Do nothing if Mats are null if (bgraMat == null || binMat == null) { return; } unsafe { //Get pointer of pixel array of 2 Mats. byte* bgraPtr = bgraMat.DataPointer; byte* binPtr = binMat.DataPointer; //Calculate number of pixels of the image. int pixelCount = binMat.Width * binMat.Height; //Make white pixels to transparent for (int i = 0; i < pixelCount; i++) { } } OpenCvSharp.Unity.MatToTexture(bgraMat, texture); } 後ほど処理を記述

Slide 119

Slide 119 text

Make White Pixels to Transparent (2/2) byte* bgraPtr = bgraMat.DataPointer; byte* binPtr = binMat.DataPointer; int pixelCount = binMat.Width * binMat.Height; for (int i = 0; i < pixelCount; i++) { //Address of blue color of i-th pixel int bgraPos = i * 4; //If i-th pixel of binPtr is 255(white). if (binPtr[i] == 255) { bgraPtr[bgraPos + 3] = 0; } //If i-th pixel of binPtr is 0(black). else { bgraPtr[bgraPos + 3] = 255; } }

Slide 120

Slide 120 text

Data Structure of Pixel Array  Pixel data of each types, gray or bgra, are stored in 1-dimensional array of byte.  binPtr(gray) :  bgraPtr(color+alpha): binPtr bgraPtr Length of pixel array is n (=width*height) Length of pixel array is n*4 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] ・・・ ・・・ 0th pixel 1st 2nd

Slide 121

Slide 121 text

Run ①Capture ②Binarized image with alpha channel

Slide 122

Slide 122 text

capture Binarization Procedure Coloring 2D→3D GOAL! Add Alpha Channel

Slide 123

Slide 123 text

Add Alpha Channel capture Binarization Procedure 2D→3D GOAL! Coloring

Slide 124

Slide 124 text

Making Color Array //14colors. Please cut & paste from color.txt byte[,] colors = { { 255, 255, 255 },{ 18, 0, 230 }, { 0, 152, 243 }, { 0, 241, 255 }, { 31, 195, 143 }, { 68, 153, 0 }, { 150, 158, 0 }, { 233, 160, 0 }, { 183, 104, 0 }, { 136, 32, 29 }, { 131, 7, 146 }, { 127, 0, 228 }, { 79, 0, 229 }, { 0, 0, 0 } }; //index of color(colNo=0~13) int colorNo = 0; void Start() { int w = Screen.width; int h = Screen.height; int sx = (int)(h * 0.1); h = (int)(h * 0.8); /*Following code are omitted.*/ } ①copy&paste from colors.txt ②Write by yourself

Slide 125

Slide 125 text

Change Color of Black Pixels (1/2) void SetColor(Texture2D texture) { //Do nothing if Mats are null if (bgraMat == null || binMat == null) { return; } unsafe { //Get pointer of pixel array of 2 Mats. byte* bgraPtr = bgraMat.DataPointer; byte* binPtr = binMat.DataPointer; //Calculate number of pixels of the image. int pixelCount = binMat.Width * binMat.Height; //Setting transparency and changing color. for (int i = 0; i < pixelCount; i++) { } } OpenCvSharp.Unity.MatToTexture(bgraMat, texture); } Changing color of each pixel. (See next slide.)

Slide 126

Slide 126 text

Change Color of Black Pixels(2/2) for (int i = 0; i < pixelCount; i++) { //Address of blue color of i-th pixel. int bgraPos = i * 4; //If i-th pixel of binPtr is 255(white). if (binPtr[i] == 255) { bgraPtr[bgraPos + 3] = 0; } //If i-th pixel of binPtr is 0(black). else { bgraPtr[bgraPos] = colors[colorNo, 0]; //B bgraPtr[bgraPos + 1] = colors[colorNo, 1]; //G bgraPtr[bgraPos + 2] = colors[colorNo, 2]; //R bgraPtr[bgraPos + 3] = 255; } }

Slide 127

Slide 127 text

Run Please substitute 0~12 to colorNo before you test. colorNo=3

Slide 128

Slide 128 text

Change Color by Using Button public void ChangeColor() { colorNo++; colorNo %= colors.Length / 3; SetColor(capTexture); } //Setting color/alpha information to texture. void SetColor(Texture2D texture) { //Do nothing if each Mat are null. if (bgraMat == null || binMat == null) { return; } unsafe { //Getting pointer of each Mat. byte* bgraPtr = bgraMat.DataPointer; byte* binPtr = binMat.DataPointer; /*Following code are omitted.*/

Slide 129

Slide 129 text

Calling ChangeColor() From UI ①Click ColorBtn ②Find Button ③Click + laying on bottom of OnClick()

Slide 130

Slide 130 text

Calling ChangeColor() From UI Find GameObject Drag&Drop into None of OnClick()

Slide 131

Slide 131 text

Calling ChangeColor() From UI ①Click No Function ②StampScript

Slide 132

Slide 132 text

Calling ChangeColor() From UI ChangeColor()

Slide 133

Slide 133 text

Run Capture Color Color

Slide 134

Slide 134 text

Maximization Preview Area ①RawImage Click

Slide 135

Slide 135 text

Maximization Preview Area Select Full Screen

Slide 136

Slide 136 text

Maximization Preview Area Set Left,Top,Right, Bottom to 0

Slide 137

Slide 137 text

Maximization Preview Area Un check RawImage

Slide 138

Slide 138 text

Showing Preview After Capturing IEnumerator ImageProcessing() { canvas.SetActive(false); //Release memory if (bgraMat != null) { bgraMat.Release(); } if (binMat != null) { binMat.Release(); } yield return new WaitForEndOfFrame(); CreateImages(); SetColor(capTexture); canvas.SetActive(true); //Show preview area preview.enabled = true; }

Slide 139

Slide 139 text

Run Capture

Slide 140

Slide 140 text

Add Alpha Channel capture Binarization Procedure 2D→3D GOAL! Coloring

Slide 141

Slide 141 text

Coloring Add Alpha Channel capture Binarization Procedure 2D→3D GOAL!

Slide 142

Slide 142 text

Making Prefab of Textured Quad Click Quad ②Drag&Drop into QuadをAssets

Slide 143

Slide 143 text

Making Prefab of Textured Quad Delete Quad

Slide 144

Slide 144 text

Stamping Image in Real World. //Template object of textured quad. public GameObject original; void Start() { int w = Screen.width; int h = Screen.height; capRect = new UnityEngine.Rect(0, 0, w, h); capTexture = new Texture2D(w, h, TextureFormat.RGBA32, false); preview.material.mainTexture = capTexture; } //Function to putting stamp object. public void PutObject() { } Source is shown in the next page.

Slide 145

Slide 145 text

Calculation of Physical Size of a Stamp //Getteing camera. Camera cam = Camera.main; //Convert left-bottom of screen into 3D space(z=0.6m) Vector3 v1 = cam.ViewportToWorldPoint(new Vector3(0, 0, 0.6f)); //Convert right-upper of screen into 3D space(z=0.6m) Vector3 v2 = cam.ViewportToWorldPoint(new Vector3(1, 1, 0.6f)); //Convert left-upper of screen into 3D space(z=0.6m) Vector3 v3 = cam.ViewportToWorldPoint(new Vector3(0, 1, 0.6f)); //Calculate physical size of stamp. float w = Vector3.Distance(v2, v3); float h = Vector3.Distance(v1, v3); /*次のページに続く*/ (0,0) (1,1) (0,1) v1 v2 v3

Slide 146

Slide 146 text

Instantiation of Stamp in Real World /*Continued form source code of previous slide*/ GameObject stamp = GameObject.Instantiate(original); //Set position/rotation/size of stamp relative to camera. stamp.transform.parent = cam.transform; stamp.transform.localPosition = new Vector3(0, 0, 0.6f); stamp.transform.localRotation = Quaternion.identity; stamp.transform.localScale = new Vector3(w, h, 1); //Creating texture to apply the object instantiated above. Texture2D stampTexture = new Texture2D(capTexture.width, capTexture.height); //Setting color and applying texture. SetColor(stampTexture); stamp.GetComponent().material.mainTexture = stampTexture; //Detach stamp object from cameara. stamp.transform.parent = null; preview.enabled = false;

Slide 147

Slide 147 text

Linking Object and Variable GameObject

Slide 148

Slide 148 text

Linking Object and Variable Find Quad

Slide 149

Slide 149 text

Linking Object and Variable Drag&Drop into Original

Slide 150

Slide 150 text

Calling PutObject() from UI ①Click StampBtn ②Find Button ③Click + laying on bottom of OnClick()

Slide 151

Slide 151 text

Calling PutObject() from UI Find GameObject Drag&Drop into None of OnClick()

Slide 152

Slide 152 text

Calling PutObject() from UI ①Click No Function ②StampScript

Slide 153

Slide 153 text

Calling PutObject() from UI PutObject()

Slide 154

Slide 154 text

Run

Slide 155

Slide 155 text

Setting Max Number of Stamp //Template object of textured quad public GameObject original; //List for holding generated stamps List stampList = new List(); void Start() { int w = Screen.width; int h = Screen.height; capRect = new UnityEngine.Rect(0, 0, w, h); capTexture = new Texture2D(w, h, TextureFormat.RGBA32, false); preview.material.mainTexture = capTexture; }

Slide 156

Slide 156 text

Setting Max Number of Stamp public void PutObject() { /*Ommited above source code.*/ stamp.transform.parent = null; //Stamp is memorized and deleted by following code. stampList.Add(stamp); if (stampList.Count == 10) { DestroyImmediate(stampList[0]. GetComponent().material.mainTexture); DestroyImmediate(stampList[0]); stampList.RemoveAt(0); } preview.enabled = false; }

Slide 157

Slide 157 text

No content