mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
node, light, texture-cube (#3460)
* node, light, texture-cube * skybox * flipY issue * mouse data when locked * fix init info
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
Scheduler.PRIORITY_NON_SYSTEM = Scheduler.PRIORITY_SYSTEM + 1;
|
||||
|
||||
cc.Scheduler = Scheduler;
|
||||
export default Scheduler;
|
||||
|
||||
@@ -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
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
// ===============================
|
||||
|
||||
Reference in New Issue
Block a user