模型
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
 |
您可在 KML 中以 COLLADA 交互式檔案格式匯入 3D 模型,例如建築物、橋樑、紀念碑和雕像,模型本身是以獨立座標空間的方式獨立於 Google 地球中,並使用 GMS、3D Studio Max、Softimage XSI 或 Maya 等應用程式。將 3D 模型匯入 Google 地球後,就會進行平移、旋轉和縮放,以符合「Google 地球」座標系統。已載入至「Google 地球」的模型可以使用 <Update> 元素來重新定位及調整大小。 |
範例模型
「Google 地球」中的模型可像任何其他幾何圖形物件 (點、線條或多邊形) 一樣使用。以下是匯入紋理紋理的 KML 檔案範例。
模型的 <Link> 參照可以是絕對或相對檔案規格,也可以是網址。
如要查看這個模型,請載入 MackyBldg.kmz 檔案,此檔案包含所有必要的紋理與疊加層檔案,以及包含此模型的 doc.gp 檔案:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>SketchUp Model of Macky Auditorium</name>
<description>University of Colorado, Boulder; model created by Noël Nemcik.</description>
<LookAt>
<longitude>-105.2727379358738</longitude>
<latitude>40.01000594412381</latitude>
<altitude>0</altitude>
<range>127.2393107680517</range>
<tilt>65.74454495876547</tilt>
<heading>-27.70337734057933</heading>
</LookAt>
<Model id="model_4">
<altitudeMode>relativeToGround</altitudeMode>
<Location>
<longitude>-105.272774533734</longitude>
<latitude>40.009993372683</latitude>
<altitude>0</altitude>
</Location>
<Orientation>
<heading>0</heading>
<tilt>0</tilt>
<roll>0</roll>
</Orientation>
<Scale>
<x>1</x>
<y>1</y>
<z>1</z>
</Scale>
<Link>
<href>MackyBldg.kmz/files/CU Macky.dae</href>
</Link>
<ResourceMap id="resourcemap_for_model_4">
<Alias>
<sourceHref>../files/CU-Macky---Center-StairsnoCulling.jpg</sourceHref>
<targetHref>C:/DOCUME~1/josiew/LOCALS~1/Temp/MackyBldg.kmz/files/CU-Macky---Center-StairsnoCulling.jpg</targetHref>
</Alias>
<Alias>
<sourceHref>../files/CU-Macky-4sideturretnoCulling.jpg</sourceHref>
<targetHref>../files/CU-Macky-4sideturretnoCulling.jpg</targetHref>
</Alias>
<Alias>
<sourceHref>../files/CU-Macky-Back-NorthnoCulling.jpg</sourceHref>
<targetHref>../files/CU-Macky-Back-NorthnoCulling.jpg</targetHref>
</Alias>
<Alias>
<sourceHref>../files/CU-Macky-BrickwallnoCulling.jpg</sourceHref>
<targetHref>../files/CU-Macky-BrickwallnoCulling.jpg</targetHref>
</Alias>
.
.
.
</ResourceMap>
</Model>
</Placemark>
</kml>
模型是根據地理位置元素的緯度、經度和海拔規格來定位。這個範例使用 [方向] 和 [比例] 元素的預設值,為附上完整資訊,這些元素提供了完整資訊。
方向元素可指定模型在 x (傾斜)、y (roll) 和 z (heading) 軸周圍的旋轉角度。y 軸指向北方且與經度線平行,x 軸則指向東方,與緯度線平行。旋轉以度數指定,正向旋轉,如下圖所示。

ResourceMap 元素會將紋理檔案從原始 Collada 檔案中指定的位置 (<sourceHref>) 對應至包含模型的 KML 或 KMZ 檔案 (<targetHref>) 中的位置。
注意:在 Google 地球 4.2 之前的版本中,這個對應函式是由 textures.txt 檔案 (KMZ 封存檔案中包含的外部檔案) 執行。Google 地球 4.2 版可接受 KML 和 KMZ 檔案,參照 textures.txt 檔案並正確處理。當 Google 地球 4.2 用戶端與後續版本編寫這類檔案時,textures.txt 檔案中的資訊會轉譯為 <ResourceMap> 及 <Alias> 元素 (也就是 <Model> 的子項)。
建立 .kmz 封存檔案
KMZ 封存是檔案,可用來建立單一 KML 簡報。此封存檔包含 .KML 檔案參照的所有本機檔案,例如圖片、紋理和模型。KMZ 封存檔案是獨立套件,不需要透過網路伺服器代管,而且可以輕鬆透過電子郵件傳送,並以單一單元的形式儲存。Google 地球可以直接讀取 .KML 和 .kmz 檔案。
使用 ZIP 檔案格式,將 doc.KML 檔案及其參照的本機檔案壓縮為封存檔。許多應用程式都可以產生這種格式。Windows 系統中的 WinZip 和 Macintosh 系統上的 Stuffit,以及 Linux 或 Macintosh 系統上的 zip 都是可讀取及寫入 ZIP 格式的常見應用程式。您也可以直接使用 Windows 檔案總管或 Mac Finder 使用 ZIP 封存檔。
建立 .zip 檔案後,請將副檔名變更為 .kmz。
包含 Macky Building 完整紋理模型的 KMZ 封存檔包含下列檔案:
- doc.zoom - 如上所示的 KML 檔案,它會匯入 COLLADA (.dae) 模型並將其放到「Google 地球」中。將這個檔案放在 KMZ (ZIP) 檔案的根目錄中。
- files/ directory - 包含用於定義模型幾何圖形、紋理和材質的 COLLADA 檔案。在 Macky Building 範例中,這個目錄包含 COLLADA 檔案 (CU Macky.dae),以及用來製作建築物紋理的 JPEG 圖片許多檔案 (CU-Macky-BrickwallnoCulling.jpg、CU-Macky.Center-br
這個範例說明如何在 KMZ 封存中建構檔案結構。實際上,您可以將檔案整理成任何對您有邏輯的結構,就像整理電腦中的資料夾或目錄一樣。舉例來說,建議您將所有圖片都放入 images/ 目錄。相對參照 (例如 NetworkLink、Link、Overlay/II 和 Model 中 <href> 元素所參照的檔案) 相對於 doc.KML 檔案。如果加入圖片目錄,則圖片的 <href> 規格為:images/myBrickTexture.jpg、images/myMountainOverlay.png 等)。
返回頁首
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2022-12-20 (世界標準時間)。
[null,null,["上次更新時間:2022-12-20 (世界標準時間)。"],[[["\u003cp\u003eKML allows importing 3D models like buildings and monuments using the COLLADA file format, which are positioned and scaled within Google Earth.\u003c/p\u003e\n"],["\u003cp\u003eModels are defined in their own coordinate space using 3D modeling software and then integrated into Google Earth using latitude, longitude, and altitude.\u003c/p\u003e\n"],["\u003cp\u003eA KMZ archive is a compressed file containing the KML file and associated resources like textures and models, simplifying distribution.\u003c/p\u003e\n"],["\u003cp\u003eThe ResourceMap element within the KML file maps texture files from their original location to their location within the KMZ archive.\u003c/p\u003e\n"],["\u003cp\u003eKMZ archives can be created using standard ZIP compression tools and are readily opened in Google Earth.\u003c/p\u003e\n"]]],[],null,["# Models\n\n|---|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | In KML, you can import 3D models---such as buildings, bridges, monuments, and statues---in the COLLADA interchange file format. Models are defined independently of Google Earth in their own coordinate space, using applications such as [SketchUp](http://sketchup.google.com/), 3D Studio Max, Softimage XSI, or Maya. When a 3D model is imported into Google Earth, it is translated, rotated, and scaled to fit into the Earth coordinate system. Models already loaded into Google Earth can be repositioned and resized using the \\\u003cUpdate\\\u003e element. |\n\nSample Model\n============\n\nA model is used in Google Earth just as any other geometry object (point, linestring, or polygon). Here is a simple example of a KML file that imports a textured model.\n\nThe \\\u003cLink\\\u003e reference to the model can be an an absolute or relative file specification, or a URL.\n\nTo view this model, load the file [*MackyBldg.kmz*](/static/kml/documentation/MackyBldg.kmz), which is an archive that contains all the necessary texture and overlay files as well as this *doc.kml* file containing the Model: \n\n```\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003ckml xmlns=\"http://www.opengis.net/kml/2.2\"\u003e\n\u003cPlacemark\u003e\n \u003cname\u003eSketchUp Model of Macky Auditorium\u003c/name\u003e\n \u003cdescription\u003eUniversity of Colorado, Boulder; model created by Noël Nemcik.\u003c/description\u003e\n \u003cLookAt\u003e\n \u003clongitude\u003e-105.2727379358738\u003c/longitude\u003e\n \u003clatitude\u003e40.01000594412381\u003c/latitude\u003e\n \u003caltitude\u003e0\u003c/altitude\u003e\n \u003crange\u003e127.2393107680517\u003c/range\u003e\n \u003ctilt\u003e65.74454495876547\u003c/tilt\u003e\n \u003cheading\u003e-27.70337734057933\u003c/heading\u003e\n \u003c/LookAt\u003e\n \u003cModel id=\"model_4\"\u003e\n \u003caltitudeMode\u003erelativeToGround\u003c/altitudeMode\u003e\n \u003cLocation\u003e\n \u003clongitude\u003e-105.272774533734\u003c/longitude\u003e\n \u003clatitude\u003e40.009993372683\u003c/latitude\u003e\n \u003caltitude\u003e0\u003c/altitude\u003e\n \u003c/Location\u003e\n \u003cOrientation\u003e\n \u003cheading\u003e0\u003c/heading\u003e\n \u003ctilt\u003e0\u003c/tilt\u003e\n \u003croll\u003e0\u003c/roll\u003e\n \u003c/Orientation\u003e\n \u003cScale\u003e\n \u003cx\u003e1\u003c/x\u003e\n \u003cy\u003e1\u003c/y\u003e\n \u003cz\u003e1\u003c/z\u003e\n \u003c/Scale\u003e\n \u003cLink\u003e\n \u003chref\u003eMackyBldg.kmz/files/CU Macky.dae\u003c/href\u003e\n \u003c/Link\u003e\n \u003cResourceMap id=\"resourcemap_for_model_4\"\u003e\n \u003cAlias\u003e\n \u003csourceHref\u003e../files/CU-Macky---Center-StairsnoCulling.jpg\u003c/sourceHref\u003e\n \u003ctargetHref\u003eC:/DOCUME~1/josiew/LOCALS~1/Temp/MackyBldg.kmz/files/CU-Macky---Center-StairsnoCulling.jpg\u003c/targetHref\u003e\n \u003c/Alias\u003e\n \u003cAlias\u003e\n \u003csourceHref\u003e../files/CU-Macky-4sideturretnoCulling.jpg\u003c/sourceHref\u003e\n \u003ctargetHref\u003e../files/CU-Macky-4sideturretnoCulling.jpg\u003c/targetHref\u003e\n \u003c/Alias\u003e\n \u003cAlias\u003e\n \u003csourceHref\u003e../files/CU-Macky-Back-NorthnoCulling.jpg\u003c/sourceHref\u003e\n \u003ctargetHref\u003e../files/CU-Macky-Back-NorthnoCulling.jpg\u003c/targetHref\u003e\n \u003c/Alias\u003e\n \u003cAlias\u003e\n \u003csourceHref\u003e../files/CU-Macky-BrickwallnoCulling.jpg\u003c/sourceHref\u003e\n \u003ctargetHref\u003e../files/CU-Macky-BrickwallnoCulling.jpg\u003c/targetHref\u003e\n \u003c/Alias\u003e\n.\n.\n.\n \u003c/ResourceMap\u003e\n \u003c/Model\u003e\n\u003c/Placemark\u003e\n\u003c/kml\u003e\n```\n\nThe model is positioned geographically with the Location element's latitude, longitude, and altitude specifications. This example uses default values for the Orientation and Scale elements, which are included here for completeness.\n\nThe Orientation element specifies rotations of the model around the *x* (*tilt* ), *y* (*roll* ) and *z* (*heading* ) axes. The *y* axis points North and is parallel to longitude lines, and the x axis points East and is parallel to latitude lines. Rotations are specified in degrees, with positive rotations as shown in the following diagram.\n\nThe ResourceMap element maps the texture files from the location specified in the original Collada file (\\\u003csourceHref\\\u003e) to a location in the KML or KMZ file (\\\u003ctargetHref\\\u003e) that contains the Model.\n\n**Note:** In releases prior to Google Earth Release 4.2, this mapping function was performed by the *textures.txt* file (an external file included in the KMZ archive). Google Earth 4.2 accepts KML and KMZ files that refer to a *textures.txt* file and processes them correctly. When such files are written out by Google Earth 4.2 clients and later, the information in the *textures.txt* file is translated into the \\\u003cResourceMap\\\u003e and \\\u003cAlias\\\u003e elements, which are children of \\\u003cModel\\\u003e.\n\nCreating a *.kmz* Archive\n=========================\n\nA *KMZ archive* is collection of files used to create a single KML presentation. This archive includes all the local files that are referenced in the *.kml* file, such as images, textures, and models. A KMZ archive is a self-contained package that does not need to be hosted on a network server and can easily be e-mailed and stored as a single unit. Google Earth can read *.kml* and *.kmz* files directly.\n\nThe *doc.kml* file and the local files it references are compressed into an archive using the ZIP file format. Many applications can produce this format. WinZip on Windows systems, Stuffit on Macintosh systems, and zip on Linux or Macintosh systems are popular applications that can read and write the ZIP format. You can also work with zip archives using the Windows Explorer or Mac Finder directly.\n\nAfter you have created the *.zip* file, change the file extension to .*kmz*.\n\nThe KMZ archive containing the complete textured model for the Macky Building includes these files:\n\n- ***doc.kml*** - the KML file shown above, which imports the COLLADA *(.dae)* model and places it in Google Earth. Place this file in the root directory of the KMZ (ZIP) file.\n\n\u003c!-- --\u003e\n\n- ***files/*** directory - contains the COLLADA files that define the geometry, textures, and material of the model. In the Macky Building example, this directory contains the COLLADA file *(CU Macky.dae)* as well as the numerous files containing the JPEG images used to texture the building (*CU-Macky-BrickwallnoCulling.jpg, CU-Macky--Center-StairsnoCulling.jpg, CU_Macky-EastdetaildoornoCulling.jpg*, and so on).\n\nThis example illustrates one way to structure the files in a KMZ archive. Actually, you can arrange the files in any structure that seems logical to you, just as you organize the files into folders or directories on your computer. For example, it might be useful to put all the images in an *images/* directory. Relative references (such as the files referred to in the \\\u003chref\\\u003e element that is used in NetworkLink, Link, Overlay/Icon, and Model) are specified relative to the *doc.kml* file. If you include an images directory, then the \\\u003chref\\\u003e specification for your images would be: *images/myBrickTexture.jpg* , *images/myMountainOverlay.png*, and so on).\n\n[Back to top](#top)"]]