File Exchange

image thumbnail

mesh2kml

version 1.0.1 (22.1 KB) by

Export textured geometry (surface or patch) to GoogleEarth as a KML and a Collada DAE files

9 Downloads

Updated

View License

Export textured geometry (surface or patch) to GoogleEarth as a KML and a
Collada DAE files
mesh2kml(...) -surface or patch inputs, see bellow
mesh2kml(...out) -one common output filename or paths to {dae img kml}
mesh2kml(...out,prp) -Collada & GoogleEarth property value pairs
color: color, default=[0.7 0.7 0.7] OR..
image, RGB(A)|BW(A)|filename (optional)
alpha: opacity, default=[1] (opaque) OR..
image, BW|filename (optional)
latlon: flag to interpret xyz as Lat,Lon,Alt, default=0
twosided: flag to render faces from both sides, default=1
position: [latitude_deg longitude_deg altitude_m]
altmode: default='absolute', 'clampToGround', 'relativeToGround',
'relativeToSeaFloor', 'clampToSeaFloor'
orientation:[heading_NtoE pitch_NtoUp roll_UPtoE] (deg), default=[0,0,0]
scale: [x y z] scale factors, default=[1,1,1]
camera: [heading_deg tilt_deg range_m]
M = mesh2kml(...) -return final properties as struct
Surface:
mesh2kml(x,y,z...) -NxM vertex coordinates
mesh2kml(x,y,z,c...) -NxMx3 face colors, last row & col ignored (TO DO)
mesh2kml(x,y,z,u,v...) -NxM texture coordinates
mesh2kml(..,nx,ny,nz...) -NxM vertex normals
mesh2kml(S) -above surface properties as struct
Patch:
mesh2kml(P...) -patch properties as struct, with fields:
vertices: Nx3 vertex positions
faces: Mx3 triangle faces (right hand rule)
normals: Nx3 vertex normals (optional)
uv: Nx2 texture coordinates for each vertex

Remarks:
-Collada (dae) files can be dragged and dropped into GoogleEarth.
-A kml file is written only if 'position' is provided.
-For lat,lon 6dp gives ~15 cm precision at equator, 8dp is ~1.5 mm.
-Textures wrap circularly if UV is outside the [0-1] range.
-Texture pixels blend and image edge pixels blend with opposite edge.
-If normals are not provided they are auto generated. Vertices shared by
triangles get a smoothed normal using triangle area weighting.
-To avoid normal smoothing when specifying a patch each vertex should be
referenced by only one face.
-Faces are auto generated using vertices(:,1:2), if missing.

Notes:
-Altitude exaggeration in GoogleEarth will affect the model's origin.
-The only way to visualise textured polygons in MatLab is to draw each
polygon as a quad with its own image chip, which is very limiting.
-To generate dae template draw a polygon in Google SketchUp 2017 > export
as kmz > open kmz with winzip > extract dae file > modify as needed.
-SketchUp duplicates all polygons to face both ways, but mesh2kml uses an
undocumented Collada tag: <effect><extra><technique><double_sided>.
-SketchUp can export a quad mesh dae but they don't work in GoogleEarth.
-GoogleEarth ignores camera references in dae file.

To do:
-Allow one colour per face, see surf2patch.
-Allow multi patch input using array of structures as input.
-Allow quad patch input by converting it to a tri patch.
-Allow input to be a handle to a displayed surface or patch object.
-Allow export as kmz file.
-Use ridge detection when triangulating surfaces.
-Test generated normals.
-Add more patch examples.
-Remove thin triangles from patch inputs.

Comments and Ratings (1)

Bin Li

Bin Li (view profile)

Updates

1.0.1

Title change

1.0.1

Minor changes

1.0

Cover photo

MATLAB Release
MATLAB 7.14 (R2012a)
Acknowledgements

Inspired by: Google Toolbox, KML toolbox

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today