diff --git a/cocos/3d/assets/texture-cube.js b/cocos/3d/assets/texture-cube.js index fafe7d5b1c..0a67f3ad19 100644 --- a/cocos/3d/assets/texture-cube.js +++ b/cocos/3d/assets/texture-cube.js @@ -25,11 +25,13 @@ // @ts-check import Texture2D from '../../assets/CCTexture2D'; import gfx from '../../renderer/gfx'; +import { ccclass } from '../../core/data/class-decorator'; let isComplete = function(elements) { - return elements.reduce((acc, t) => acc = acc && t.complete, false); + return elements.every(cube => cube.every(img => img.complete)); }; +@ccclass('cc.TextureCube') export default class TextureCube extends Texture2D { constructor() { @@ -37,7 +39,7 @@ export default class TextureCube extends Texture2D { this._ctor = gfx.TextureCube; } - handleLoadedTexture () { + handleLoadedTexture() { let image = this._image[0]; if (!image || !image.width || !image.height) return; @@ -45,13 +47,13 @@ export default class TextureCube extends Texture2D { this.width = image.width; this.height = image.height; - this._updateTexture([this._image]); + this._updateTexture(this._imageMipmaps); //dispatch load event to listener. this.loaded = true; this.emit("load"); - this._image.forEach(img => { + this._imageMipmaps.forEach(cube => cube.forEach(img => { if (cc.macro.CLEANUP_IMAGE_CACHE && image instanceof HTMLImageElement) { // wechat game platform will cache image parsed data, // so image will consume much more memory than web, releasing it @@ -59,22 +61,33 @@ export default class TextureCube extends Texture2D { // Release image in loader cache cc.loader.removeItem(img.id); } - }); + })); } - initWithElement (element) { + initWithElement(element) { if (!element) return; - this._image = element; + if (!Array.isArray(element[0])) element = [element]; + + this._image = element[0]; + this._imageMipmaps = element; if (CC_WECHATGAME || CC_QQPLAY || isComplete(element) - || element[0] instanceof HTMLCanvasElement) { + || this._image[0] instanceof HTMLCanvasElement) { this.handleLoadedTexture(); return; } - element.forEach(() => addEventListener('load', () => { - if (isComplete(element)) this.handleLoadedTexture(); - })); - element.forEach(() => addEventListener('error', err => { - cc.warnID(3119, err.message); - })); + element.forEach(cube => cube.forEach(img => + img.addEventListener('load', () => + { if (isComplete(element)) this.handleLoadedTexture(); }) + )); + element.forEach(cube => cube.forEach(img => + img.addEventListener('error', err => cc.warnID(3119, err.message)) + )); + } + + destroy() { + super.destroy(); + this._imageMipmaps = null; } } + +cc.TextureCube = TextureCube; diff --git a/cocos/3d/framework/index.js b/cocos/3d/framework/index.js index 19e21f98ae..e081211c88 100644 --- a/cocos/3d/framework/index.js +++ b/cocos/3d/framework/index.js @@ -29,11 +29,11 @@ import AnimationComponent from './animation-component'; import LightComponent from './light-component'; import ModelComponent from './model-component'; import SkinnedModelComponent from './skinning-model-component'; -import SkyBoxComponent from './skybox-component'; +import SkyboxComponent from './skybox-component'; cc.CameraComponent = CameraComponent; cc.AnimationComponent = AnimationComponent; cc.LightComponent = LightComponent; cc.ModelComponent = ModelComponent; cc.SkinnedModelComponent = SkinnedModelComponent; -cc.SkyBoxComponent = SkyBoxComponent; +cc.SkyboxComponent = SkyboxComponent; diff --git a/cocos/3d/framework/light-component.js b/cocos/3d/framework/light-component.js index 688717e007..9e6028f271 100644 --- a/cocos/3d/framework/light-component.js +++ b/cocos/3d/framework/light-component.js @@ -418,6 +418,19 @@ export default class LightComponent extends RenderSystemActor { onLoad() { this._light.setNode(this.node); + this.type = this._type; + this.color = this._color; + this.intensity = this._intensity; + this.range = this._range; + this.spotAngle = this._spotAngle; + this.spotExp = this._spotExp; + this.shadowType = this._shadowType; + this.shadowResolution = this._shadowResolution; + this.shadowDarkness = this._shadowDarkness; + this.shadowMaxDepth = this._shadowMaxDepth; + this.shadowDepthScale = this._shadowDepthScale; + this.shadowFrustumSize = this._shadowFrustumSize; + this.shadowBias = this._shadowBias; } onEnable() { diff --git a/cocos/3d/framework/skybox-component.js b/cocos/3d/framework/skybox-component.js index 175157858f..428e0dd7e9 100644 --- a/cocos/3d/framework/skybox-component.js +++ b/cocos/3d/framework/skybox-component.js @@ -23,7 +23,6 @@ THE SOFTWARE. ****************************************************************************/ // @ts-check -import RenderSystemActor from '../framework/renderSystemActor'; import renderer from '../../renderer/index'; import { box } from '../primitive/index'; import Material from '../assets/material'; @@ -69,16 +68,16 @@ export default class SkyboxComponent extends RenderableComponent { onLoad() { this._model.setNode(this.node); - let ia = renderer.createIA(cc.game._renderContext, box(2, 2, 2, { + let ia = renderer.createIA(cc.game._renderContext, box(2, 2, 2, { widthSegments: 1, heightSegments: 1, lengthSegments: 1, })); this._model.setInputAssembler(ia); - if (this._material === null) { + if (!this._material) { this._material = new Material(); - // this._material.effectAsset = this._app.assets.get('builtin-effect-skybox'); + this._material.effectAsset = cc.game._builtins['builtin-effect-skybox']; } this._updateMaterialParams(); @@ -87,7 +86,7 @@ export default class SkyboxComponent extends RenderableComponent { onEnable() { if (this.node != null) { - let cameraComponent = this.getComponent('Camera'); + let cameraComponent = this.getComponent(cc.CameraComponent); if (cameraComponent != null && (cameraComponent._clearFlags & renderer.CLEAR_SKYBOX)) { this._attachedCamera = cameraComponent._camera; this._attachedCamera._clearModel = this._model; @@ -102,17 +101,17 @@ export default class SkyboxComponent extends RenderableComponent { } } - _onMaterialModified(idx, mat) { - this._updateMaterialParams(mat); - this._model.setEffect(mat.effect); - } + _onMaterialModified(idx, mat) { + this._updateMaterialParams(mat); + this._model.setEffect(mat.effect); + } - _updateMaterialParams(mat) { - if (mat === null || mat === undefined) { + _updateMaterialParams() { + if (this._material === null || this._material === undefined) { return; } if (this._cubeMap !== null && this._cubeMap !== undefined) { - mat.setProperty('cubeMap', this._cubeMap); + this._material.setProperty('cubeMap', this._cubeMap); } } } diff --git a/cocos/assets/index.js b/cocos/assets/index.js index 59eaf319d1..a5dcdb1f37 100644 --- a/cocos/assets/index.js +++ b/cocos/assets/index.js @@ -26,15 +26,12 @@ export {default as RawAsset} from './CCRawAsset'; export {default as Asset} from './CCAsset'; -export {default as Font} from './CCFont'; export {default as Prefab} from './CCPrefab'; export * from './CCScripts'; export {default as SceneAsset} from './CCSceneAsset'; export {default as SpriteFrame} from './CCSpriteFrame'; export {default as Texture2D} from './CCTexture2D'; -export {default as TTFFont} from './CCTTFFont'; export {default as SpriteAtlas} from './CCSpriteAtlas'; -export {default as BitmapFont} from './CCBitmapFont'; export {default as TextAsset} from './CCTextAsset'; export {default as JsonAsset} from './CCJsonAsset'; export {default as GLTFAsset} from './CCGLTFAsset'; diff --git a/cocos/core/CCGame.js b/cocos/core/CCGame.js index 1cfbe4363d..9322cb7248 100644 --- a/cocos/core/CCGame.js +++ b/cocos/core/CCGame.js @@ -366,7 +366,7 @@ var game = { // Init engine this._initEngine(); // Log engine version - console.log('Cocos Creator v' + cc.ENGINE_VERSION); + console.log('Cocos3D v' + cc.ENGINE_VERSION); this._setAnimFrame(); this._runMainLoop(); diff --git a/cocos/core/CCScheduler.js b/cocos/core/CCScheduler.js index fd7543cc2c..4b76e4be79 100644 --- a/cocos/core/CCScheduler.js +++ b/cocos/core/CCScheduler.js @@ -284,7 +284,7 @@ CallbackTimer.put = function (timer) { * * @class Scheduler */ -export default class Scheduler { +class Scheduler { constructor () { this._timeScale = 1.0; this._updatesNegList = []; // list of priority < 0 @@ -1104,4 +1104,7 @@ Scheduler.PRIORITY_SYSTEM = 1 << 31; * @type {Number} * @static */ -Scheduler.PRIORITY_NON_SYSTEM = Scheduler.PRIORITY_SYSTEM + 1; \ No newline at end of file +Scheduler.PRIORITY_NON_SYSTEM = Scheduler.PRIORITY_SYSTEM + 1; + +cc.Scheduler = Scheduler; +export default Scheduler; diff --git a/cocos/core/platform/event-manager/CCEventManager.js b/cocos/core/platform/event-manager/CCEventManager.js index 74502598bb..4e0bcdee6a 100644 --- a/cocos/core/platform/event-manager/CCEventManager.js +++ b/cocos/core/platform/event-manager/CCEventManager.js @@ -1083,9 +1083,6 @@ var eventManager = { } } -js.get(cc, 'eventManager', function () { - cc.warnID(1405, 'cc.eventManager', 'cc.EventTarget or cc.systemEvent'); - return eventManager; -}); +cc.eventManager = eventManager; export default eventManager \ No newline at end of file diff --git a/cocos/core/platform/event-manager/CCInputManager.js b/cocos/core/platform/event-manager/CCInputManager.js index 9ca5ab3f0d..af56dcff40 100644 --- a/cocos/core/platform/event-manager/CCInputManager.js +++ b/cocos/core/platform/event-manager/CCInputManager.js @@ -494,6 +494,10 @@ let inputManager = { if (!selfPointer._mousePressed) { mouseEvent.setButton(null); } + if (event.movementX !== undefined && event.movementY !== undefined) { + mouseEvent.movementX = event.movementX; + mouseEvent.movementY = event.movementY; + } }], ["mousewheel", EventMouse.SCROLL, function (event, mouseEvent) { mouseEvent.setScrollData(0, event.wheelDelta); diff --git a/cocos/renderer/shaders/templates/pbr.frag b/cocos/renderer/shaders/templates/pbr.frag index b200bea47f..d9bc8d3f75 100644 --- a/cocos/renderer/shaders/templates/pbr.frag +++ b/cocos/renderer/shaders/templates/pbr.frag @@ -268,7 +268,7 @@ void main() { vec3 specularEnv = textureCube(specularEnvTexture, R).rgb; #endif #endif - vec2 brdf = texture2D(brdfLUT, vec2(max(dot(N, V), 0.0), roughness)).rg; + vec2 brdf = texture2D(brdfLUT, vec2(max(dot(N, V), 0.0), 1.0 - roughness)).rg; vec3 specular = specularEnv * (F * brdf.x + brdf.y); ambient = (kD * diffuse + specular) * ao; #endif diff --git a/cocos/scene-graph/node.js b/cocos/scene-graph/node.js index 17767a9190..3712fb224e 100644 --- a/cocos/scene-graph/node.js +++ b/cocos/scene-graph/node.js @@ -40,22 +40,27 @@ class Node extends BaseNode { EventTarget.call(this); } - onRestore() { - super.onRestore(); - this.invalidateChildren(); - } // =============================== // hierarchy // =============================== /** - * invalidate all children after parent changed + * invalidate all children after relevant events */ + onRestore() { + super.onRestore(); + this.invalidateChildren(); + } + _onSetParent(/*oldParent*/) { this.invalidateChildren(); } + _onPostActivated() { + this.invalidateChildren(); + } + // =============================== // transform helper // ===============================