From cf213ebdd723e2181d599954f19764be6f3c9bbc Mon Sep 17 00:00:00 2001 From: Leslie Leigh Date: Mon, 8 Oct 2018 11:52:14 +0800 Subject: [PATCH] changes to run in editor (#3311) * add name to ccclass decorators; temporarily comment out vb/ib buffer creation in gltf-loader;temporarily modification of base-node.js * Open commented vb/ib creation * make gltf-asset itself a variant of json * fix import bugs * import fix * node transform api --- cocos/3d/assets/animation-clip.js | 7 +-- cocos/3d/assets/audio-clip.js | 2 +- cocos/3d/assets/bitmap-font.js | 2 +- cocos/3d/assets/dom-audio-clip.js | 2 +- cocos/3d/assets/font.js | 2 +- cocos/3d/assets/index.js | 3 +- cocos/3d/assets/material.js | 2 +- cocos/3d/assets/mesh.js | 8 ++-- cocos/3d/assets/opentype-font.js | 2 +- cocos/3d/assets/skeleton.js | 2 +- cocos/3d/assets/sprite.js | 2 +- cocos/3d/assets/texture-cube.js | 3 +- cocos/3d/assets/texture-sprite.js | 3 +- cocos/3d/assets/texture.js | 38 ---------------- cocos/3d/assets/utils/gltf-utils.js | 60 +++++++++++-------------- cocos/3d/assets/web-audio-clip.js | 2 +- cocos/3d/assets/wx-game-audio-clip.js | 2 +- cocos/3d/framework/renderSystemActor.js | 2 +- cocos/assets/CCBufferAsset.js | 7 ++- cocos/assets/CCGLTFAsset.js | 24 ++++++---- cocos/assets/index.js | 2 + cocos/load-pipeline/uuid-loader.js | 1 + cocos/scene-graph/base-node.js | 2 +- 23 files changed, 74 insertions(+), 106 deletions(-) delete mode 100644 cocos/3d/assets/texture.js diff --git a/cocos/3d/assets/animation-clip.js b/cocos/3d/assets/animation-clip.js index b68375d083..96f2887c4d 100644 --- a/cocos/3d/assets/animation-clip.js +++ b/cocos/3d/assets/animation-clip.js @@ -64,7 +64,7 @@ function _binaryIndexOf(array, key) { /** * @interface */ -@ccclass +@ccclass('cc.AnimationResource') export class AnimationResource { /** * @@ -74,8 +74,9 @@ export class AnimationResource { } } +cc.AnimationResource = AnimationResource; -@ccclass +@ccclass('cc.AnimationClip') export default class AnimationClip extends Asset { /** * @type {AnimationResource} @@ -89,7 +90,7 @@ export default class AnimationClip extends Asset { set resource(value) { this._resource = value; - this.update(); + this.flush(); } constructor() { diff --git a/cocos/3d/assets/audio-clip.js b/cocos/3d/assets/audio-clip.js index 11d04be712..eb7684cd20 100644 --- a/cocos/3d/assets/audio-clip.js +++ b/cocos/3d/assets/audio-clip.js @@ -67,7 +67,7 @@ export const AudioSourceType = { * The base class for audio clip asset. * @mixes {EventTarget} */ -@ccclass +@ccclass('cc.AudioClip') @mixins(EventTarget) export class AudioClip extends Asset { /** diff --git a/cocos/3d/assets/bitmap-font.js b/cocos/3d/assets/bitmap-font.js index 18f1db66f1..5d7bfda364 100644 --- a/cocos/3d/assets/bitmap-font.js +++ b/cocos/3d/assets/bitmap-font.js @@ -29,7 +29,7 @@ import Font from "./font"; import vec2 from "../../core/vmath/vec2"; import Texture2D from "../../assets/CCTexture2D"; -@ccclass +@ccclass('cc.BitmapFont') export class BitmapFont extends Font { /** * @type {Texture2D} diff --git a/cocos/3d/assets/dom-audio-clip.js b/cocos/3d/assets/dom-audio-clip.js index 3055407bbc..b7e474c02c 100644 --- a/cocos/3d/assets/dom-audio-clip.js +++ b/cocos/3d/assets/dom-audio-clip.js @@ -27,7 +27,7 @@ import { _decorator } from "../../core/data/index"; const { ccclass } = _decorator; import { AudioClip, AudioSourceType, PlayingState } from "./audio-clip"; -@ccclass +@ccclass('cc.DOMAudioClip') export class DOMAudioClip extends AudioClip { /** * @type {number} diff --git a/cocos/3d/assets/font.js b/cocos/3d/assets/font.js index 1a6d526f60..319bacfd94 100644 --- a/cocos/3d/assets/font.js +++ b/cocos/3d/assets/font.js @@ -27,7 +27,7 @@ import { _decorator } from "../../core/data/index"; const {ccclass} = _decorator; import Asset from "../../assets/CCAsset"; -@ccclass +@ccclass('cc.Font') export default class Font extends Asset { /** Font size. * @type {number} diff --git a/cocos/3d/assets/index.js b/cocos/3d/assets/index.js index 73b8ab7d67..2ab8f11573 100644 --- a/cocos/3d/assets/index.js +++ b/cocos/3d/assets/index.js @@ -34,4 +34,5 @@ import "./opentype-font"; import "./skeleton"; import "./sprite"; import "./web-audio-clip"; -import "./wx-game-audio-clip"; \ No newline at end of file +import "./wx-game-audio-clip"; +import "./utils/gltf-utils.js"; \ No newline at end of file diff --git a/cocos/3d/assets/material.js b/cocos/3d/assets/material.js index 54de988a2f..6e10e11d2a 100644 --- a/cocos/3d/assets/material.js +++ b/cocos/3d/assets/material.js @@ -26,7 +26,7 @@ import { _decorator } from "../../core/data/index"; const { ccclass, property } = _decorator; import Asset from "../../assets/CCAsset"; -import Texture from './texture'; +import Texture from '../../assets/CCTexture2D'; import renderer from "../../renderer"; import { vec2, vec3, vec4, color3, color4 } from '../../core/vmath/index'; diff --git a/cocos/3d/assets/mesh.js b/cocos/3d/assets/mesh.js index ec82a24d8c..31d907dff1 100644 --- a/cocos/3d/assets/mesh.js +++ b/cocos/3d/assets/mesh.js @@ -31,7 +31,7 @@ import Asset from "../../assets/CCAsset"; /** * @interface */ -@ccclass +@ccclass('cc.MeshResource') export class MeshResource { /** * @@ -41,8 +41,9 @@ export class MeshResource { } } +cc.MeshResource = MeshResource; -@ccclass +@ccclass('cc.Mesh') export default class Mesh extends Asset { /** * @type {MeshResource} @@ -56,7 +57,7 @@ export default class Mesh extends Asset { set resource(value) { this._resource = value; - this.update(); + this.flush(); } constructor() { @@ -146,5 +147,4 @@ export default class Mesh extends Asset { // } // } } - cc.Mesh = Mesh; \ No newline at end of file diff --git a/cocos/3d/assets/opentype-font.js b/cocos/3d/assets/opentype-font.js index de366dc5fd..c29b7c9e0c 100644 --- a/cocos/3d/assets/opentype-font.js +++ b/cocos/3d/assets/opentype-font.js @@ -30,7 +30,7 @@ import vec2 from "../../core/vmath/vec2"; import ShelfPack from "./utils/shelf-pack"; import Texture2D from "../../assets/CCTexture2D"; -@ccclass +@ccclass('cc.OpentypeFont') export default class OpentypeFont extends Font { /** * opentype.Font diff --git a/cocos/3d/assets/skeleton.js b/cocos/3d/assets/skeleton.js index 7d4e386b10..6129354fe9 100644 --- a/cocos/3d/assets/skeleton.js +++ b/cocos/3d/assets/skeleton.js @@ -30,7 +30,7 @@ import Asset from "../../assets/CCAsset"; import SkeletonInstance from '../framework/skeleton-instance'; import { Node } from "../../scene-graph"; -@ccclass +@ccclass('cc.Skeleton') export default class Skeleton extends Asset { /** * @type {Node} diff --git a/cocos/3d/assets/sprite.js b/cocos/3d/assets/sprite.js index 6e1dbcb2d3..93c544ea7b 100644 --- a/cocos/3d/assets/sprite.js +++ b/cocos/3d/assets/sprite.js @@ -33,7 +33,7 @@ let _s_tmp = vec3.create(0, 0, 0); let _mat4_tmp = mat4.create(); let _textureMatrix = mat4.create(); -@ccclass +@ccclass('cc.Sprite') export default class Sprite extends Asset { constructor() { super(); diff --git a/cocos/3d/assets/texture-cube.js b/cocos/3d/assets/texture-cube.js index 2ce0d0c2d8..911c70bf38 100644 --- a/cocos/3d/assets/texture-cube.js +++ b/cocos/3d/assets/texture-cube.js @@ -25,7 +25,7 @@ // @ts-check import { _decorator } from "../../core/data/index"; const { ccclass } = _decorator; -import Texture from './texture'; +import Texture from '../../assets/CCTexture2D'; import gfx from '../../renderer/gfx'; import { gfxFilters, gfxWraps, gfxTextureFmts } from '../misc/mappings'; @@ -58,7 +58,6 @@ function _updateOpts(out, texture) { out.mipFilter = gfxFilters[texture._mipFilter]; } -@ccclass export class TextureCube extends Texture { constructor(device, width = 2, height = 2, fmt = 'rgba8') { super(device); diff --git a/cocos/3d/assets/texture-sprite.js b/cocos/3d/assets/texture-sprite.js index 900ffa4b4d..7df8b24c4e 100644 --- a/cocos/3d/assets/texture-sprite.js +++ b/cocos/3d/assets/texture-sprite.js @@ -28,7 +28,7 @@ const { ccclass, property } = _decorator; import Texture2D from '../../assets/CCTexture2D'; import Sprite from "./sprite"; -@ccclass +@ccclass('cc.TextureSprite') export default class TextureSprite extends Texture2D { /** * @type {Sprite[]} @@ -47,3 +47,4 @@ export default class TextureSprite extends Texture2D { return super.destroy(); } } +cc.TextureSprite = TextureSprite; \ No newline at end of file diff --git a/cocos/3d/assets/texture.js b/cocos/3d/assets/texture.js deleted file mode 100644 index cd016035bf..0000000000 --- a/cocos/3d/assets/texture.js +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ -// @ts-check -import { _decorator } from "../../core/data/index"; -const { ccclass } = _decorator; -import Asset from "../../assets/CCAsset"; - -@ccclass -export default class Texture extends Asset { - constructor(device) { - super(); - - this._device = device; - this._texture = null; // gfx.Texture2D | gfx.TextureCube - } -} diff --git a/cocos/3d/assets/utils/gltf-utils.js b/cocos/3d/assets/utils/gltf-utils.js index 39a7712375..a3ee9053d6 100644 --- a/cocos/3d/assets/utils/gltf-utils.js +++ b/cocos/3d/assets/utils/gltf-utils.js @@ -15,13 +15,13 @@ import Skeleton from "../skeleton"; * @typedef {import("../../../../types/glTF/glTF").Node} GLTFNode */ -@ccclass +@ccclass('cc.GltfMeshResource') export class GltfMeshResource extends MeshResource { /** * @type {GLTFAsset} */ @property(GLTFAsset) - gltfAsset; + gltfAsset = null; /** * @type {number} @@ -43,7 +43,7 @@ export class GltfMeshResource extends MeshResource { } /** @type GLTFFormat */ - const gltf = this.gltfAsset.description.json; + const gltf = this.gltfAsset.description; if (this.gltfIndex >= gltf.meshes.length) { return; } @@ -59,8 +59,6 @@ export class GltfMeshResource extends MeshResource { let iVertexBufferView = -1; let vertexCount = -1; - let expectedOffset = 0; - let positionType = gfx.ATTR_TYPE_FLOAT32; const vfmt = []; for (const gltfAttribName in primitive.attributes) { const gfxAttribName = _gltfAttribMap[gltfAttribName]; @@ -84,29 +82,17 @@ export class GltfMeshResource extends MeshResource { vertexCount = gltfAccessor.count; } - if (gltfAccessor.byteOffset !== expectedOffset) { - console.error(`Attributes of one GlTf primitive should be interleaved.`); - return; - } - expectedOffset += gltfAccessor.byteOffset; - if (gltfAttribName === "POSITION") { mesh._minPos = vec3.create(gltfAccessor.min[0], gltfAccessor.min[1], gltfAccessor.min[2]); mesh._maxPos = vec3.create(gltfAccessor.max[0], gltfAccessor.max[1], gltfAccessor.max[2]); - positionType = gltfAccessor.componentType; } vfmt.push({ name: gfxAttribName, type: gltfAccessor.componentType, num: _type2size[gltfAccessor.type] }); } const vertexBufferView = gltf.bufferViews[iVertexBufferView]; - if (expectedOffset !== vertexBufferView.byteStride) { - console.warn(`There is extra data resides in GlTf primitive's buffer.`); - return; - } - - const vbData = new DataView(this.gltfAsset.buffers[vertexBufferView.buffer].data, vertexBufferView.byteOffset, vertexBufferView.byteLength); + const vbData = new Uint8Array(this.gltfAsset.buffers[vertexBufferView.buffer].data, vertexBufferView.byteOffset, vertexBufferView.byteLength); const vb = new gfx.VertexBuffer( - app.device, + cc.game._renderContext, new gfx.VertexFormat(vfmt), gfx.USAGE_STATIC, vbData, @@ -120,7 +106,7 @@ export class GltfMeshResource extends MeshResource { let ibData = new DataView(this.gltfAsset.buffers[ibView.buffer].data, ibView.byteOffset, ibView.byteLength); ib = new gfx.IndexBuffer( - app.device, + cc.game._renderContext, ibAcc.componentType, gfx.USAGE_STATIC, ibData, @@ -146,7 +132,7 @@ export class GltfMeshResource extends MeshResource { */ createSkinning(index) { /** @type GLTFFormat */ - const gltf = this.gltfAsset.description.json; + const gltf = this.gltfAsset.description; if (index >= gltf.skins.length) { return null; } @@ -174,14 +160,15 @@ export class GltfMeshResource extends MeshResource { }; } } +cc.GltfMeshResource = GltfMeshResource; -@ccclass +@ccclass('cc.GltfAnimationResource') export class GltfAnimationResource extends AnimationResource { /** * @type {GLTFAsset} */ @property(GLTFAsset) - gltfAsset; + gltfAsset = null; /** * @type {number} @@ -199,7 +186,7 @@ export class GltfAnimationResource extends AnimationResource { } /** @type GLTFFormat */ - const gltf = this.gltfAsset.description.json; + const gltf = this.gltfAsset.description; if (this.gltfIndex >= gltf.animations.length) { return; } @@ -216,7 +203,7 @@ export class GltfAnimationResource extends AnimationResource { // When node isn't defined, channel should be ignored. continue; } - let gltfSampler = gltf.samplers[gltfChannel.sampler]; + let gltfSampler = gltfAnimation.samplers[gltfChannel.sampler]; let inputAcc = gltf.accessors[gltfSampler.input]; // find frames by input name @@ -269,7 +256,7 @@ export class GltfAnimationResource extends AnimationResource { frames.joints.push(jointFrames); } - let outArray = _createArray(gltf, bin, gltfChannel.output); + let outArray = _createArray(gltf, bin, gltfSampler.output); if (gltfChannel.target.path === 'translation') { let cnt = outArray.length / 3; jointFrames.translations = new Array(cnt); @@ -309,6 +296,7 @@ export class GltfAnimationResource extends AnimationResource { animationClip._length = maxLength; } } +cc.GltfAnimationResource = GltfAnimationResource; const _type2size = { SCALAR: 1, @@ -321,13 +309,13 @@ const _type2size = { }; const _compType2Array = { - [gfx.ATTR_TYPE_INT8]: Int8Array, - [gfx.ATTR_TYPE_UINT8]: Uint8Array, - [gfx.ATTR_TYPE_INT16]: Int16Array, - [gfx.ATTR_TYPE_UINT16]: Uint16Array, - [gfx.ATTR_TYPE_INT32]: Int32Array, - [gfx.ATTR_TYPE_UINT32]: Uint32Array, - [gfx.ATTR_TYPE_FLOAT32]: Float32Array, + 5120: Int8Array, + 5121: Uint8Array, + 5122: Int16Array, + 5123: Uint16Array, + 5124: Int32Array, + 5125: Uint32Array, + 5126: Float32Array, }; const _gltfAttribMap = { @@ -351,6 +339,9 @@ const _gltfAttribMap = { */ function _createArray(gltf, bin, accessorID) { let acc = gltf.accessors[accessorID]; + if (acc.bufferView === undefined) { + throw "Unexpect accessor format."; + } let bufView = gltf.bufferViews[acc.bufferView]; let num = _type2size[acc.type]; @@ -395,6 +386,7 @@ export function createEntities(app, gltfNodes) { for (let i = 0; i < gltfNodes.length; ++i) { let gltfNode = gltfNodes[i]; + /** @type Node */ let node = app.createEntity(gltfNode.name); if (gltfNode.translation) { @@ -446,7 +438,7 @@ export function createEntities(app, gltfNodes) { */ export function createSkeleton(gltfAsset, index) { /** @type GLTFFormat */ - const gltf = gltfAsset.description.json; + const gltf = gltfAsset.description; if (!gltf.skins || index >= gltf.skins.length) { return; diff --git a/cocos/3d/assets/web-audio-clip.js b/cocos/3d/assets/web-audio-clip.js index 5e0ae8dc72..8a88dd7138 100644 --- a/cocos/3d/assets/web-audio-clip.js +++ b/cocos/3d/assets/web-audio-clip.js @@ -27,7 +27,7 @@ import { _decorator } from "../../core/data/index"; const { ccclass } = _decorator; import { AudioClip, AudioSourceType, PlayingState } from "./audio-clip"; -@ccclass +@ccclass('cc.WebAudioClip') export default class WebAudioClip extends AudioClip { /** * @type {number} diff --git a/cocos/3d/assets/wx-game-audio-clip.js b/cocos/3d/assets/wx-game-audio-clip.js index c49150dd8c..534495dfe0 100644 --- a/cocos/3d/assets/wx-game-audio-clip.js +++ b/cocos/3d/assets/wx-game-audio-clip.js @@ -30,7 +30,7 @@ import { AudioClip, AudioSourceType, PlayingState } from './audio-clip'; /** * WeChat audio to port. https://developers.weixin.qq.com/minigame/dev/document/media/audio/InnerAudioContext.html */ -@ccclass +@ccclass('cc.WxGameAudioClip') export default class WxGameAudioClip extends AudioClip { constructor() { super(); diff --git a/cocos/3d/framework/renderSystemActor.js b/cocos/3d/framework/renderSystemActor.js index 1221fcdd4f..b897692d35 100644 --- a/cocos/3d/framework/renderSystemActor.js +++ b/cocos/3d/framework/renderSystemActor.js @@ -1,4 +1,4 @@ -import Component from '../../Components/CCComponent'; +import Component from '../../components/CCComponent'; class RenderSystemActorListener { constructor() { diff --git a/cocos/assets/CCBufferAsset.js b/cocos/assets/CCBufferAsset.js index 0c40670caf..4d69216c35 100644 --- a/cocos/assets/CCBufferAsset.js +++ b/cocos/assets/CCBufferAsset.js @@ -36,8 +36,8 @@ const {ccclass, property} = _decorator; * @class BufferAsset * @extends Asset */ -@ccclass -export class BufferAsset extends cc.Asset { +@ccclass('cc.BufferAsset') +export default class BufferAsset extends cc.Asset { /** * @type {ArrayBuffer} */ @@ -48,5 +48,8 @@ export class BufferAsset extends cc.Asset { /** * @type {ArrayBuffer} */ + @property _data = null; } + +cc.BufferAsset = BufferAsset; \ No newline at end of file diff --git a/cocos/assets/CCGLTFAsset.js b/cocos/assets/CCGLTFAsset.js index 7c3913d5f4..d9873e75b3 100644 --- a/cocos/assets/CCGLTFAsset.js +++ b/cocos/assets/CCGLTFAsset.js @@ -26,9 +26,13 @@ import { _decorator } from "../core/data/index"; const { ccclass, property } = _decorator; import JsonAsset from "./CCJsonAsset"; -import { BufferAsset } from "./CCBufferAsset"; +import BufferAsset from "./CCBufferAsset"; import Asset from "./CCAsset"; +/** + * @typedef {import("../../../types/glTF/glTF").GlTf} GlTf + */ + /** * !#en * Class for GLTF file. @@ -39,13 +43,13 @@ import Asset from "./CCAsset"; * @class GLTFAsset * @extends Asset */ -@ccclass +@ccclass('cc.GLTFAsset') export default class GLTFAsset extends Asset { /** - * @type {JsonAsset} + * @type {GlTf} */ - @property(JsonAsset) - _description; + @property + _description = null; /** * @type {BufferAsset[]} @@ -54,16 +58,16 @@ export default class GLTFAsset extends Asset { _buffers = []; /** - * Sets the underlying GlTf file asset. - * @param {JsonAsset} value + * Sets the underlying GlTf file content. + * @param {GlTf} value */ set description(value) { this._description = value; } /** - * Gets the underlying GlTf file asset. - * @return {JsonAsset} description + * Gets the underlying GlTf file content. + * @return {GlTf} description */ get description() { return this._description; @@ -76,3 +80,5 @@ export default class GLTFAsset extends Asset { return this._buffers; } } + +cc.GLTFAsset = GLTFAsset; \ No newline at end of file diff --git a/cocos/assets/index.js b/cocos/assets/index.js index 6ed9ac910a..59eaf319d1 100644 --- a/cocos/assets/index.js +++ b/cocos/assets/index.js @@ -37,4 +37,6 @@ 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'; +export {default as BufferAsset} from './CCBufferAsset'; export {default as AssetLibrary} from './CCAssetLibrary'; \ No newline at end of file diff --git a/cocos/load-pipeline/uuid-loader.js b/cocos/load-pipeline/uuid-loader.js index 2ad4d977be..0e887e5cbc 100644 --- a/cocos/load-pipeline/uuid-loader.js +++ b/cocos/load-pipeline/uuid-loader.js @@ -24,6 +24,7 @@ THE SOFTWARE. ****************************************************************************/ +import * as js from '../core/utils/js'; import {_getClassById} from '../core/utils/js'; import debug from '../core/platform/CCDebug'; import deserialize from '../core/data/deserialize'; diff --git a/cocos/scene-graph/base-node.js b/cocos/scene-graph/base-node.js index e5fc2af61a..f603077edf 100644 --- a/cocos/scene-graph/base-node.js +++ b/cocos/scene-graph/base-node.js @@ -1081,7 +1081,7 @@ export default class BaseNode extends CCObject { } // conflict detection - _Scene.DetectConflict.afterAddChild(this); + //_Scene.DetectConflict.afterAddChild(this); } var shouldActiveNow = this._active && !!(newParent && newParent._activeInHierarchy);