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
This commit is contained in:
Leslie Leigh
2018-10-08 11:52:14 +08:00
committed by pandamicro
parent 0c86fddb13
commit cf213ebdd7
23 changed files with 74 additions and 106 deletions
+4 -3
View File
@@ -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() {
+1 -1
View File
@@ -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 {
/**
+1 -1
View File
@@ -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}
+1 -1
View File
@@ -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}
+1 -1
View File
@@ -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}
+2 -1
View File
@@ -34,4 +34,5 @@ import "./opentype-font";
import "./skeleton";
import "./sprite";
import "./web-audio-clip";
import "./wx-game-audio-clip";
import "./wx-game-audio-clip";
import "./utils/gltf-utils.js";
+1 -1
View File
@@ -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';
+4 -4
View File
@@ -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;
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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}
+1 -1
View File
@@ -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();
+1 -2
View File
@@ -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);
+2 -1
View File
@@ -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;
-38
View File
@@ -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
}
}
+26 -34
View File
@@ -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;
+1 -1
View File
@@ -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}
+1 -1
View File
@@ -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();
+1 -1
View File
@@ -1,4 +1,4 @@
import Component from '../../Components/CCComponent';
import Component from '../../components/CCComponent';
class RenderSystemActorListener {
constructor() {
+5 -2
View File
@@ -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;
+15 -9
View File
@@ -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;
+2
View File
@@ -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';
+1
View File
@@ -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';
+1 -1
View File
@@ -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);