Skip to content

Commit

Permalink
Merge pull request #23 from loicgasser/light
Browse files Browse the repository at this point in the history
Fix light computation
  • Loading branch information
loicgasser authored Mar 28, 2018
2 parents a31f5c2 + 9d1d895 commit 31a0560
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist/
build/
doc/build/
.idea/
.coverage
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ quantized-mesh-tile
[![Coverage Status](https://coveralls.io/repos/github/loicgasser/quantized-mesh-tile/badge.svg?branch=master)](https://coveralls.io/github/loicgasser/quantized-mesh-tile?branch=master)
[![Doc Status](https://readthedocs.org/projects/quantized-mesh-tile/badge/?version=latest)](http://quantized-mesh-tile.readthedocs.io/en/latest/?badge=latest)

Quantized-mesh-tile is a Python encoder/decoder and topology builder for terrain tiles.
[Quantized-mesh-tile](https://github.com/AnalyticalGraphicsInc/quantized-mesh) is a Python encoder/decoder and topology builder for terrain tiles.

Doc is hosted on Readthedocs: https://quantized-mesh-tile.readthedocs.io/en/latest/
4 changes: 2 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
# built documents.
#
# The short X.Y version.
version = u'0.4'
version = u'0.5'
# The full version, including alpha/beta/rc tags.
release = u'0.4'
release = u'0.5'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
12 changes: 5 additions & 7 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,18 @@ Disclamer

This library is only at a very early stage (very first version) and is subject to changes.

Known issue
-----------

This library can read and write tiles with the lighting extension header, but still fail to create correct unit
vectors from scratch. PRs are welcome though!

Development
-----------

The code is available on GitHub: https://github.com/loicgasser/quantized-mesh-tile

Contributors:
Author:

* Loïc Gasser (https://github.com/loicgasser)

Contributors:

* tiloSchlemmer (https://github.com/thiloSchlemmer)
* Gilbert Jeiziner (https://github.com/gjn)
* Roland Arsenault (https://github.com/rolker)
* Ulrich Meier (https://github.com/umeier)
Expand Down
7 changes: 6 additions & 1 deletion doc/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The only available client able to read and display this format is `Cesium`_.
This module has been developed based on the specifications of the format described `here`_.

.. _here:
http://cesiumjs.org/data-and-assets/terrain/formats/quantized-mesh-1.0.html
https://github.com/AnalyticalGraphicsInc/quantized-mesh

Therefore, if you've planned on creating your own terrain server, please make sure you follow all the instructions
provided in the specifications of the format. You may also need to define a `layer.json`_ metadata file at the root of your
Expand Down Expand Up @@ -85,6 +85,11 @@ If you don't want to create a physical file but only need its content, you can u

This operation will create a gzipped compressed string buffer wrapped in a `io.BytesIO` instance.

If you want to enable lighting effect (experimental):

>>> tile = encode(geometries, bounds=bounds, hasLighting=True)
>>> content = tile.toBytesIO(gzipped=True)

To define a water-mask you can use:

>>> # Water only
Expand Down
4 changes: 2 additions & 2 deletions quantized_mesh_tile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def encode(geometries, bounds=[], autocorrectGeometries=False, hasLighting=False
Default is `False`.
``hasLighting``
``hasLighting`` (Experimental)
Indicate whether unit vectors should be computed for the lighting extension.
Expand Down Expand Up @@ -93,7 +93,7 @@ def decode(filePath, bounds, hasLighting=False, hasWatermask=False, gzipped=Fals
The bounds of the terrain tile. (west, south, east, north) (Required).
``hasLighting``
``hasLighting`` (Experimental)
Indicate whether the tile has the lighting extension.
Expand Down
14 changes: 3 additions & 11 deletions quantized_mesh_tile/terrain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" This module defines the :class:`quantized_mesh_tile.terrain.TerrainTile`.
More information about the format specification can be found here:
http://cesiumjs.org/data-and-assets/terrain/formats/quantized-mesh-1.0.html
https://github.com/AnalyticalGraphicsInc/quantized-mesh
Reference
---------
Expand Down Expand Up @@ -388,11 +388,7 @@ def fromBytesIO(self, f, hasLighting=False, hasWatermask=False):
if extensionId == 1:
extensionLength = unpackEntry(f, meta['extensionLength'])

# Consider padding of 2 bits
# http://cesiumjs.org/data-and-assets/terrain/formats/quantized-mesh-1.0.html
f.read(2)

for i in range(0, (old_div(extensionLength, 2)) - 1):
for i in range(0, old_div(extensionLength, 2)):
x = unpackEntry(f, TerrainTile.OctEncodedVertexNormals['xy'])
y = unpackEntry(f, TerrainTile.OctEncodedVertexNormals['xy'])
self.vLight.append(octDecode(x, y))
Expand Down Expand Up @@ -554,12 +550,8 @@ def _writeTo(self, f):
# Unsigned char size len is 1
f.write(packEntry(meta['extensionLength'], 2 * vertexCount))

# Add 2 bytes of padding
f.write(packEntry('B', 1))
f.write(packEntry('B', 1))

metaV = TerrainTile.OctEncodedVertexNormals
for i in xrange(0, vertexCount - 1):
for i in xrange(0, vertexCount):
x, y = octEncode(self.vLight[i])
f.write(packEntry(metaV['xy'], x))
f.write(packEntry(metaV['xy'], y))
Expand Down
4 changes: 2 additions & 2 deletions quantized_mesh_tile/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ def _loadGeometry(self, geometrySpec):
if type(geometrySpec) is str and geometrySpec.startswith('POLYGON Z'):
try:
geometry = load_wkt(geometrySpec)
except:
except Exception:
geometry = None
else:
try:
geometry = load_wkb(geometrySpec)
except:
except Exception:
geometry = None

if geometry is None:
Expand Down
18 changes: 2 additions & 16 deletions quantized_mesh_tile/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,12 @@ def computeNormals(vertices, faces):
v0 = vertices[face[0]]
v1 = vertices[face[1]]
v2 = vertices[face[2]]
ctrd = centroid(v0, v1, v2)

v1A = c3d.subtract(v1, v0)
v2A = c3d.subtract(v2, v0)
normalA = np.cross(v1A, v2A)
viewPointA = c3d.add(ctrd, normalA)

normalB = np.cross(v2A, v1A)
viewPointB = c3d.add(ctrd, normalB)
normal = np.cross(c3d.subtract(v1, v0), c3d.subtract(v2, v0))

area = triangleArea(v0, v1)
areasPerFace[i] = area
squaredDistanceA = c3d.magnitudeSquared(viewPointA)
squaredDistanceB = c3d.magnitudeSquared(viewPointB)

# Always take the furthest point
if squaredDistanceA > squaredDistanceB:
normalsPerFace[i] = normalA
else:
normalsPerFace[i] = normalB
normalsPerFace[i] = normal

for i in xrange(0, numFaces):
face = faces[i]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
requires = ['shapely', 'numpy']

setup(name='quantized-mesh-tile',
version='0.4',
version='0.5',
description='Quantized-Mesh format reader and writer',
author=u'Loic Gasser',
author_email='[email protected]',
Expand Down

0 comments on commit 31a0560

Please sign in to comment.