Skip to content

Commit

Permalink
Update: Update Box3D with new material default (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiiBond authored May 23, 2017
1 parent 2cacedd commit 97fe7a1
Show file tree
Hide file tree
Showing 37 changed files with 11,307 additions and 269 deletions.
2 changes: 1 addition & 1 deletion build/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const webpackConfig = require('./webpack.karma.config');

const DOC_STATIC_ASSETS_VERSION = '0.121.1';
const MEDIA_STATIC_ASSETS_VERSION = '0.122.0';
const MODEL3D_STATIC_ASSETS_VERSION = '0.115.0';
const MODEL3D_STATIC_ASSETS_VERSION = '0.125.0';
const SWF_STATIC_ASSETS_VERSION = '0.112.0';
const TEXT_STATIC_ASSETS_VERSION = '0.114.0';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const X_REP_HINT_VIDEO_MP4 = '[mp4]';
// whenever a file in that third party directory is updated
export const DOC_STATIC_ASSETS_VERSION = '0.121.1';
export const MEDIA_STATIC_ASSETS_VERSION = '0.122.0';
export const MODEL3D_STATIC_ASSETS_VERSION = '0.115.0';
export const MODEL3D_STATIC_ASSETS_VERSION = '0.125.0';
export const SWF_STATIC_ASSETS_VERSION = '0.112.0';
export const TEXT_STATIC_ASSETS_VERSION = '0.114.0';

Expand Down
4 changes: 2 additions & 2 deletions src/lib/viewers/box3d/image360/Image360Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ class Image360Renderer extends Box3DRenderer {
this.textureAsset = this.box3d.createTexture2d();
this.textureAsset.setProperties({
imageId: this.imageAsset.id,
uMapping: 'clamp',
vMapping: 'clamp'
wrapModeV: 'clampToEdge',
wrapModeU: 'clampToEdge'
});
return new Promise((resolve) => {
this.textureAsset.load(() => {
Expand Down
28 changes: 3 additions & 25 deletions src/lib/viewers/box3d/model3d/Model3DRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,36 +161,11 @@ class Model3DRenderer extends Box3DRenderer {
return;
}

this.optimizeMaterials();
this.createPrefabInstances();
this.addHelpersToScene();
scene.when('load', () => this.onSceneLoad());
}

/**
* Go through all materials and look for ways to turn off features to optimize perfomance.
*
* @private
* @return {void}
*/
optimizeMaterials() {
this.box3d.getAssetsByType(Box3D.MaterialAsset).forEach((mat) => {
if (mat.getProperty('roughness') <= 0.01 && !mat.getProperty('glossMap')) {
mat.setProperty('envMapGlossVariance', false);
}

if (mat.getProperty('roughness') >= 0.99) {
mat.setProperty('envMapGlossVariance', false);
mat.enableFeature('specular', false);
}

// Normal maps don't work nicely on mobile right now.
if (Browser.isMobile()) {
mat.enableFeature('normals', false);
}
});
}

/**
* Create instances of prefabs and add them to the scene.
*
Expand Down Expand Up @@ -325,6 +300,9 @@ class Model3DRenderer extends Box3DRenderer {
}));

Promise.all(assetPromises).then(() => {
if (!this.box3d) {
return;
}
this.startOptimizer();

if (animations.length > 0) {
Expand Down
208 changes: 28 additions & 180 deletions src/lib/viewers/box3d/model3d/SceneEntities.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,39 @@ function sceneEntities(prefix) {
// The scene contains the lights and camera
children: [
'CAMERA_ID',
'AMBIENT_LIGHT_ID'
],
components: [
{
name: 'Light Environment',
attributes: {
irradianceMap: 'HDR_ENV_MAP_CUBE_2',
radianceMapHalfGloss: 'HDR_ENV_MAP_CUBE_1',
radianceMap: 'HDR_ENV_MAP_CUBE_0'
},
scriptId: 'light_environment'
}
'AMBIENT_LIGHT_ID',
'DIRECTIONAL_LIGHT_1_ID',
'DIRECTIONAL_LIGHT_2_ID'
]
}, {
id: 'AMBIENT_LIGHT_ID',
type: 'light',
parentId: 'SCENE_ID',
properties: {
lightType: 'ambient',
color: { r: 0.0, g: 0.0, b: 0.0 }
color: { r: 1, g: 1, b: 1 }
}
}, {
id: 'DIRECTIONAL_LIGHT_1_ID',
type: 'light',
parentId: 'SCENE_ID',
properties: {
lightType: 'directional',
name: 'Key Light',
position: { x: -3, y: 3, z: 2 },
color: { r: 1, g: 1, b: 0.85 },
intensity: 2
}
}, {
id: 'DIRECTIONAL_LIGHT_2_ID',
type: 'light',
parentId: 'SCENE_ID',
properties: {
lightType: 'directional',
name: 'Back Light',
position: { x: 3, y: 2, z: -2 },
color: { r: 0.75, g: 0.75, b: 1 },
intensity: 1.5
}
}, {
id: 'APP_ASSET_ID',
Expand Down Expand Up @@ -164,8 +177,8 @@ function sceneEntities(prefix) {
properties: {
name: 'Mat Cap Texture',
imageId: 'MAT_CAP_IMG',
uMapping: 'clamp',
vMapping: 'clamp'
wrapModeU: 'clampToEdge',
wrapModeV: 'clampToEdge'
}
}, {
id: 'MAT_CAP_IMG',
Expand All @@ -185,171 +198,6 @@ function sceneEntities(prefix) {
height: 256,
compression: 'zip'
}]
}, {
id: 'HDR_ENV_IMG_0',
type: 'image',
properties: {
name: 'HDR Env Image 0',
width: 1024,
height: 512,
stream: false,
encoding: 'linear'
},
representations: [{
src: `${prefix}third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/HDR_Env0.png`,
isExternal: true,
contentType: 'image/png',
contentEncoding: 'identity',
width: 1024,
height: 512,
compression: 'zip',
channels: ['red', 'green', 'blue', 'exponent']
}]
}, {
id: 'HDR_ENV_IMG_1',
type: 'image',
properties: {
name: 'HDR Env Image 1',
width: 256,
height: 128,
stream: false,
encoding: 'linear'
},
representations: [{
src: `${prefix}third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/HDR_Env1.png`,
isExternal: true,
contentType: 'image/png',
contentEncoding: 'identity',
width: 256,
height: 128,
compression: 'zip',
channels: ['red', 'green', 'blue', 'exponent']
}]
}, {
id: 'HDR_ENV_IMG_2',
type: 'image',
properties: {
name: 'HDR Env Image 2',
width: 64,
height: 32,
stream: false,
encoding: 'linear'
},
representations: [{
src: `${prefix}third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/HDR_Env2.png`,
isExternal: true,
contentType: 'image/png',
contentEncoding: 'identity',
width: 64,
height: 32,
compression: 'zip',
channels: ['red', 'green', 'blue', 'exponent']
}]
}, {
id: 'HDR_ENV_MAP_0',
type: 'texture2D',
properties: {
imageId: 'HDR_ENV_IMG_0',
name: 'HDR Env Map 0',
type: Browser.isAndroid() ? 'uByte' : 'halfFloat',
minFilter: 'linear',
magFilter: 'linear',
vMapping: 'clamp',
generateMipmaps: false
}
}, {
id: 'HDR_ENV_MAP_1',
type: 'texture2D',
properties: {
imageId: 'HDR_ENV_IMG_1',
name: 'HDR Env Map 1',
type: Browser.isAndroid() ? 'uByte' : 'halfFloat',
minFilter: 'linear',
magFilter: 'linear',
vMapping: 'clamp',
generateMipmaps: false
}
}, {
id: 'HDR_ENV_MAP_2',
type: 'texture2D',
properties: {
imageId: 'HDR_ENV_IMG_2',
name: 'HDR Env Map 2',
type: Browser.isAndroid() ? 'uByte' : 'halfFloat',
minFilter: 'linear',
magFilter: 'linear',
vMapping: 'clamp',
generateMipmaps: false
}
}, {
id: 'HDR_ENV_MAP_CUBE_0',
type: 'renderTextureCube',
properties: {
name: 'HDR Cube Env Map 0',
type: Browser.isAndroid() ? 'uByte' : 'halfFloat',
width: 512,
height: 512,
generateMipmaps: true,
vMapping: 'clamp',
uMapping: 'clamp',
encoding: 'linear'
},
components: [
{
name: 'Convert Panorama To CubeMap',
scriptId: 'panorama_to_cube_map',
enabled: true,
attributes: {
inputTexture: 'HDR_ENV_MAP_0'
}
}
]
}, {
id: 'HDR_ENV_MAP_CUBE_1',
type: 'renderTextureCube',
properties: {
name: 'HDR Cube Env Map 1',
type: Browser.isAndroid() ? 'uByte' : 'halfFloat',
width: 256,
height: 256,
generateMipmaps: true,
vMapping: 'clamp',
uMapping: 'clamp',
encoding: 'linear'
},
components: [
{
name: 'Convert Panorama To CubeMap',
scriptId: 'panorama_to_cube_map',
enabled: true,
attributes: {
inputTexture: 'HDR_ENV_MAP_1'
}
}
]
}, {
id: 'HDR_ENV_MAP_CUBE_2',
type: 'renderTextureCube',
properties: {
name: 'HDR Cube Env Map 2',
type: Browser.isAndroid() ? 'uByte' : 'halfFloat',
width: 128,
height: 128,
generateMipmaps: true,
vMapping: 'clamp',
uMapping: 'clamp',
encoding: 'linear'
},
components: [
{
name: 'Convert Panorama To CubeMap',
scriptId: 'panorama_to_cube_map',
enabled: true,
attributes: {
inputTexture: 'HDR_ENV_MAP_2'
}
}
]
}];
}

Expand Down
56 changes: 0 additions & 56 deletions src/lib/viewers/box3d/model3d/__tests__/Model3DRenderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,10 @@ describe('lib/viewers/box3d/model3d/Model3DRenderer', () => {
});

it('should do nothing if no scene instance is present', () => {
renderMock.expects('optimizeMaterials').never();
renderMock.expects('getScene').returns(undefined);
renderer.setupScene();
});

it('should invoke optimizeMaterials()', () => {
sandbox.stub(renderer, 'getScene').returns(scene);
renderMock.expects('optimizeMaterials').once();
renderer.setupScene([]);
});

it('should invoke createPrefabInstances() to add the model to the scene', () => {
sandbox.stub(renderer, 'getScene').returns(scene);
renderMock.expects('createPrefabInstances').once();
Expand Down Expand Up @@ -243,55 +236,6 @@ describe('lib/viewers/box3d/model3d/Model3DRenderer', () => {
});
});

describe('optimizeMaterials()', () => {
it('should invoke box3d.getAssetsByType() to gather all materials registered with the runtime', () => {
sandbox.mock(renderer.box3d).expects('getAssetsByType').returns([]);
renderer.optimizeMaterials();
});

it('should turn off environment map gloss variance feature if the material roughness is too low AND there is no glossMap', () => {
const mat = {
enableFeature: sandbox.stub(),
getProperty: sandbox.stub(),
setProperty: sandbox.stub()
};
sandbox.mock(renderer.box3d).expects('getAssetsByType').returns([mat]);
mat.getProperty.withArgs('roughness').returns(0);
mat.getProperty.withArgs('glossMap').returns(undefined);

renderer.optimizeMaterials();

expect(mat.setProperty).to.be.calledWith('envMapGlossVariance', false);
});

it('should turn off environment map gloss variance feature and specular lighting feature if roughness is too high', () => {
const mat = {
enableFeature: sandbox.stub(),
getProperty: sandbox.stub(),
setProperty: sandbox.stub()
};
sandbox.mock(renderer.box3d).expects('getAssetsByType').returns([mat]);
mat.getProperty.withArgs('roughness').returns(1);

renderer.optimizeMaterials();

expect(mat.setProperty).to.be.calledWith('envMapGlossVariance', false);
expect(mat.enableFeature).to.be.calledWith('specular', false);
});

it('should disable normal maps if on a mobile device', () => {
sandbox.stub(Browser, 'isMobile').returns(true);
const mat = {
enableFeature: sandbox.stub(),
getProperty: sandbox.stub()
};
sandbox.mock(renderer.box3d).expects('getAssetsByType').returns([mat]);
renderer.optimizeMaterials();

expect(mat.enableFeature).to.be.calledWith('normals', false);
});
});

describe('createPrefabInstances()', () => {
let b3dMock;
beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/viewers/box3d/video360/Video360Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const VIDEO_TEXTURE_PROPS = {
imageId: VIDEO_ID,
minFilter: 'linear',
magFilter: 'linear',
uMapping: 'clamp',
vMapping: 'clamp'
wrapModeV: 'clampToEdge',
wrapModeU: 'clampToEdge'
};

class Video360Viewer extends DashViewer {
Expand Down
Loading

0 comments on commit 97fe7a1

Please sign in to comment.