<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Teapot &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/teapot/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Sat, 24 Jul 2021 03:14:53 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>Teapot &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Qualcomm Vuforia 教學 (5) – 替換茶壺 – Android JNI 版本</title>
		<link>https://noter.tw/3392/qualcomm-vuforia-%e6%95%99%e5%ad%b8-5-%e6%9b%bf%e6%8f%9b%e8%8c%b6%e5%a3%ba-android-jni-%e7%89%88%e6%9c%ac/</link>
					<comments>https://noter.tw/3392/qualcomm-vuforia-%e6%95%99%e5%ad%b8-5-%e6%9b%bf%e6%8f%9b%e8%8c%b6%e5%a3%ba-android-jni-%e7%89%88%e6%9c%ac/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Tue, 09 Dec 2014 09:54:17 +0000</pubDate>
				<category><![CDATA[手機 App]]></category>
		<category><![CDATA[Teapot]]></category>
		<category><![CDATA[glDrawArrays]]></category>
		<category><![CDATA[ndk-build]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[AR]]></category>
		<category><![CDATA[Qualcomm]]></category>
		<category><![CDATA[Vuforia]]></category>
		<guid isPermaLink="false">http://wazai.net/?p=3392</guid>

					<description><![CDATA[<p>前面的文章提到為什麼要用 Android NDK 來開發，既然已經有了 Android 版本替換茶壺的文章，這邊記錄 Android NDK 版本的替換茶壺。 2016-07-07 更新：本篇為 3.&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/3392/qualcomm-vuforia-%e6%95%99%e5%ad%b8-5-%e6%9b%bf%e6%8f%9b%e8%8c%b6%e5%a3%ba-android-jni-%e7%89%88%e6%9c%ac/" data-wpel-link="internal">Qualcomm Vuforia 教學 (5) – 替換茶壺 – Android JNI 版本</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>前面的文章提到為什麼要用 Android NDK 來開發，既然已經有了 Android 版本替換茶壺的文章，這邊記錄 Android NDK 版本的替換茶壺。</p>



<span id="more-3392"></span>



<p><strong>2016-07-07 更新：本篇為 3.x 版本，目前 Vuforia 以更新到 5.5.9，新版本使用方式請參考&nbsp;</strong></p>



<p><strong>Android Vuforia 系列：</strong></p>



<ul class="my-li bg-darkblue wp-block-list"><li><a href="https://noter.tw/3639/android-vuforia-with-jpct-ae-1-%e5%9f%ba%e6%9c%ac%e7%af%84%e4%be%8b/" data-wpel-link="internal">Android Vuforia with jPCT-AE (1) – 基本範例</a></li><li><a href="https://noter.tw/3688/android-vuforia-with-jpct-ae-2-%e8%bc%89%e5%85%a5-obj-%e6%b8%ac%e8%a9%a6/" data-wpel-link="internal">Android Vuforia with jPCT-AE (2) – 載入 obj 測試</a></li><li><a href="https://noter.tw/3735/android-vuforia-with-jpct-ae-3-%e8%bc%89%e5%85%a5-md2-%e6%b8%ac%e8%a9%a6/" data-wpel-link="internal">Android Vuforia with jPCT-AE (3) – 載入 md2 測試</a></li><li><a href="https://noter.tw/3737/android-vuforia-with-jpct-ae-4-%e8%bc%89%e5%85%a5-3ds-%e6%b8%ac%e8%a9%a6/" data-wpel-link="internal">Android Vuforia with jPCT-AE (4) – 載入 3DS 測試</a></li><li><a href="https://noter.tw/3739/android-vuforia-with-jpct-ae-5-%e5%a4%9a%e9%87%8d%e6%a8%a1%e5%9e%8b%e8%bc%89%e5%85%a5%ef%bc%8c%e4%bb%a5-obj-%e7%82%ba%e4%be%8b/" data-wpel-link="internal">Android Vuforia with jPCT-AE (5) – 多重模型載入，以 obj 為例</a></li></ul>


<p><span style="line-height: 1.5em;">使用 Android NDK 來做的好處在</span><a style="line-height: 1.5em;" title="Qualcomm Vuforia 教學 (4) – 使用 Android NDK 版本並開啟多重偵測" href="https://noter.tw/3371/qualcomm-vuforia-%e6%95%99%e5%ad%b8-4-%e4%bd%bf%e7%94%a8-android-ndk-%e7%89%88%e6%9c%ac%e4%b8%a6%e9%96%8b%e5%95%9f%e5%a4%9a%e9%87%8d%e5%81%b5%e6%b8%ac/" data-wpel-link="internal">上一篇文章</a><span style="line-height: 1.5em;">已提過，C++ 在處理複雜模型上有不錯的表現，也不會出現 Java 宣告大小上限的問題，直接進入步驟。</span></p>
<p style="padding-left: 30px;">1. 下載範例檔案 &#8211; <a href="https://noter.tw/dn/cube.h" target="_blank" rel="noopener noreferrer" data-wpel-link="internal">cube.h</a>、<a href="https://noter.tw/dn/cube.png" target="_blank" rel="noopener noreferrer" data-wpel-link="internal">cube.png</a> (這個跟前面範例使用的是一樣的)</p>
<p style="padding-left: 30px;">2. 將範例檔案<span style="color: #0000ff;"><strong> cube.h</strong></span> 放到&nbsp;&nbsp;ImageTargetsNative 專案下的<strong><span style="color: #ff0000;"> jni 目錄</span></strong></p>
<p style="padding-left: 30px;">3. 將範例檔案 <span style="color: #0000ff;"><strong>cube.png</strong></span> 放到&nbsp;ImageTargetsNative 專案下的 <span style="color: #ff0000;"><strong>assets 目錄</strong></span></p>
<p style="padding-left: 30px;">4. 開啟&nbsp;ImageTargetsNative 專案下 jni 下的<span style="color: #0000ff;"><strong> ImageTargets.cpp</strong></span></p>
<div>
<div id="highlighter_118336" class="syntaxhighlighter  cpp">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="gutter">
<div class="line number1 index0 alt2">01</div>
<div class="line number2 index1 alt1">02</div>
<div class="line number3 index2 alt2">03</div>
<div class="line number4 index3 alt1">04</div>
<div class="line number5 index4 alt2">05</div>
<div class="line number6 index5 alt1">06</div>
<div class="line number7 index6 alt2">07</div>
<div class="line number8 index7 alt1">08</div>
<div class="line number9 index8 alt2">09</div>
<div class="line number10 index9 alt1">10</div>
<div class="line number11 index10 alt2">11</div>
<div class="line number12 index11 alt1">12</div>
<div class="line number13 index12 alt2">13</div>
<div class="line number14 index13 alt1">14</div>
<div class="line number15 index14 alt2">15</div>
<div class="line number16 index15 alt1">16</div>
<div class="line number17 index16 alt2">17</div>
</td>
<td class="code">
<div class="container">
<div class="line number1 index0 alt2"><code class="cpp comments">// 在上方加入</code></div>
<div class="line number2 index1 alt1"><code class="cpp preprocessor">#include "cube.h"</code></div>
<div class="line number3 index2 alt2"><code class="cpp comments">// static const float kObjectScale = 3.f;</code></div>
<div class="line number4 index3 alt1"><code class="cpp comments">// 改成</code></div>
<div class="line number5 index4 alt2"><code class="cpp keyword bold">static</code> <code class="cpp keyword bold">const</code> <code class="cpp color1 bold">float</code> <code class="cpp plain">kObjectScale = 120.f;</code></div>
<div class="line number6 index5 alt1"><code class="cpp comments">// glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &amp;teapotVertices[0]);</code></div>
<div class="line number7 index6 alt2"><code class="cpp comments">// 改成</code></div>
<div class="line number8 index7 alt1"><code class="cpp plain">glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (</code><code class="cpp keyword bold">const</code> <code class="cpp plain">GLvoid*) &amp;cubeVerts[0]);</code></div>
<div class="line number9 index8 alt2"><code class="cpp comments">// glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &amp;teapotNormals[0]);</code></div>
<div class="line number10 index9 alt1"><code class="cpp comments">// 改成</code></div>
<div class="line number11 index10 alt2"><code class="cpp plain">glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (</code><code class="cpp keyword bold">const</code> <code class="cpp plain">GLvoid*) &amp;cubeNormals[0]);</code></div>
<div class="line number12 index11 alt1"><code class="cpp comments">// glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &amp;teapotTexCoords[0]);</code></div>
<div class="line number13 index12 alt2"><code class="cpp comments">// 改成</code></div>
<div class="line number14 index13 alt1"><code class="cpp plain">glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (</code><code class="cpp keyword bold">const</code> <code class="cpp plain">GLvoid*) &amp;cubeTexCoords[0]);</code></div>
<div class="line number15 index14 alt2"><code class="cpp comments">// glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &amp;teapotIndices[0]);</code></div>
<div class="line number16 index15 alt1"><code class="cpp comments">// 改成</code></div>
<div class="line number17 index16 alt2"><code class="cpp plain">glDrawArrays(GL_TRIANGLES, 0, cubeNumVerts);</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p style="padding-left: 30px;">5.&nbsp;開啟&nbsp;ImageTargetsNative 專案下 jni 下的<strong>&nbsp;<span style="color: #0000ff;">ImageTargets.java</span></strong></p>
<div>
<div id="highlighter_747441" class="syntaxhighlighter  java">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="gutter">
<div class="line number1 index0 alt2">1</div>
<div class="line number2 index1 alt1">2</div>
<div class="line number3 index2 alt2">3</div>
<div class="line number4 index3 alt1">4</div>
<div class="line number5 index4 alt2">5</div>
<div class="line number6 index5 alt1">6</div>
<div class="line number7 index6 alt2">7</div>
<div class="line number8 index7 alt1">8</div>
</td>
<td class="code">
<div class="container">
<div class="line number1 index0 alt2"><code class="java keyword">private</code> <code class="java keyword">void</code> <code class="java plain">loadTextures()</code></div>
<div class="line number2 index1 alt1"><code class="java plain">{</code></div>
<div class="line number3 index2 alt2"><code class="java spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="java comments">//mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png", getAssets()));</code></div>
<div class="line number4 index3 alt1"><code class="java spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="java plain">mTextures.add(Texture.loadTextureFromApk(</code><code class="java string">"TextureTeapotBlue.png"</code><code class="java plain">, getAssets()));</code></div>
<div class="line number5 index4 alt2"><code class="java spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="java plain">mTextures.add(Texture.loadTextureFromApk(</code><code class="java string">"cube.png"</code><code class="java plain">, getAssets()));</code></div>
<div class="line number6 index5 alt1"><code class="java spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="java plain">mTextures.add(Texture.loadTextureFromApk(</code><code class="java string">"TextureTeapotRed.png"</code><code class="java plain">, getAssets()));</code></div>
<div class="line number7 index6 alt2"><code class="java spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="java plain">mTextures.add(Texture.loadTextureFromApk(</code><code class="java string">"Buildings.jpeg"</code><code class="java plain">, getAssets()));</code></div>
<div class="line number8 index7 alt1"><code class="java plain">}</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p style="padding-left: 30px;">6. 執行 <span style="color: #ff0000;"><strong>ndk-build</strong></span> (如果忘記可查看<a title="Qualcomm Vuforia 教學 (4) – 使用 Android NDK 版本並開啟多重偵測" href="https://noter.tw/3371/qualcomm-vuforia-%e6%95%99%e5%ad%b8-4-%e4%bd%bf%e7%94%a8-android-ndk-%e7%89%88%e6%9c%ac%e4%b8%a6%e9%96%8b%e5%95%9f%e5%a4%9a%e9%87%8d%e5%81%b5%e6%b8%ac/" target="_blank" rel="noopener noreferrer" data-wpel-link="internal">上一篇文章</a>)，重新整理 Eclipse 專案後執行。下圖是 cube.h 透過 OpenGL 畫出來的模型，上方是 cube.png 當材質繪製出來的，下方是原本範例中茶壺的貼圖。<br><a title="018.png" href="http://lh4.ggpht.com/-BU2AtqHNgIQ/VIbD6BeJZ-I/AAAAAAAAKl0/kXuktzOsul0/s0/018.png" target="_blank" rel="noopener nofollow external noreferrer" data-wpel-link="external"><img fetchpriority="high" decoding="async" class="pe2-photo aligncenter" title="018.png" src="//lh4.ggpht.com/-BU2AtqHNgIQ/VIbD6BeJZ-I/AAAAAAAAKl0/kXuktzOsul0/w500-o/018.png" alt="018.png" width="180" height="320"></a></p>


<p><strong>Qualcomm Vuforia&nbsp;</strong><strong>系列：</strong></p>



<ul class="my-li bg-darkblue wp-block-list"><li><a href="https://noter.tw/3320/qualcomm-vuforia-%e6%95%99%e5%ad%b8-1/" data-wpel-link="internal">Qualcomm Vuforia 教學 (1) – 安裝 Vuforia</a></li><li><a href="https://noter.tw/3347/qualcomm-vuforia-%e6%95%99%e5%ad%b8-2-create-image-target/" data-wpel-link="internal">Qualcomm Vuforia 教學 (2) – Create Image Target</a></li><li><a href="https://noter.tw/3360/qualcomm-vuforia-%e6%95%99%e5%ad%b8-3-%e6%9b%bf%e6%8f%9b%e8%8c%b6%e5%a3%ba-android-%e7%89%88%e6%9c%ac/" data-wpel-link="internal">Qualcomm Vuforia 教學 (3) – 替換茶壺 – Android 版本</a></li><li><a href="https://noter.tw/3371/qualcomm-vuforia-%e6%95%99%e5%ad%b8-4-%e4%bd%bf%e7%94%a8-android-ndk-%e7%89%88%e6%9c%ac%e4%b8%a6%e9%96%8b%e5%95%9f%e5%a4%9a%e9%87%8d%e5%81%b5%e6%b8%ac/" data-wpel-link="internal">Qualcomm Vuforia 教學 (4) – 使用 Android NDK 版本並開啟多重偵測</a></li><li><a href="https://noter.tw/3392/qualcomm-vuforia-%e6%95%99%e5%ad%b8-5-%e6%9b%bf%e6%8f%9b%e8%8c%b6%e5%a3%ba-android-jni-%e7%89%88%e6%9c%ac/" data-wpel-link="internal">Qualcomm Vuforia 教學 (5) – 替換茶壺 – Android JNI 版本</a></li><li><a href="https://noter.tw/3403/qualcomm-vuforia-%e6%95%99%e5%ad%b8-6-3d-model-obj-h/" data-wpel-link="internal">Qualcomm Vuforia 教學 (6) – 3D model -&gt; .obj -&gt; .h</a></li></ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/3392/qualcomm-vuforia-%e6%95%99%e5%ad%b8-5-%e6%9b%bf%e6%8f%9b%e8%8c%b6%e5%a3%ba-android-jni-%e7%89%88%e6%9c%ac/" data-wpel-link="internal">Qualcomm Vuforia 教學 (5) – 替換茶壺 – Android JNI 版本</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/3392/qualcomm-vuforia-%e6%95%99%e5%ad%b8-5-%e6%9b%bf%e6%8f%9b%e8%8c%b6%e5%a3%ba-android-jni-%e7%89%88%e6%9c%ac/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Qualcomm Vuforia 教學 (3) – 替換茶壺 – Android 版本</title>
		<link>https://noter.tw/3360/qualcomm-vuforia-%e6%95%99%e5%ad%b8-3-%e6%9b%bf%e6%8f%9b%e8%8c%b6%e5%a3%ba-android-%e7%89%88%e6%9c%ac/</link>
					<comments>https://noter.tw/3360/qualcomm-vuforia-%e6%95%99%e5%ad%b8-3-%e6%9b%bf%e6%8f%9b%e8%8c%b6%e5%a3%ba-android-%e7%89%88%e6%9c%ac/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Tue, 09 Dec 2014 07:38:17 +0000</pubDate>
				<category><![CDATA[手機 App]]></category>
		<category><![CDATA[Qualcomm]]></category>
		<category><![CDATA[Vuforia]]></category>
		<category><![CDATA[GLES20.glDrawArrays]]></category>
		<category><![CDATA[ImageTarget]]></category>
		<category><![CDATA[ImageTargetRenderer]]></category>
		<category><![CDATA[Teapot]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[AR]]></category>
		<guid isPermaLink="false">http://wazai.net/?p=3360</guid>

					<description><![CDATA[<p>接續上一篇&#160;Qualcomm Vuforia 教學 (2) – Create Image Target，這篇要來記錄怎麼把預設的茶壺 (Teapot) 換成簡單的正方形 (Cube)。 20&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/3360/qualcomm-vuforia-%e6%95%99%e5%ad%b8-3-%e6%9b%bf%e6%8f%9b%e8%8c%b6%e5%a3%ba-android-%e7%89%88%e6%9c%ac/" data-wpel-link="internal">Qualcomm Vuforia 教學 (3) – 替換茶壺 – Android 版本</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>接續上一篇&nbsp;<a rel="noreferrer noopener" href="https://noter.tw/3347/qualcomm-vuforia-%e6%95%99%e5%ad%b8-2-create-image-target/" target="_blank" data-wpel-link="internal">Qualcomm Vuforia 教學 (2) – Create Image Target</a>，這篇要來記錄怎麼把預設的茶壺 (Teapot) 換成簡單的正方形 (Cube)。 </p>



<span id="more-3360"></span>



<p><strong>2016-07-07 更新：本篇為 3.x 版本，目前 Vuforia 以更新到 5.5.9，新版本使用方式請參考</strong></p>



<p><strong>Android Vuforia 系列：</strong></p>



<ul class="my-li bg-darkblue wp-block-list"><li><a href="https://noter.tw/3639/android-vuforia-with-jpct-ae-1-%e5%9f%ba%e6%9c%ac%e7%af%84%e4%be%8b/" data-wpel-link="internal">Android Vuforia with jPCT-AE (1) – 基本範例</a></li><li><a href="https://noter.tw/3688/android-vuforia-with-jpct-ae-2-%e8%bc%89%e5%85%a5-obj-%e6%b8%ac%e8%a9%a6/" data-wpel-link="internal">Android Vuforia with jPCT-AE (2) – 載入 obj 測試</a></li><li><a href="https://noter.tw/3735/android-vuforia-with-jpct-ae-3-%e8%bc%89%e5%85%a5-md2-%e6%b8%ac%e8%a9%a6/" data-wpel-link="internal">Android Vuforia with jPCT-AE (3) – 載入 md2 測試</a></li><li><a href="https://noter.tw/3737/android-vuforia-with-jpct-ae-4-%e8%bc%89%e5%85%a5-3ds-%e6%b8%ac%e8%a9%a6/" data-wpel-link="internal">Android Vuforia with jPCT-AE (4) – 載入 3DS 測試</a></li><li><a href="https://noter.tw/3739/android-vuforia-with-jpct-ae-5-%e5%a4%9a%e9%87%8d%e6%a8%a1%e5%9e%8b%e8%bc%89%e5%85%a5%ef%bc%8c%e4%bb%a5-obj-%e7%82%ba%e4%be%8b/" data-wpel-link="internal">Android Vuforia with jPCT-AE (5) – 多重模型載入，以 obj 為例</a></li></ul>



<p>小蛙先提供兩個檔案下載，一個是 <strong>cube.png</strong> 用來當作等等要替換的材質貼圖，另一個是繼承 Vuforia SDK MeshObject 的 3D 模型物件 <strong>CubeTest2.java</strong>。點選下載 &#8211; <a href="https://noter.tw/dn/cube.png" target="_blank" rel="noreferrer noopener" data-wpel-link="internal">cube.png</a>、<a href="https://noter.tw/dn/CubeTest2.java" target="_blank" rel="noreferrer noopener" data-wpel-link="internal">CubeTest2.java</a>。</p>



<p>在之後的文章會說明要怎麼產生出像 CubeTest2.java 這種檔案或裡面的一些模型資訊，這個範例就先直接套用下載下來的檔案。接著需要對 <strong>ImageTargetRender.java</strong>、<strong>ImageTarget.java</strong> 作一些修改。CubeTest2.java 內容可以大概看一下，重點只有在之後的修改會讓 <strong>mIndBuff </strong>都是空白 (小蛙找到的教學產生出來的檔案都沒有 Indices 資訊，這邊把 <strong>setIndices()</strong> 做了些修改，避免出現 NullPointerException 錯誤)。</p>



<p>正式開始。</p>



<p>1. 把下載來的<strong> cube.png</strong> 放到 <strong>VuforiaSample 專案下的 assets 目錄</strong>中 (在目錄中看到&nbsp;TextureTeapotBlue.png 這些就表示位置對了)</p>



<p>2. 把下載來的 <strong>CubeTest2.java</strong> 放在&nbsp;<strong>com.qualcomm.vuforia.samples.SampleApplication.utils package</strong> 下，同目錄可以看到 Teapot.java</p>



<p>3. 修改 <strong>com.qualcomm.vuforia.samples.VuforiaSamples.app.ImageTargets\ImageTarget.java</strong><br>找到&nbsp;<strong>loadTextures()</strong> 載入材質時，一併載入 cube.png</p>



<pre class="wp-block-preformatted withcode">private void loadTextures()
{
        //mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png", getAssets()));
        mTextures.add(Texture.loadTextureFromApk("TextureTeapotBlue.png", getAssets()));
        mTextures.add(Texture.loadTextureFromApk("cube.png", getAssets()));
        mTextures.add(Texture.loadTextureFromApk("TextureTeapotRed.png", getAssets()));
        mTextures.add(Texture.loadTextureFromApk("ImageTargets/Buildings.jpeg", getAssets()));
}</pre>



<p>4. 修改 <strong>com.qualcomm.vuforia.samples.VuforiaSamples.app.ImageTargets\ImageTargetRenderer.java</strong> ，這邊採用註解掉的方式，到時要復原比較方便</p>



<pre class="wp-block-preformatted withcode">// 註解掉 private Teapot mTeapot; 並加入
private CubeTest2 mTeapot;
// 注解掉 private static final float OBJECT_SCALE_FLOAT = 3.0f; 並加入
private static final float OBJECT_SCALE_FLOAT = 120.0f;
// 註解掉 mTeapot = new Teapot(); 並加入
mTeapot = new CubeTest2();
// 註解掉以下幾行
//GLES20.glDrawElements(GLES20.GL_TRIANGLES,
//                    mTeapot.getNumObjectIndex(), GLES20.GL_UNSIGNED_SHORT,
//                    mTeapot.getIndices());
// 並加入
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, mTeapot.getNumObjectVertex());</pre>



<div class="wp-block-image"><figure class="aligncenter is-resized"><a href="http://lh4.ggpht.com/-iKUnFBtOnm8/VIalvTvAt_I/AAAAAAAAKk4/GNUCcmo3-j4/s0/Screenshot_2014-12-09-14-50-29.png" target="_blank" rel="noopener nofollow external noreferrer" data-wpel-link="external"><img decoding="async" src="//lh4.ggpht.com/-iKUnFBtOnm8/VIalvTvAt_I/AAAAAAAAKk4/GNUCcmo3-j4/w500-o/Screenshot_2014-12-09-14-50-29.png" alt="Screenshot_2014-12-09-14-50-29.png" width="250" height="445" title="Screenshot_2014-12-09-14-50-29.png"/></a></figure></div>



<p>5. 執行專案，就可以看到茶壺被取代掉了，變成一個方形，並且貼上了 cube.png 這張圖的表面，至於上下為什麼黑黑的，這跟 3D 塑模時的打光以及環境光源有關，這裡就不討論了。</p>



<p>也許有更好的做法，但網路上大多找到的教學都是以<strong> Unity Extension </strong>為主，以 Android 為主的較少，所以如果有更好的方法，也歡迎提供給小蛙！感恩！</p>



<p><strong>Qualcomm Vuforia&nbsp;</strong><strong>系列：</strong></p>



<ul class="my-li bg-darkblue wp-block-list"><li><a href="https://noter.tw/3320/qualcomm-vuforia-%e6%95%99%e5%ad%b8-1/" data-wpel-link="internal">Qualcomm Vuforia 教學 (1) – 安裝 Vuforia</a></li><li><a href="https://noter.tw/3347/qualcomm-vuforia-%e6%95%99%e5%ad%b8-2-create-image-target/" data-wpel-link="internal">Qualcomm Vuforia 教學 (2) – Create Image Target</a></li><li><a href="https://noter.tw/3360/qualcomm-vuforia-%e6%95%99%e5%ad%b8-3-%e6%9b%bf%e6%8f%9b%e8%8c%b6%e5%a3%ba-android-%e7%89%88%e6%9c%ac/" data-wpel-link="internal">Qualcomm Vuforia 教學 (3) – 替換茶壺 – Android 版本</a></li><li><a href="https://noter.tw/3371/qualcomm-vuforia-%e6%95%99%e5%ad%b8-4-%e4%bd%bf%e7%94%a8-android-ndk-%e7%89%88%e6%9c%ac%e4%b8%a6%e9%96%8b%e5%95%9f%e5%a4%9a%e9%87%8d%e5%81%b5%e6%b8%ac/" data-wpel-link="internal">Qualcomm Vuforia 教學 (4) – 使用 Android NDK 版本並開啟多重偵測</a></li><li><a href="https://noter.tw/3392/qualcomm-vuforia-%e6%95%99%e5%ad%b8-5-%e6%9b%bf%e6%8f%9b%e8%8c%b6%e5%a3%ba-android-jni-%e7%89%88%e6%9c%ac/" data-wpel-link="internal">Qualcomm Vuforia 教學 (5) – 替換茶壺 – Android JNI 版本</a></li><li><a href="https://noter.tw/3403/qualcomm-vuforia-%e6%95%99%e5%ad%b8-6-3d-model-obj-h/" data-wpel-link="internal">Qualcomm Vuforia 教學 (6) – 3D model -&gt; .obj -&gt; .h</a></li></ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/3360/qualcomm-vuforia-%e6%95%99%e5%ad%b8-3-%e6%9b%bf%e6%8f%9b%e8%8c%b6%e5%a3%ba-android-%e7%89%88%e6%9c%ac/" data-wpel-link="internal">Qualcomm Vuforia 教學 (3) – 替換茶壺 – Android 版本</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/3360/qualcomm-vuforia-%e6%95%99%e5%ad%b8-3-%e6%9b%bf%e6%8f%9b%e8%8c%b6%e5%a3%ba-android-%e7%89%88%e6%9c%ac/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
