Skip to content

Commit

Permalink
Merge pull request #5038 from AnalyticalGraphicsInc/hierarchy-no-parents
Browse files Browse the repository at this point in the history
3D Tiles - Added support for batch table hierarchy without parents
  • Loading branch information
pjcozzi committed Mar 8, 2017
2 parents dad1fd8 + 72872de commit dc06f02
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 19 deletions.
26 changes: 20 additions & 6 deletions Source/Scene/Cesium3DTileBatchTable.js
Expand Up @@ -167,11 +167,13 @@ define([
}
}

if (defined(parentIds.byteOffset)) {
parentIds.componentType = defaultValue(parentIds.componentType, 'UNSIGNED_SHORT');
parentIds.type = 'SCALAR';
binaryAccessor = getBinaryAccessor(parentIds);
parentIds = binaryAccessor.createArrayBufferView(binary.buffer, binary.byteOffset + parentIds.byteOffset, parentIdsLength);
if (defined(parentIds)) {
if (defined(parentIds.byteOffset)) {
parentIds.componentType = defaultValue(parentIds.componentType, 'UNSIGNED_SHORT');
parentIds.type = 'SCALAR';
binaryAccessor = getBinaryAccessor(parentIds);
parentIds = binaryAccessor.createArrayBufferView(binary.buffer, binary.byteOffset + parentIds.byteOffset, parentIdsLength);
}
}

var classesLength = classes.length;
Expand Down Expand Up @@ -227,6 +229,11 @@ define([
var classIds = hierarchy.classIds;
var instancesLength = classIds.length;

if (!defined(parentIds)) {
// No need to validate if there are no parents
return;
}

if (instanceIndex >= instancesLength) {
throw new DeveloperError('Parent index ' + instanceIndex + ' exceeds the total number of instances: ' + instancesLength);
}
Expand Down Expand Up @@ -555,11 +562,18 @@ define([
}
}

function traverseHierarchyNoParents(hierarchy, instanceIndex, endConditionCallback) {
return endConditionCallback(hierarchy, instanceIndex);
}

function traverseHierarchy(hierarchy, instanceIndex, endConditionCallback) {
// Traverse over the hierarchy and process each instance with the endConditionCallback.
// When the endConditionCallback returns a value, the traversal stops and that value is returned.
var parentCounts = hierarchy.parentCounts;
if (defined(parentCounts)) {
var parentIds = hierarchy.parentIds;
if (!defined(parentIds)) {
return traverseHierarchyNoParents(hierarchy, instanceIndex, endConditionCallback);
} else if (defined(parentCounts)) {
return traverseHierarchyMultipleParents(hierarchy, instanceIndex, endConditionCallback);
}
return traverseHierarchySingleParent(hierarchy, instanceIndex, endConditionCallback);
Expand Down
Binary file modified Specs/Data/Cesium3DTiles/Hierarchy/BatchTableHierarchy/tile.b3dm
Binary file not shown.
Expand Up @@ -27,16 +27,16 @@
"box": [
0,
0,
25,
100,
10,
50,
0,
0,
0,
100,
50,
0,
0,
0,
50
10
]
},
"geometricError": 0,
Expand Down
Binary file not shown.
Expand Up @@ -27,16 +27,16 @@
"box": [
0,
0,
25,
100,
10,
50,
0,
0,
0,
100,
50,
0,
0,
0,
50
10
]
},
"geometricError": 0,
Expand Down
Binary file not shown.
Expand Up @@ -27,16 +27,16 @@
"box": [
0,
0,
25,
100,
10,
50,
0,
0,
0,
100,
50,
0,
0,
0,
50
10
]
},
"geometricError": 0,
Expand Down
Binary file not shown.
@@ -0,0 +1,47 @@
{
"asset": {
"version": "0.0"
},
"geometricError": 70,
"root": {
"transform": [
0.9686356343768792,
0.24848542777253735,
0,
0,
-0.15986460744966327,
0.623177611820219,
0.765567091384559,
0,
0.19023226619126932,
-0.7415555652213445,
0.6433560667227647,
0,
1215011.9317263428,
-4736309.3434217675,
4081602.0044800863,
1
],
"refine": "add",
"boundingVolume": {
"box": [
0,
0,
10,
50,
0,
0,
0,
50,
0,
0,
0,
10
]
},
"geometricError": 0,
"content": {
"url": "tile.b3dm"
}
}
}
76 changes: 75 additions & 1 deletion Specs/Scene/Cesium3DTileBatchTableSpec.js
Expand Up @@ -41,6 +41,7 @@ defineSuite([
var batchTableHierarchyUrl = './Data/Cesium3DTiles/Hierarchy/BatchTableHierarchy/';
var batchTableHierarchyBinaryUrl = './Data/Cesium3DTiles/Hierarchy/BatchTableHierarchyBinary/';
var batchTableHierarchyMultipleParentsUrl = './Data/Cesium3DTiles/Hierarchy/BatchTableHierarchyMultipleParents/';
var batchTableHierarchyNoParentsUrl = './Data/Cesium3DTiles/Hierarchy/BatchTableHierarchyNoParents/';

var result = new Color();

Expand Down Expand Up @@ -752,6 +753,38 @@ defineSuite([
});
}

function checkHierarchyStylingNoParents(tileset) {
// Check that a feature is colored from a generic batch table property.
tileset.style = new Cesium3DTileStyle({color : "${height} === 6.0 ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});

// Check that a feature is colored from a class property.
tileset.style = new Cesium3DTileStyle({color : "${roof_name} === 'roof2' ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});

// Check isExactClass
tileset.style = new Cesium3DTileStyle({color : "isExactClass('roof') ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});

// Check isClass
tileset.style = new Cesium3DTileStyle({color : "isClass('roof') ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});

// Check getExactClassName
tileset.style = new Cesium3DTileStyle({color : "getExactClassName() === 'roof' ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});
}

function checkHierarchyProperties(tileset, multipleParents) {
// Check isExactClass, isClass, and getExactClassName in Cesium3DTileFeature
var content = tileset._root.content;
Expand Down Expand Up @@ -814,25 +847,66 @@ defineSuite([
batchTable._batchTableHierarchy = hierarchy;
}

function checkHierarchyPropertiesNoParents(tileset) {
// Check isExactClass, isClass, and getExactClassName in Cesium3DTileFeature
var content = tileset._root.content;
var doorFeature = content.getFeature(4);
expect(doorFeature.isExactClass('door')).toBe(true);
expect(doorFeature.isExactClass('doorknob')).toBe(false);
expect(doorFeature.isClass('door')).toBe(true);
expect(doorFeature.isClass('doorknob')).toBe(false);
expect(doorFeature.getExactClassName()).toBe('door');
expect(doorFeature.hasProperty('door_name')).toBe(true);
expect(doorFeature.hasProperty('height')).toBe(true);

// Includes batch table properties and hierarchy properties from all inherited classes
var expectedPropertyNames = ['height', 'area', 'door_mass', 'door_width', 'door_name'];

var propertyNames = doorFeature.getPropertyNames();
expect(expectedPropertyNames.sort()).toEqual(propertyNames.sort());

expect(doorFeature.getProperty('height')).toBe(5.0); // Gets generic property
expect(doorFeature.getProperty('door_name')).toBe('door0'); // Gets class property

// Sets generic property
doorFeature.setProperty('height', 10.0);
expect(doorFeature.getProperty('height')).toBe(10.0);

// Sets class property
doorFeature.setProperty('door_name', 'new_door');
expect(doorFeature.getProperty('door_name')).toBe('new_door');
}

function checkBatchTableHierarchy(url, multipleParents) {
return Cesium3DTilesTester.loadTileset(scene, url).then(function(tileset) {
checkHierarchyStyling(tileset);
checkHierarchyProperties(tileset, multipleParents);
});
}

function checkBatchTableHierarchyNoParents(url) {
return Cesium3DTilesTester.loadTileset(scene, url).then(function(tileset) {
checkHierarchyStylingNoParents(tileset);
checkHierarchyPropertiesNoParents(tileset);
});
}

it('renders tileset with batch table hierarchy', function() {
return checkBatchTableHierarchy(batchTableHierarchyUrl, false);
});

it('renders tileset with batch table hierarchy using binary properties', function() {
return checkBatchTableHierarchy(batchTableHierarchyBinaryUrl, false);
return checkBatchTableHierarchy(batchTableHierarchyBinaryUrl, true);
});

it('renders tileset with batch table hierarchy with multiple parent classes', function() {
return checkBatchTableHierarchy(batchTableHierarchyMultipleParentsUrl, true);
});

it('renders tileset with batch table hierarchy with no parents', function() {
return checkBatchTableHierarchyNoParents(batchTableHierarchyNoParentsUrl);
});

it('validates hierarchy with multiple parents', function() {
// building0
// / \
Expand Down

0 comments on commit dc06f02

Please sign in to comment.