Complete Cocos Creator port with level bundles, themes, and tooling.
Adds level prefabs, theme assets, audio, extensions, and deployment scripts for the Unity WebGL migration. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
36
extensions/plugin-import-2x/creator/browser.ts
Normal file
36
extensions/plugin-import-2x/creator/browser.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
declare const Editor: any;
|
||||
|
||||
/**
|
||||
* 插件定义的方法
|
||||
* Methods defined by extension
|
||||
* 可以在 package.json 里的 contributions 里定义 messages 触发这里的方法
|
||||
* And of course, messages can be defined in the contributions section in package.JSON to trigger the method here
|
||||
*/
|
||||
exports.methods = {
|
||||
async importCreatorProject() {
|
||||
const result = await Editor.Dialog.select({
|
||||
title: Editor.I18n.t('plugin-import-2x.select_dialog.title'),
|
||||
path: await Editor.Profile.getConfig('plugin-import-2x', 'import-path') || Editor.Project.path,
|
||||
type: 'directory',
|
||||
});
|
||||
if (!result.filePaths || !result.filePaths[0]) {
|
||||
return;
|
||||
}
|
||||
Editor.Profile.setConfig('plugin-import-2x', 'import-path', result.filePaths[0]);
|
||||
Editor.Panel.open('plugin-import-2x.creator');
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* 启动的时候执行的初始化方法
|
||||
* Initialization method performed at startup
|
||||
*/
|
||||
exports.load = function() {};
|
||||
|
||||
/**
|
||||
* 插件被关闭的时候执行的卸载方法
|
||||
* Uninstall method performed when the extension is closed
|
||||
*/
|
||||
exports.unload = function() {};
|
||||
474
extensions/plugin-import-2x/creator/common/base.ts
Normal file
474
extensions/plugin-import-2x/creator/common/base.ts
Normal file
@@ -0,0 +1,474 @@
|
||||
/**
|
||||
* 用于导入 2d 项目到 3d 项目
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// @ts-ignore
|
||||
import { v4 } from 'node-uuid';
|
||||
import { nameToId } from './utlis';
|
||||
import { relative, join, dirname, parse, extname, ParsedPath } from 'path';
|
||||
// @ts-ignore
|
||||
import { existsSync, ensureDirSync, copyFileSync, readJSONSync, writeJSONSync, readFileSync, writeFileSync } from 'fs-extra';
|
||||
import {
|
||||
migratePlatformSettings,
|
||||
saveUuid,
|
||||
getDefaultAssets2D,
|
||||
getNewUuid,
|
||||
import2DChunks,
|
||||
importSubAssets, importProjectAssets,
|
||||
} from './utlis';
|
||||
import { UUID_2D_TO_3D, UUID_SKIP_EFFECT, UUID_UI_2D_TO_3D } from "./diff";
|
||||
import { getConverter } from "../convertor";
|
||||
|
||||
export interface MessageInfo {
|
||||
type: string; // 类型表示需要处理什么资源
|
||||
json: any; // 实际资源的源数据
|
||||
}
|
||||
|
||||
export abstract class ImporterBase {
|
||||
public type: string = '';
|
||||
// 导入到 3d 工程所在磁盘的路径
|
||||
protected destFsPath: string = '';
|
||||
protected destMetaFsPath: string = '';
|
||||
// 2d 源文件所在磁盘的路径
|
||||
protected sourceFsPath: string = '';
|
||||
protected pathInfo: ParsedPath | null = null;
|
||||
protected _2dMeta: any = null;
|
||||
protected _3dMeta: any = null;
|
||||
// 2d 源文件转成 3d 源文件,如果不为 null 说明需要保存
|
||||
// 例如 animation、prefab、scene 之类的源文件
|
||||
protected _2dTo3dSource: any = null;
|
||||
|
||||
// 检查 uuid 是否冲突,如果有就存储起来,后续会用到
|
||||
async checkUuid(meta: any) {
|
||||
const assetFsPath = await Editor.Message.request('asset-db', 'query-path', meta.uuid);
|
||||
if (assetFsPath && assetFsPath !== this.destFsPath) {
|
||||
const newUuid = v4();
|
||||
saveUuid(meta.uuid, newUuid);
|
||||
return newUuid;
|
||||
}
|
||||
// 存放 sprite frame uuid 对应的 texture uuid
|
||||
if (meta.type === 'sprite' && meta.subMetas) {
|
||||
for (const key in meta.subMetas) {
|
||||
const subMeta = meta.subMetas[key];
|
||||
saveUuid(subMeta.uuid, subMeta.rawTextureUuid);
|
||||
}
|
||||
}
|
||||
return meta.uuid;
|
||||
}
|
||||
|
||||
get3DUuid() {
|
||||
try {
|
||||
const meta = readJSONSync(this.destMetaFsPath);
|
||||
return meta.uuid;
|
||||
}
|
||||
catch (e) {
|
||||
return v4();
|
||||
}
|
||||
}
|
||||
|
||||
public reset() {
|
||||
this.destFsPath = '';
|
||||
this.sourceFsPath = '';
|
||||
this.pathInfo = null;
|
||||
this._2dMeta = null;
|
||||
this._3dMeta = null;
|
||||
this._2dTo3dSource = null;
|
||||
}
|
||||
|
||||
public static getPathInfo(projectRoot: string, sourceFsPath: string) {
|
||||
let relativePath = relative(projectRoot, sourceFsPath);
|
||||
if (!relativePath.startsWith('assets')) {
|
||||
relativePath = join('assets', relativePath);
|
||||
}
|
||||
let to = join(Editor.Project.path, relativePath);
|
||||
// 改后缀名 .fire to .scene;
|
||||
if (to.endsWith('.fire')) {
|
||||
to = to.replace(/.fire+$/g, '.scene');
|
||||
} else if (to.endsWith('.js')) {
|
||||
const meta = readJSONSync(sourceFsPath + '.meta');
|
||||
if (!meta.isPlugin) {
|
||||
to = to.replace(/.js+$/g, '.ts');
|
||||
}
|
||||
}
|
||||
return {
|
||||
to: to,
|
||||
toMeta: to + '.meta',
|
||||
from: sourceFsPath,
|
||||
fromMeta: sourceFsPath + '.meta',
|
||||
pathInfo: parse(sourceFsPath),
|
||||
};
|
||||
}
|
||||
|
||||
public static isNew(projectRoot: string, sourceFsPath: string) {
|
||||
try {
|
||||
if (sourceFsPath.endsWith('assets')) {
|
||||
return false;
|
||||
}
|
||||
const info = ImporterBase.getPathInfo(projectRoot, sourceFsPath);
|
||||
if (existsSync(info.to) && existsSync(info.toMeta)) {
|
||||
const _3DMeta = readJSONSync(info.toMeta);
|
||||
if (_3DMeta.importer === 'directory') {
|
||||
return false;
|
||||
}
|
||||
const _2DMeta = readJSONSync(info.fromMeta);
|
||||
return _2DMeta.uuid !== _3DMeta.uuid;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 导入前
|
||||
* 参数一:项目的路径
|
||||
* 参数二:项目的资源路径
|
||||
*/
|
||||
public async beforeImport(projectRoot: string, sourceFsPath: string): Promise<boolean> {
|
||||
// 重置
|
||||
this.reset();
|
||||
//
|
||||
this.sourceFsPath = sourceFsPath;
|
||||
const info = ImporterBase.getPathInfo(projectRoot, sourceFsPath);
|
||||
this.destFsPath = info.to;
|
||||
this.destMetaFsPath = info.toMeta;
|
||||
this.pathInfo = info.pathInfo;
|
||||
// update asset meta
|
||||
this._2dMeta = this.read2dMeta(sourceFsPath);
|
||||
// 检查 uuid 是否冲突
|
||||
const newUuid = this._2dMeta ? await this.checkUuid(this._2dMeta) : this.get3DUuid();
|
||||
this._3dMeta = this.createNewMeta(newUuid);
|
||||
this._3dMeta.uuid = newUuid;
|
||||
|
||||
this._2dMeta && importProjectAssets.set(this._2dMeta.uuid, {
|
||||
type: extname(sourceFsPath),
|
||||
basePath: sourceFsPath,
|
||||
outPath: this.destMetaFsPath,
|
||||
outUuid: this._2dMeta.uuid,
|
||||
meta: this._2dMeta,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
public needImport() {
|
||||
let doImport = true;
|
||||
if (existsSync(this.destFsPath) && existsSync(this.destMetaFsPath)) {
|
||||
const meta = readJSONSync(this.destMetaFsPath);
|
||||
doImport = this._3dMeta.uuid !== meta.uuid;
|
||||
}
|
||||
if (doImport) {
|
||||
// console.log(Editor.I18n.t('plugin-import-2x.import_log', {
|
||||
// path: this.sourceFsPath,
|
||||
// }));
|
||||
}
|
||||
return doImport;
|
||||
}
|
||||
|
||||
/*
|
||||
* 导入并且进行转换
|
||||
*/
|
||||
public async import(main?: any): Promise<boolean> {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* 转换后进行报错跟拷贝源文件的处理
|
||||
*/
|
||||
public async afterImport() {
|
||||
this.copySync(this.sourceFsPath);
|
||||
if (this._2dTo3dSource) {
|
||||
try {
|
||||
if (this.destFsPath.endsWith('.ts') ||
|
||||
this.destFsPath.endsWith('.js') ||
|
||||
this.destFsPath.endsWith('.plist') ||
|
||||
this.destFsPath.endsWith('.effect')) {
|
||||
writeFileSync(this.destFsPath, this._2dTo3dSource, { encoding: 'utf8' });
|
||||
}
|
||||
else {
|
||||
writeJSONSync(this.destFsPath, this._2dTo3dSource, { spaces: 2 });
|
||||
}
|
||||
}
|
||||
catch (e) { console.error(e); }
|
||||
}
|
||||
// console.log('保存:' + this.destFsPath);
|
||||
this.saveMeta();
|
||||
}
|
||||
|
||||
/*
|
||||
* 创建新的 meta 对象
|
||||
*/
|
||||
public createNewMeta(uuid?: string) {
|
||||
return {
|
||||
uuid: uuid || '',
|
||||
imported: false,
|
||||
importer: '*',
|
||||
files: [],
|
||||
subMetas: {},
|
||||
userData: {},
|
||||
ver: '0.0.1',
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* 读取 meta
|
||||
*/
|
||||
public read2dMeta(sourceFsPath: string) {
|
||||
try {
|
||||
if (!sourceFsPath.endsWith('.meta')) {
|
||||
sourceFsPath += '.meta';
|
||||
}
|
||||
if (!existsSync(sourceFsPath)) {
|
||||
return null;
|
||||
}
|
||||
return readJSONSync(sourceFsPath);
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 拷贝资源 + meta
|
||||
*/
|
||||
public copySync(from: string, to?: string) {
|
||||
try {
|
||||
if (!existsSync(from)) {
|
||||
return 0;
|
||||
}
|
||||
if (to) {
|
||||
ensureDirSync(dirname(to));
|
||||
copyFileSync(from, to);
|
||||
} else {
|
||||
ensureDirSync(dirname(this.destFsPath));
|
||||
copyFileSync(from, this.destFsPath);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 保存 meta
|
||||
*/
|
||||
public async saveMeta() {
|
||||
if (!this.destMetaFsPath.endsWith('.meta')) {
|
||||
this.destMetaFsPath += '.meta';
|
||||
}
|
||||
try {
|
||||
writeJSONSync(this.destMetaFsPath, this._3dMeta, { spaces: 2 });
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 保存
|
||||
*/
|
||||
public writeFileSync(to: string, data: any) {
|
||||
try {
|
||||
writeFileSync(to, data, { encoding: 'utf8' });
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 加载源文件类型为 JSON
|
||||
*/
|
||||
public readJSONSync(sourceFsPath?: string) {
|
||||
try {
|
||||
return readJSONSync(sourceFsPath || this.sourceFsPath);
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 加载源文件
|
||||
*/
|
||||
public readFileSync(sourceFsPath?: string) {
|
||||
try {
|
||||
return readFileSync(sourceFsPath || this.sourceFsPath, 'utf8');
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 导入缓存纹理设置
|
||||
*/
|
||||
public async migratePlatformSettings(platformSettings: any) {
|
||||
return await migratePlatformSettings(platformSettings);
|
||||
}
|
||||
|
||||
static async getUuid(uuid: string, type?: string) {
|
||||
if (UUID_2D_TO_3D.has(uuid)) {
|
||||
return UUID_2D_TO_3D.get(uuid);
|
||||
}
|
||||
if (UUID_UI_2D_TO_3D.has(uuid)) {
|
||||
return UUID_UI_2D_TO_3D.get(uuid);
|
||||
}
|
||||
if (UUID_SKIP_EFFECT.has(uuid)) {
|
||||
console.warn(Editor.I18n.t('plugin-import-2x.effect_warn_tips', {
|
||||
name: UUID_SKIP_EFFECT.get(uuid) as string,
|
||||
}));
|
||||
}
|
||||
uuid = await ImporterBase.ensureDefaultAssets2DFor3D(uuid);
|
||||
uuid = getNewUuid(uuid);
|
||||
|
||||
if (type && !uuid.includes('@')) {
|
||||
const id = `@${ImporterBase.getNameByID(type)}`;
|
||||
if (!uuid.endsWith(id)) {
|
||||
uuid += id;
|
||||
}
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
static getNewUuid(uuid: string) {
|
||||
return getNewUuid(uuid);
|
||||
}
|
||||
|
||||
/*
|
||||
* 通过名字获取 id
|
||||
*/
|
||||
static getNameByID(name: string) {
|
||||
return nameToId(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* 创建默认资源
|
||||
*/
|
||||
static getDefaultAssets2D(uuid: string) {
|
||||
return getDefaultAssets2D(uuid);
|
||||
}
|
||||
|
||||
/*
|
||||
* 创建 2d 默认资源
|
||||
*/
|
||||
static async ensureDefaultAssets2DFor3D(uuid: string) {
|
||||
const subAssets = importSubAssets.get(uuid);
|
||||
if (subAssets) {
|
||||
uuid = subAssets.baseUuid;
|
||||
}
|
||||
else {
|
||||
const projectAssets = importProjectAssets.get(uuid);
|
||||
if (projectAssets) {
|
||||
uuid = projectAssets.outUuid;
|
||||
}
|
||||
}
|
||||
const info = getDefaultAssets2D(uuid);
|
||||
if (info && info.path) {
|
||||
// 如果是内置资源与 3d 的一致就直接用 3D 的
|
||||
if (UUID_UI_2D_TO_3D.has(info.baseUuid)) {
|
||||
return UUID_UI_2D_TO_3D.get(info.baseUuid);
|
||||
}
|
||||
if (UUID_2D_TO_3D.has(info.baseUuid)) {
|
||||
return UUID_2D_TO_3D.get(info.baseUuid);
|
||||
}
|
||||
const defaultAssetsRootPath = join(__dirname, '../../static');
|
||||
let relativePath = relative(defaultAssetsRootPath, info.path);
|
||||
if (!relativePath.startsWith('assets')) {
|
||||
relativePath = join('assets', relativePath);
|
||||
}
|
||||
const destFsPath = join(Editor.Project.path, relativePath);
|
||||
try {
|
||||
if (!existsSync(destFsPath)) {
|
||||
if (destFsPath.endsWith('.mtl') || destFsPath.endsWith('.effect')) {
|
||||
await import2DChunks(false);
|
||||
}
|
||||
const converter = getConverter(extname(info.path));
|
||||
if (converter) {
|
||||
await converter.beforeImport(defaultAssetsRootPath, info.path);
|
||||
const isDone = await converter.import();
|
||||
if (isDone) {
|
||||
await converter.afterImport();
|
||||
}
|
||||
}
|
||||
const readmePath = join(Editor.Project.path, 'asset', 'migrate-resources', 'README.md');
|
||||
if (!existsSync(readmePath)) {
|
||||
ensureDirSync(dirname(readmePath));
|
||||
writeFileSync(readmePath, readFileSync(join(defaultAssetsRootPath, 'migrate-resources', 'README.md'), {encoding: 'utf8'}));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
if (subAssets) {
|
||||
return subAssets.uuid;
|
||||
}
|
||||
return info.baseUuid;
|
||||
}
|
||||
if (subAssets) {
|
||||
return subAssets.uuid;
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/*
|
||||
* 通过 engine 进行序列化与反序列化
|
||||
*/
|
||||
async queryCCClass(engine: any, message: any) {
|
||||
engine.contentWindow.postMessage(message, '*');
|
||||
return new Promise((resolve, reject) => {
|
||||
function onMessageCb(event: any) {
|
||||
window.removeEventListener("message", onMessageCb, false);
|
||||
resolve(event.data);
|
||||
}
|
||||
window.addEventListener("message", onMessageCb, false);
|
||||
});
|
||||
}
|
||||
|
||||
replaceScript(name: string) {
|
||||
try {
|
||||
const defaultAssetsRootPath = join(__dirname, '../../static/migrate-resources/default-assets-2d/scripts');
|
||||
const fromFsPath = join(defaultAssetsRootPath, name);
|
||||
const destFsPath = join(Editor.Project.path, 'assets', 'default-assets-2d', 'scripts', name);
|
||||
if (!existsSync(destFsPath)) {
|
||||
ensureDirSync(dirname(destFsPath));
|
||||
copyFileSync(fromFsPath, destFsPath);
|
||||
}
|
||||
const fromMetaPath = fromFsPath + '.meta';
|
||||
const destMetaFsPath = destFsPath + '.meta';
|
||||
if (!existsSync(destMetaFsPath)) {
|
||||
ensureDirSync(dirname(destMetaFsPath));
|
||||
copyFileSync(fromMetaPath, destMetaFsPath);
|
||||
}
|
||||
const meta = readJSONSync(fromMetaPath);
|
||||
// @ts-ignore
|
||||
const EditorExtends: any = require('@base/electron-module').require('EditorExtends');
|
||||
const UuidUtils = EditorExtends.UuidUtils;
|
||||
return UuidUtils.compressUuid(meta.uuid, false);
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
ensureDefaultSprite2DFor3D(json3D: any) {
|
||||
for (const key in json3D) {
|
||||
const item = json3D[key];
|
||||
if (item.__type__ === 'cc.StudioComponent') {
|
||||
item.__type__ = this.replaceScript('studio-component.ts');
|
||||
}
|
||||
else if (item.__type__ === 'cc.StudioWidget') {
|
||||
item.__type__ = this.replaceScript('studio-widget.ts');
|
||||
}
|
||||
}
|
||||
return json3D;
|
||||
}
|
||||
}
|
||||
127
extensions/plugin-import-2x/creator/common/diff.ts
Normal file
127
extensions/plugin-import-2x/creator/common/diff.ts
Normal file
@@ -0,0 +1,127 @@
|
||||
export const UUID_2D_TO_3D: Map<string, string> = new Map<string, string>();
|
||||
export const UUID_UI_2D_TO_3D: Map<string, string> = new Map<string, string>();
|
||||
export const UUID_SKIP_EFFECT: Map<string, string> = new Map<string, string>();
|
||||
|
||||
export function initDiff() {
|
||||
// builtin-standard.effect -> builtin-phong.effect
|
||||
UUID_2D_TO_3D.set('abc2cb62-7852-4525-a90d-d474487b88f2', '1baf0fc9-befa-459c-8bdd-af1a450a0319');
|
||||
// builtin-2d-graphics -> builtin-graphics
|
||||
UUID_2D_TO_3D.set('30682f87-9f0d-4f17-8a44-72863791461b', '1c02ae6f-4492-4915-b8f8-7492a3b1e4cd');
|
||||
// builtin-2d-spine -> builtin-spine
|
||||
UUID_2D_TO_3D.set('0e93aeaa-0b53-4e40-b8e0-6268b4e07bd7', '7383da24-dfde-48e8-82a7-a6e8a56f285c');
|
||||
// builtin-2d-sprite -> builtin-sprite
|
||||
UUID_2D_TO_3D.set('2874f8dd-416c-4440-81b7-555975426e93', '60f7195c-ec2a-45eb-ba94-8955f60e81d0');
|
||||
// builtin-3d-particle -> builtin-particle
|
||||
UUID_2D_TO_3D.set('829a282c-b049-4019-bd38-5ace8d8a6417', 'd1346436-ac96-4271-b863-1f4fdead95b0');
|
||||
// builtin-3d-trail -> builtin-particle-trail
|
||||
UUID_2D_TO_3D.set('2a7c0036-e0b3-4fe1-8998-89a54b8a2bec', '17debcc3-0a6b-4b8a-b00b-dc58b885581e');
|
||||
// builtin-clear-stencil
|
||||
UUID_2D_TO_3D.set('cf7e0bb8-a81c-44a9-ad79-d28d43991032', '810e96e4-e456-4468-9b59-f4e8f39732c0');
|
||||
// builtin-unlit
|
||||
UUID_2D_TO_3D.set('6d91e591-4ce0-465c-809f-610ec95019c6', 'a3cd009f-0ab0-420d-9278-b9fdab939bbc');
|
||||
// builtin-toon
|
||||
UUID_2D_TO_3D.set('e2f00085-c597-422d-9759-52c360279106', 'a7612b54-35e3-4238-a1a9-4a7b54635839');
|
||||
// builtin-2d-sprite -> ui-sprite-material
|
||||
UUID_2D_TO_3D.set('eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432', 'fda095cb-831d-4601-ad94-846013963de8');
|
||||
// builtin-2d-label -> ui-sprite-material
|
||||
UUID_2D_TO_3D.set('e02d87d4-e599-4d16-8001-e14891ac6506', 'fda095cb-831d-4601-ad94-846013963de8');
|
||||
// builtin-2d-gray-sprite -> ui-sprite-material
|
||||
UUID_2D_TO_3D.set('3a7bb79f-32fd-422e-ada2-96f518fed422', 'fda095cb-831d-4601-ad94-846013963de8');
|
||||
|
||||
// primitives
|
||||
UUID_2D_TO_3D.set('954fec8b-cd16-4bb9-a3b7-7719660e7558', '1263d74c-8167-4928-91a6-4e2672411f47');
|
||||
// box.mesh
|
||||
UUID_2D_TO_3D.set('046f172c-1574-488b-bbb8-6415a9adb96d', '1263d74c-8167-4928-91a6-4e2672411f47@a804a');
|
||||
// capsule.mesh
|
||||
UUID_2D_TO_3D.set('83f5eff8-3385-4f95-9b76-8da0aa1d96cd', '1263d74c-8167-4928-91a6-4e2672411f47@801ec');
|
||||
// cone.mesh
|
||||
UUID_2D_TO_3D.set('7a17de6e-227a-46b1-8009-e7157d4d3acf', '1263d74c-8167-4928-91a6-4e2672411f47@38fd2');
|
||||
// cylinder.mesh
|
||||
UUID_2D_TO_3D.set('b430cea3-6ab3-4106-b073-26c698918edd', '1263d74c-8167-4928-91a6-4e2672411f47@8abdc');
|
||||
// DefaultMaterial
|
||||
UUID_2D_TO_3D.set('a5849239-3ad3-41d1-8ab4-ae9fea11f97f', '1263d74c-8167-4928-91a6-4e2672411f47@ea6e2');
|
||||
// plane.mesh
|
||||
UUID_2D_TO_3D.set('a1ef2fc9-9c57-418a-8f69-6bed9a7a0e7f', '1263d74c-8167-4928-91a6-4e2672411f47@2e76e');
|
||||
// primitives.prefab
|
||||
UUID_2D_TO_3D.set('ab2fdde9-10c2-44e4-bfe1-fcfcc1a86aa9', '1263d74c-8167-4928-91a6-4e2672411f47@aae0f');
|
||||
// quad.mesh
|
||||
UUID_2D_TO_3D.set('e93d3fa9-8c21-4375-8a21-14ba84066c77', '1263d74c-8167-4928-91a6-4e2672411f47@fc873');
|
||||
// sphere.mesh
|
||||
UUID_2D_TO_3D.set('3bbdb0f6-c5f6-45de-9f33-8b5cbafb4d6d', '1263d74c-8167-4928-91a6-4e2672411f47@17020');
|
||||
// torus.mesh
|
||||
UUID_2D_TO_3D.set('14c74869-bdb4-4f57-86d8-a7875de2be30', '1263d74c-8167-4928-91a6-4e2672411f47@40ece');
|
||||
|
||||
|
||||
// box -> cube
|
||||
UUID_2D_TO_3D.set('a87cc147-01b2-43f8-8e42-a7ca90b0c757', '30da77a1-f02d-4ede-aa56-403452ee7fde');
|
||||
// capsule
|
||||
UUID_2D_TO_3D.set('fe1417b6-fe6b-46a4-ae7c-9fd331f33a2a', '73ce1f7f-d1f4-4942-ad93-66ca3b3041ab');
|
||||
// cone
|
||||
UUID_2D_TO_3D.set('b5fc2cf2-7942-483d-be1f-bbeadc4714ad', '6350d660-e888-4acf-a552-f3b719ae9110');
|
||||
// Cylinder
|
||||
UUID_2D_TO_3D.set('1c5e4038-953a-44c2-b620-0bbfc6170477', 'ab3e16f9-671e-48a7-90b7-d0884d9cbb85');
|
||||
// Plane
|
||||
UUID_2D_TO_3D.set('3f376125-a699-40ca-ad05-04d662eaa1f2', '40563723-f8fc-4216-99ea-a81636435c10');
|
||||
// Quad
|
||||
UUID_2D_TO_3D.set('6c9ef10d-b479-420b-bfe6-39cdda6a8ae0', '34a07346-9f62-4a84-90ae-cb83f7a426c1');
|
||||
// Sphere
|
||||
UUID_2D_TO_3D.set('2d9a4b85-b0ab-4c46-84c5-18f393ab2058', '655c9519-1a37-472b-bae6-29fefac0b550');
|
||||
// Torus
|
||||
UUID_2D_TO_3D.set('de510076-056b-484f-b94c-83bef217d0e1', 'd47f5d5e-c931-4ff4-987b-cc818a728b82');
|
||||
//
|
||||
UUID_SKIP_EFFECT.set('abc2cb62-7852-4525-a90d-d474487b88f2', 'builtin-phong.effect');
|
||||
// 内置 UI 替换
|
||||
// default-particle.png
|
||||
UUID_UI_2D_TO_3D.set('600301aa-3357-4a10-b086-84f011fa32ba', 'b5b27ab1-e740-4398-b407-848fc2b2c897');
|
||||
// default_btn_disabled.png
|
||||
UUID_UI_2D_TO_3D.set('71561142-4c83-4933-afca-cb7a17f67053', '951249e0-9f16-456d-8b85-a6ca954da16b');
|
||||
// default_btn_normal.png
|
||||
UUID_UI_2D_TO_3D.set('e851e89b-faa2-4484-bea6-5c01dd9f06e2', '20835ba4-6145-4fbc-a58a-051ce700aa3e');
|
||||
// default_btn_pressed.png
|
||||
UUID_UI_2D_TO_3D.set('b43ff3c2-02bb-4874-81f7-f2dea6970f18', '544e49d6-3f05-4fa8-9a9e-091f98fc2ce8');
|
||||
// default_editbox_bg.png
|
||||
UUID_UI_2D_TO_3D.set('edd215b9-2796-4a05-aaf5-81f96c9281ce', 'bd1bcaba-bd7d-4a71-b143-997c882383e4');
|
||||
// default_panel.png
|
||||
UUID_UI_2D_TO_3D.set('d81ec8ad-247c-4e62-aa3c-d35c4193c7af', 'b730527c-3233-41c2-aaf7-7cdab58f9749');
|
||||
// default_progressbar.png
|
||||
UUID_UI_2D_TO_3D.set('cfef78f1-c8df-49b7-8ed0-4c953ace2621', '24a704da-2867-446d-8d1a-5e920c75e09d');
|
||||
// default_progressbar_bg.png
|
||||
UUID_UI_2D_TO_3D.set('99170b0b-d210-46f1-b213-7d9e3f23098a', '9fd900dd-221b-4f89-8f2c-fba34243c835');
|
||||
// default_radio_button_off.png
|
||||
UUID_UI_2D_TO_3D.set('567dcd80-8bf4-4535-8a5a-313f1caf078a', 'f12a23c4-b924-4322-a260-3d982428f1e8');
|
||||
// default_radio_button_on.png
|
||||
UUID_UI_2D_TO_3D.set('9d60001f-b5f4-4726-a629-2659e3ded0b8', '45828f25-b50d-4c52-a591-e19491a62b8c');
|
||||
// default_scrollbar.png
|
||||
UUID_UI_2D_TO_3D.set('0291c134-b3da-4098-b7b5-e397edbe947f', '0da256a2-21f6-481b-90b6-d3643a09179b');
|
||||
// default_scrollbar_bg.png
|
||||
UUID_UI_2D_TO_3D.set('4bab67cb-18e6-4099-b840-355f0473f890', '28765e2f-040a-4c65-8e8c-f9d0bb79d863');
|
||||
// default_scrollbar_vertical.png
|
||||
UUID_UI_2D_TO_3D.set('d6d3ca85-4681-47c1-b5dd-d036a9d39ea2', 'afc47931-f066-46b0-90be-9fe61f213428');
|
||||
// default_scrollbar_vertical_bg.png
|
||||
UUID_UI_2D_TO_3D.set('617323dd-11f4-4dd3-8eec-0caf6b3b45b9', 'ffb88a8f-af62-48f4-8f1d-3cb606443a43');
|
||||
// default_sprite.png
|
||||
UUID_UI_2D_TO_3D.set('6e056173-d285-473c-b206-40a7fff5386e', '57520716-48c8-4a19-8acf-41c9f8777fb0');
|
||||
// default_sprite_splash.png
|
||||
UUID_UI_2D_TO_3D.set('0275e94c-56a7-410f-bd1a-fc7483f7d14a', '7d8f9b89-4fd1-4c9f-a3ab-38ec7cded7ca');
|
||||
// default_toggle_checkmark.png
|
||||
UUID_UI_2D_TO_3D.set('73a0903d-d80e-4e3c-aa67-f999543c08f5', '158e7e52-3220-4cd7-9694-713e0e6e8278');
|
||||
// default_toggle_disabled.png
|
||||
UUID_UI_2D_TO_3D.set('c25b9d50-c8fc-4d27-beeb-6e7c1f2e5c0f', 'ca7e121b-293c-4763-829a-b7a5fa81f0d2');
|
||||
// default_toggle_normal.png
|
||||
UUID_UI_2D_TO_3D.set('d29077ba-1627-4a72-9579-7b56a235340c', '11bdc4b0-64a8-4eb7-a2a7-9fb9e233e977');
|
||||
// default_toggle_pressed.png
|
||||
UUID_UI_2D_TO_3D.set('b181c1e4-0a72-4a91-bfb0-ae6f36ca60bd', 'a04e994f-ee49-47b6-9d08-2f59e3773fcc');
|
||||
// atom
|
||||
UUID_UI_2D_TO_3D.set('b8223619-7e38-47c4-841f-9160c232495a', '86f25d5c-9de5-454f-a5f9-ee16603e6701');
|
||||
UUID_UI_2D_TO_3D.set('b2687ac4-099e-403c-a192-ff477686f4f5', '86f25d5c-9de5-454f-a5f9-ee16603e6701');
|
||||
// atom.png texture
|
||||
UUID_UI_2D_TO_3D.set('8a96b965-2dc0-4e03-aa90-3b79cb93b5b4', '24c419ea-63a8-4ea1-a9d0-7fc469489bbc@6c48a');
|
||||
UUID_UI_2D_TO_3D.set('d0a82d39-bede-46c4-b698-c81ff0dedfff', '24c419ea-63a8-4ea1-a9d0-7fc469489bbc@6c48a');
|
||||
// atom.png sprite-frame
|
||||
UUID_UI_2D_TO_3D.set('bb42ed8e-0867-4584-ad63-b6f84f83bba8', '24c419ea-63a8-4ea1-a9d0-7fc469489bbc@f9941');
|
||||
UUID_UI_2D_TO_3D.set('472df5d3-35e7-4184-9e6c-7f41bee65ee3', '24c419ea-63a8-4ea1-a9d0-7fc469489bbc@f9941');
|
||||
// 3d 粒子
|
||||
UUID_UI_2D_TO_3D.set('432fa09c-cf03-4cff-a186-982604408a07', 'ea7478b0-408d-4052-b703-f0d2355e095f');
|
||||
// video
|
||||
UUID_UI_2D_TO_3D.set('2be36297-9abb-4fee-8049-9ed5e271da8a', '2be36297-9abb-4fee-8049-9ed5e271da8a');
|
||||
}
|
||||
810
extensions/plugin-import-2x/creator/common/parseCode.ts
Normal file
810
extensions/plugin-import-2x/creator/common/parseCode.ts
Normal file
@@ -0,0 +1,810 @@
|
||||
import { readWriteFileByLineWithProcess } from "./utlis";
|
||||
|
||||
function getType(val: string) {
|
||||
if (!isNaN(Number(val))) {
|
||||
return undefined;
|
||||
}
|
||||
if (val === 'false' || val === 'true') {
|
||||
return undefined;
|
||||
}
|
||||
if (val === 'null' || val === 'undefined') {
|
||||
return undefined;
|
||||
}
|
||||
// 数组
|
||||
if (val.startsWith('[') && val.endsWith(']')) {
|
||||
return [];
|
||||
}
|
||||
val = val.split('(')[0];
|
||||
if (!val.includes('cc')) {
|
||||
return undefined;
|
||||
}
|
||||
if (val.startsWith('cc.')) {
|
||||
const array = val.split('.');
|
||||
if (array.length > 3) {
|
||||
return array[1];
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
function getInfo(line: string, skip: boolean = false) {
|
||||
let values = line.split(':');
|
||||
if (values.length <= 1) {
|
||||
// 函数
|
||||
values = line.split('(');
|
||||
}
|
||||
if (values.length <= 1) {
|
||||
return {
|
||||
key: line,
|
||||
value: line,
|
||||
};
|
||||
}
|
||||
let value = values[1].trim().split(',')[0];
|
||||
if (!skip) {
|
||||
value = value.replace(/'|"|,/g, '');
|
||||
}
|
||||
return {
|
||||
key: values[0].trim(),
|
||||
value: value,
|
||||
};
|
||||
}
|
||||
|
||||
function syncIndex(line: string, index: number) {
|
||||
let result = line.match(/\{/g);
|
||||
if (result && result.length > 0) {
|
||||
index += result.length;
|
||||
}
|
||||
result = line.match(/\}/g);
|
||||
if (result && result.length > 0) {
|
||||
index -= result.length;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
function createContent(name: string) {
|
||||
return {
|
||||
name: name,
|
||||
extends: '',
|
||||
mixins: '',
|
||||
editors: {},
|
||||
statics: {},
|
||||
properties: {},
|
||||
functions: {},
|
||||
};
|
||||
}
|
||||
|
||||
export async function parseJSCode(path: string, name: string) {
|
||||
let otherIndex = 0;
|
||||
let classCodeIndex = 0;
|
||||
const classCodeMap: Map<number, any> = new Map();
|
||||
const importCodeMap: Map<number, string> = new Map();
|
||||
const otherCodeMap: Map<number, string> = new Map();
|
||||
const endCodeMap: Map<number, string> = new Map();
|
||||
const ccKeys: string[] = [];
|
||||
let openClass: boolean = false;
|
||||
let classIndex = 0;
|
||||
let openName: boolean | undefined = undefined;
|
||||
let openExtends: boolean | undefined = undefined;
|
||||
let openMixins: boolean | undefined = undefined;
|
||||
let openEditors: boolean | undefined = undefined;
|
||||
let propTotalIndex = 0;
|
||||
let subPropName = '';
|
||||
let subPropIndex = 0;
|
||||
let hasGet: boolean | undefined = undefined;
|
||||
let getIndex = 0;
|
||||
let hasSet: boolean | undefined = undefined;
|
||||
let setIndex = 0;
|
||||
let hasNotify: boolean | undefined = undefined;
|
||||
let notifyIndex = 0;
|
||||
let openSubProp: boolean | undefined = undefined;
|
||||
let openProperties: boolean | undefined = undefined;
|
||||
let staticIndex = 0;
|
||||
let subStaticIndex = 0;
|
||||
let subStaticName: string | undefined = undefined;
|
||||
let openStatics: boolean | undefined = undefined;
|
||||
let funcName = '';
|
||||
let funcIndex = 0;
|
||||
let openFunctions: boolean | undefined = undefined;
|
||||
let content: any;
|
||||
let isSkips = false;
|
||||
let topNote: string = '';
|
||||
await readWriteFileByLineWithProcess(path, (line: string) => {
|
||||
try {
|
||||
// 剔除空格
|
||||
let noTrimLine = line;
|
||||
line = line.trim();
|
||||
|
||||
if (line.startsWith('/*')) {
|
||||
isSkips = true;
|
||||
topNote += (line + '\n');
|
||||
return;
|
||||
}
|
||||
|
||||
if (isSkips) {
|
||||
isSkips = !line.endsWith('*/');
|
||||
topNote += (line + '\n');
|
||||
return;
|
||||
}
|
||||
|
||||
// 直接过滤注释文字
|
||||
if (line.startsWith('/') || line.startsWith('*') || !line) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!openClass) {
|
||||
if (line.includes('cc.Class(')) {
|
||||
openClass = true;
|
||||
classIndex = 1;
|
||||
classCodeIndex = classCodeMap.size;
|
||||
content = createContent(name);
|
||||
if (!classCodeMap.has(classCodeIndex)) {
|
||||
classCodeMap.set(classCodeIndex, content);
|
||||
}
|
||||
} else {
|
||||
if (line.includes('require')) {
|
||||
importCodeMap.set(importCodeMap.size, line);
|
||||
} else {
|
||||
const ccKeyArr = line.match(/(?<=cc.)(.*?)(?=[.|,|;|)|}|(])/);
|
||||
const ccKey = ccKeyArr && ccKeyArr[0];
|
||||
if (ccKey) {
|
||||
ccKeys.push(ccKey);
|
||||
}
|
||||
if (classCodeMap.size === 0) {
|
||||
otherIndex = syncIndex(line, otherIndex);
|
||||
if (line.includes('cc.runtime')) {
|
||||
otherIndex -= 1;
|
||||
noTrimLine = '//' + noTrimLine;
|
||||
}
|
||||
if (ccKey) {
|
||||
if (ccKey.includes('=') || ccKey.includes('function')) {
|
||||
noTrimLine = noTrimLine.replace(`cc.${ccKey}`, `const ${ccKey}`);
|
||||
}
|
||||
else {
|
||||
noTrimLine = noTrimLine.replace(`cc.${ccKey}`, ccKey);
|
||||
}
|
||||
const multiple = noTrimLine.match(new RegExp(ccKey, 'g'));
|
||||
if (multiple && multiple.length > 1) {
|
||||
noTrimLine = '//' + noTrimLine;
|
||||
}
|
||||
}
|
||||
otherCodeMap.set(otherCodeMap.size, noTrimLine);
|
||||
} else if (classCodeMap.size > 0) {
|
||||
otherIndex = syncIndex(line, otherIndex);
|
||||
if (otherIndex < 0) {
|
||||
noTrimLine = '//' + line;
|
||||
}
|
||||
endCodeMap.set(endCodeMap.size, noTrimLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (openClass) {
|
||||
// --------------- 检测是否解析类完毕 ---------------
|
||||
classIndex = syncIndex(line, classIndex);
|
||||
if (classIndex === 0 &&
|
||||
(line.endsWith('});') || line.endsWith('})') || line.endsWith(');') || line.endsWith(')') || line.endsWith(';'))) {
|
||||
openClass = false;
|
||||
classCodeMap.set(classCodeIndex, content);
|
||||
return;
|
||||
}
|
||||
|
||||
if (openProperties === undefined && openFunctions === undefined && openStatics === undefined) {
|
||||
// --------------- 获取 name ---------------
|
||||
if (openName === undefined && line.startsWith('name:')) {
|
||||
openName = true;
|
||||
}
|
||||
if (openName) {
|
||||
content.name = getInfo(line).value;
|
||||
if (line.endsWith(',')) {
|
||||
openName = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// --------------- 获取继承 ---------------
|
||||
if (openExtends === undefined && line.startsWith('extends:')) {
|
||||
openExtends = true;
|
||||
}
|
||||
if (openExtends) {
|
||||
content.extends = getInfo(line).value;
|
||||
if (line.endsWith(',')) {
|
||||
openExtends = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// --------------- 获取 mixins ---------------
|
||||
if (openMixins === undefined && line.startsWith('mixins:')) {
|
||||
openMixins = true;
|
||||
}
|
||||
if (openMixins) {
|
||||
content.mixins = getInfo(line).value;
|
||||
if (line.endsWith(',')) {
|
||||
openMixins = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// --------------- 获取 editor ---------------
|
||||
if (openEditors === undefined && line.startsWith('editor:')) {
|
||||
openEditors = true;
|
||||
return;
|
||||
}
|
||||
if (openEditors) {
|
||||
if (line.endsWith('},')) {
|
||||
openEditors = false;
|
||||
return;
|
||||
}
|
||||
const info = getInfo(line);
|
||||
content.editors[info.key] = info.value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------- 获取 properties ---------------
|
||||
if (openProperties === undefined && line.startsWith('properties:')) {
|
||||
propTotalIndex = syncIndex(line, propTotalIndex);
|
||||
if (propTotalIndex === 0) {
|
||||
return;
|
||||
}
|
||||
openProperties = true;
|
||||
return;
|
||||
}
|
||||
if (openProperties) {
|
||||
if (openSubProp === undefined && line.includes('{')) {
|
||||
subPropIndex = syncIndex(line, subPropIndex);
|
||||
const info = getInfo(line);
|
||||
subPropName = info.key;
|
||||
content.properties[subPropName] = {
|
||||
hasGet: undefined,
|
||||
hasSet: undefined,
|
||||
notify: undefined,
|
||||
type: undefined,
|
||||
default: undefined,
|
||||
visible: undefined,
|
||||
serializable: undefined,
|
||||
content: '',
|
||||
};
|
||||
if (subPropIndex === 0) {
|
||||
content.properties[subPropName].content = line;
|
||||
return;
|
||||
}
|
||||
openSubProp = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (openSubProp) {
|
||||
subPropIndex = syncIndex(line, subPropIndex);
|
||||
if (subPropIndex === 0 && (line.endsWith('},') || line.endsWith('}'))) {
|
||||
openSubProp = undefined;
|
||||
return;
|
||||
}
|
||||
|
||||
const subProp = content.properties[subPropName];
|
||||
subProp.content += (line + '\n');
|
||||
if (hasGet === undefined && line.includes('get:')) {
|
||||
getIndex = syncIndex(line, getIndex);
|
||||
if (getIndex === 0) {
|
||||
subProp.hasGet = noTrimLine + '\n';
|
||||
return;
|
||||
}
|
||||
subProp.hasGet = ` get ${subPropName} () {\n`;
|
||||
hasGet = true;
|
||||
return;
|
||||
}
|
||||
if (hasGet) {
|
||||
getIndex = syncIndex(line, getIndex);
|
||||
if (getIndex === 0 && (line.endsWith('},') || line.endsWith('}'))) {
|
||||
hasGet = undefined;
|
||||
subProp.hasGet += ' }';
|
||||
return;
|
||||
} else {
|
||||
subProp.hasGet += ' ' + noTrimLine.substring(noTrimLine.search(/\S/), noTrimLine.length) + '\n';
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (hasSet === undefined && line.includes('set:')) {
|
||||
setIndex = syncIndex(line, setIndex);
|
||||
let params = line.match(/(?<=\()(.*)(?=\))/);
|
||||
params = params ? params[0].split(',') : [];
|
||||
let str = '';
|
||||
for (let i = 0; i < params.length; ++i) {
|
||||
const param = params[i].trim();
|
||||
if (param === '') {
|
||||
continue;
|
||||
}
|
||||
if (i > 0) {
|
||||
str += ' ';
|
||||
}
|
||||
str += `${param}: any`;
|
||||
if (i < params.length - 1) {
|
||||
str += ',';
|
||||
}
|
||||
}
|
||||
if (setIndex === 0) {
|
||||
subProp.hasSet = noTrimLine + '\n';
|
||||
return;
|
||||
}
|
||||
subProp.hasSet = ` set ${subPropName} (${str}) {\n`;
|
||||
hasSet = true;
|
||||
return;
|
||||
}
|
||||
if (hasSet) {
|
||||
setIndex = syncIndex(line, setIndex);
|
||||
if (setIndex === 0 && (line.endsWith('},') || line.endsWith('}'))) {
|
||||
hasSet = undefined;
|
||||
subProp.hasSet += ' }';
|
||||
return;
|
||||
} else {
|
||||
subProp.hasSet += ' ' + noTrimLine.substring(noTrimLine.search(/\S/), noTrimLine.length) + '\n';
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (hasNotify === undefined && line.includes('notify')) {
|
||||
notifyIndex = syncIndex(line, notifyIndex);
|
||||
if (notifyIndex === 0) {
|
||||
subProp.notify = noTrimLine + '\n';
|
||||
return;
|
||||
}
|
||||
hasNotify = true;
|
||||
subProp.notify = line + '\n';
|
||||
return;
|
||||
}
|
||||
if (hasNotify) {
|
||||
notifyIndex = syncIndex(line, notifyIndex);
|
||||
if (notifyIndex === 0 && (line.endsWith('},') || line.endsWith('}'))) {
|
||||
hasNotify = undefined;
|
||||
subProp.notify += '}';
|
||||
} else {
|
||||
subProp.notify += line + '\n';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const info = getInfo(line);
|
||||
if (subProp.default === undefined && line.includes('default:')) {
|
||||
subProp.default = info.value;
|
||||
}
|
||||
if (subProp.type === undefined && line.includes('type:')) {
|
||||
subProp.type = info.value;
|
||||
}
|
||||
if (subProp.visible === undefined && line.includes('visible:')) {
|
||||
subProp.visible = info.value;
|
||||
}
|
||||
if (subProp.serializable === undefined && line.includes('serializable:')) {
|
||||
subProp.serializable = info.value;
|
||||
}
|
||||
|
||||
} else {
|
||||
propTotalIndex = syncIndex(line, propTotalIndex);
|
||||
if (propTotalIndex === 0 && (line.endsWith('},') || line.endsWith('}'))) {
|
||||
openProperties = undefined;
|
||||
return;
|
||||
}
|
||||
const info = getInfo(line);
|
||||
let type = getType(info.value);
|
||||
if (Array.isArray(type)) {
|
||||
if (info.value.length > 2) {
|
||||
type = 'array:' + info.value.substring(1, info.value.length - 1);
|
||||
}
|
||||
else {
|
||||
type = undefined;
|
||||
}
|
||||
}
|
||||
const value = info.value;
|
||||
content.properties[info.key] = {
|
||||
hasGet: undefined,
|
||||
hasSet: undefined,
|
||||
notify: undefined,
|
||||
type: type,
|
||||
default: value,
|
||||
visible: undefined,
|
||||
serializable: undefined,
|
||||
content: line,
|
||||
};
|
||||
}
|
||||
return;
|
||||
}
|
||||
// --------------- 获取 statics ---------------
|
||||
if (openStatics === undefined && line.startsWith('statics:')) {
|
||||
staticIndex = syncIndex(line, staticIndex);
|
||||
if (staticIndex === 0) {
|
||||
return;
|
||||
}
|
||||
openStatics = true;
|
||||
return;
|
||||
}
|
||||
if (openStatics) {
|
||||
staticIndex = syncIndex(line, staticIndex);
|
||||
if (staticIndex === 0 && (line.endsWith('},') || line.endsWith(','))) {
|
||||
openStatics = false;
|
||||
subStaticName = undefined;
|
||||
return;
|
||||
}
|
||||
if (subStaticName === undefined && line.includes('function')) {
|
||||
const info = getInfo(line);
|
||||
subStaticIndex = syncIndex(line, subStaticIndex);
|
||||
let params = line.match(/(?<=\()(.*)(?=\))/);
|
||||
params = params ? params[0].split(',') : [];
|
||||
let str = '';
|
||||
for (let i = 0; i < params.length; ++i) {
|
||||
const param = params[i].trim();
|
||||
if (param === '') {
|
||||
continue;
|
||||
}
|
||||
if (i > 0) {
|
||||
str += ' ';
|
||||
}
|
||||
str += `${param}: any`;
|
||||
if (i < params.length - 1) {
|
||||
str += ',';
|
||||
}
|
||||
}
|
||||
if (subStaticIndex === 0) {
|
||||
content.statics[info.key] = {
|
||||
parameter: '',
|
||||
content: noTrimLine + '\n',
|
||||
};
|
||||
return;
|
||||
}
|
||||
subStaticName = info.key;
|
||||
content.statics[subStaticName] = {
|
||||
parameter: params ? params[0] : '',
|
||||
content: ` public static ${subPropName} (${str}) {\n`,
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (subStaticName !== undefined) {
|
||||
subStaticIndex = syncIndex(line, subStaticIndex);
|
||||
if (subStaticIndex === 0 && (line.endsWith('},') || line.endsWith('}'))) {
|
||||
content.statics[subStaticName].content += ' }';
|
||||
return;
|
||||
}
|
||||
content.statics[subStaticName].content += (' ' + noTrimLine.substring(noTrimLine.search(/\S/), noTrimLine.length) + '\n');
|
||||
} else {
|
||||
const info = getInfo(line);
|
||||
content.statics[info.key] = {
|
||||
parameter: '',
|
||||
content: ` public static ${info.key} = ${info.value};\n`,
|
||||
};
|
||||
}
|
||||
return;
|
||||
}
|
||||
// --------------- 获取函数 ---------------
|
||||
if (openFunctions === undefined) {
|
||||
const info = getInfo(line);
|
||||
funcName = info.key;
|
||||
let params = line.match(/(?<=\()(.*)(?=\))/);
|
||||
if (params) {
|
||||
params = params[0].split(',');
|
||||
let str = '';
|
||||
for (let i = 0; i < params.length; ++i) {
|
||||
const param = params[i].trim();
|
||||
if (param === '') {
|
||||
continue;
|
||||
}
|
||||
if (i > 0) {
|
||||
str += ' ';
|
||||
}
|
||||
str += `${param}: any`;
|
||||
if (i < params.length - 1) {
|
||||
str += ',';
|
||||
}
|
||||
}
|
||||
content.functions[funcName] = {
|
||||
parameter: params ? params[0] : '',
|
||||
content: ` ${funcName} (${str}) {\n`,
|
||||
};
|
||||
funcIndex = syncIndex(line, funcIndex);
|
||||
if (funcIndex === 0) {
|
||||
content.functions[funcName].content += ' }\n\n';
|
||||
return;
|
||||
}
|
||||
openFunctions = true;
|
||||
} else {
|
||||
content.properties[info.key] = {
|
||||
hasGet: undefined,
|
||||
hasSet: undefined,
|
||||
notify: undefined,
|
||||
type: undefined,
|
||||
default: info.value,
|
||||
visible: undefined,
|
||||
serializable: undefined,
|
||||
content: line,
|
||||
};
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (openFunctions) {
|
||||
funcIndex = syncIndex(line, funcIndex);
|
||||
if (funcIndex === 0 && (line.endsWith('},') || line.endsWith('}'))) {
|
||||
openFunctions = undefined;
|
||||
content.functions[funcName].content += ' }\n\n';
|
||||
return;
|
||||
}
|
||||
const func = content.functions[funcName];
|
||||
|
||||
const len = noTrimLine.search(/\S/);
|
||||
func.content += `${noTrimLine.substring(0, len)}// ${noTrimLine.substring(len, noTrimLine.length)} \n`;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
topNote,
|
||||
ccKeys,
|
||||
classCodeMap,
|
||||
importCodeMap,
|
||||
otherCodeMap,
|
||||
endCodeMap,
|
||||
};
|
||||
}
|
||||
|
||||
function match(line: string, regExpStr: string, global: string = '') {
|
||||
try {
|
||||
const regExp = new RegExp(`(?<=${regExpStr})([a-zA-Z0-9]+)`, global);
|
||||
const result = line.match(regExp);
|
||||
if (result) {
|
||||
if (!global) {
|
||||
return result[result.length - 1];
|
||||
} else {
|
||||
let arr: string[] = [];
|
||||
for (let element of result) {
|
||||
arr.push(element);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function getRegExp(str: string, global: string = '') {
|
||||
return new RegExp(str, global);
|
||||
}
|
||||
|
||||
function addCode(content: string, code: string, enter: boolean = true) {
|
||||
if (code) {
|
||||
content += code;
|
||||
if (enter) {
|
||||
content += '\n';
|
||||
}
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
const RENAME_COMPONENT: any = {
|
||||
'BoxCollider': 'BoxCollider2D',
|
||||
'BoxCollider3D': 'BoxCollider',
|
||||
'CircleCollider': 'CircleCollider2D',
|
||||
'Collider': 'Collider2D',
|
||||
'Collider3D': 'Collider',
|
||||
'DistanceJoint': 'DistanceJoint2D',
|
||||
'ClickEvent': 'EventHandler',
|
||||
'MouseJoint': 'MouseJoint2D',
|
||||
'WheelJoint': 'WheelJoint2D',
|
||||
'PolygonCollider': 'PolygonCollider2D',
|
||||
'ParticleSystem': 'ParticleSystem2D',
|
||||
'ParticleSystem3D': 'ParticleSystem',
|
||||
'Joint': 'Joint2D',
|
||||
'RigidBody': 'RigidBody2D',
|
||||
'RigidBody3D': 'RigidBody',
|
||||
'SphereCollider3D': 'SphereCollider',
|
||||
'RenderComponent': 'UIRenderable',
|
||||
'SkeletonAnimation': 'SkeletalAnimation',
|
||||
'Float': 'CCFloat',
|
||||
'string': 'CCString',
|
||||
'Boolean': 'CCBoolean',
|
||||
'Integer': 'CCInteger',
|
||||
};
|
||||
|
||||
export async function parseTSCode(baseClassName: string, path: string) {
|
||||
let isTop = true;
|
||||
let isOther = false;
|
||||
let topCode = '';
|
||||
let imports: string[] = ['_decorator'];
|
||||
let decoratorCode = '';
|
||||
let otherImportCode = '';
|
||||
let otherDecoratorCode = '';
|
||||
let cccclassCode = '';
|
||||
let contentCode = '';
|
||||
let openClass = false;
|
||||
let waitOpenClass = false;// 需要检测到 { 才能开启 openClass
|
||||
let classIndex = 0;
|
||||
let openFunctions: boolean | undefined = undefined;
|
||||
let funcIndex = 0;
|
||||
let openConstructor: boolean | undefined = undefined;
|
||||
let constructorIndex = 0;
|
||||
|
||||
function pushImports(name: string) {
|
||||
name = RENAME_COMPONENT[name] || name;
|
||||
if (!imports.includes(name)) {
|
||||
imports.push(name);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
function replaceCodeByClassName(line: string, noTrimLine: string, isFunc?: boolean) {
|
||||
let classNames;
|
||||
if (isFunc) {
|
||||
// 删除只需要判断是否是 cc.xx
|
||||
classNames = match(line, '\:? (cc\.)', 'g');
|
||||
}
|
||||
else {
|
||||
classNames = match(line, '\:? ?(cc\.)', 'g');
|
||||
}
|
||||
|
||||
if (classNames) {
|
||||
let newline = noTrimLine;
|
||||
for (let className of classNames) {
|
||||
let newClassName = pushImports(className);
|
||||
let RegExp = getRegExp(`cc.${className}`, 'g');
|
||||
if (noTrimLine.trim().replace(/ /g, '').includes(`${className}=null`)) {
|
||||
newline = noTrimLine.replace(RegExp, `${newClassName} | null`);
|
||||
} else {
|
||||
newline = noTrimLine.replace(RegExp, newClassName);
|
||||
}
|
||||
}
|
||||
let matchArr = newline.match(/([a-zA-Z0-9]+)? =? ([a-zA-Z0-9]+)/);
|
||||
if (matchArr && matchArr[1] !== undefined && (matchArr[1] === matchArr[2])) {
|
||||
return undefined;
|
||||
}
|
||||
return newline + '\n';
|
||||
} else if (noTrimLine) {
|
||||
return noTrimLine + '\n';
|
||||
}
|
||||
}
|
||||
|
||||
await readWriteFileByLineWithProcess(path, (line: string) => {
|
||||
try {
|
||||
// 剔除空格
|
||||
let noTrimLine = line;
|
||||
line = line.trim();
|
||||
|
||||
if (!openClass) {
|
||||
if (line.includes('export default class ') || line.includes('export class ') || waitOpenClass) {
|
||||
// const name = match(line, 'class? ') as string;
|
||||
// if (name) {
|
||||
// line = line.replace(name, baseClassName);
|
||||
// }
|
||||
let extend = match(line, 'extends ?(cc\.)') as string;
|
||||
if (extend) {
|
||||
let newExtend = pushImports(extend);
|
||||
contentCode += line.replace(`cc.${extend}`, newExtend);
|
||||
}
|
||||
else {
|
||||
contentCode += line;
|
||||
}
|
||||
contentCode += '\n';
|
||||
classIndex = syncIndex(line, classIndex);
|
||||
if (classIndex === 0) {
|
||||
waitOpenClass = true;
|
||||
return;
|
||||
}
|
||||
waitOpenClass = false;
|
||||
openClass = true;
|
||||
}
|
||||
else {
|
||||
// 直接过滤注释文字
|
||||
if (line.startsWith('/') || line.startsWith('*')) {
|
||||
if (isTop) {
|
||||
topCode += '// ' + noTrimLine + '\n';
|
||||
}
|
||||
else if (isOther) {
|
||||
otherImportCode += '// ' + noTrimLine + '\n';
|
||||
}
|
||||
}
|
||||
else if (line.includes('cc._decorator')) {
|
||||
isTop = false;
|
||||
decoratorCode += noTrimLine.replace(/cc._decorator/, '_decorator') + '\n';
|
||||
}
|
||||
else if (line.includes('@ccclass')) {
|
||||
cccclassCode = noTrimLine;
|
||||
}
|
||||
else if (line.startsWith('@')) {
|
||||
otherDecoratorCode += noTrimLine;
|
||||
}
|
||||
else {
|
||||
isOther = true;
|
||||
if (!line) {
|
||||
return;
|
||||
}
|
||||
let newline = replaceCodeByClassName(line, noTrimLine);
|
||||
if (newline === undefined) {
|
||||
otherImportCode += `// ${noTrimLine}\n`;
|
||||
}
|
||||
else if (newline) {
|
||||
otherImportCode += newline;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 直接过滤注释文字
|
||||
if (line.startsWith('/') || line.startsWith('*')) {
|
||||
contentCode += '//' + noTrimLine + '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
// --------------- 检测是否解析类完毕 ---------------
|
||||
classIndex = syncIndex(line, classIndex);
|
||||
if (classIndex === 0 && (line.endsWith('}') || line.endsWith('};'))) {
|
||||
contentCode += '}\n\n';
|
||||
openClass = false;
|
||||
return;
|
||||
}
|
||||
if (openFunctions === undefined) {
|
||||
let newline = replaceCodeByClassName(line, noTrimLine);
|
||||
if (newline !== undefined) {
|
||||
if ((line.includes('constructor ()') || line.includes('constructor()'))) {
|
||||
openConstructor = true;
|
||||
}
|
||||
contentCode += newline;
|
||||
}
|
||||
}
|
||||
|
||||
// 函数
|
||||
if (openFunctions === undefined && line.match(/(?<=\()(.*)(?=\))/)) {
|
||||
funcIndex = syncIndex(line, funcIndex);
|
||||
if (funcIndex === 0) {
|
||||
return;
|
||||
}
|
||||
openFunctions = true;
|
||||
return;
|
||||
}
|
||||
if (openFunctions) {
|
||||
funcIndex = syncIndex(line, funcIndex);
|
||||
if (funcIndex === 0 && line.endsWith('}')) {
|
||||
contentCode += noTrimLine;
|
||||
contentCode += '\n';
|
||||
openFunctions = undefined;
|
||||
return;
|
||||
}
|
||||
if (line) {
|
||||
if (openConstructor && line.startsWith('super();')) {
|
||||
contentCode += ' ' + line;
|
||||
}
|
||||
else {
|
||||
contentCode += ' // ' + line;
|
||||
}
|
||||
}
|
||||
else {
|
||||
contentCode += line;
|
||||
}
|
||||
contentCode += '\n';
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
|
||||
let content = '';
|
||||
content = addCode(content, topCode);
|
||||
let importCode = `import { `;
|
||||
for (let i = 0; i < imports.length; ++i) {
|
||||
importCode += imports[i];
|
||||
if (i < imports.length - 1) {
|
||||
importCode += ', ';
|
||||
}
|
||||
}
|
||||
importCode += ` } from 'cc';`;
|
||||
content = addCode(content, importCode);
|
||||
content = addCode(content, decoratorCode);
|
||||
content = addCode(content, otherImportCode);
|
||||
content = addCode(content, cccclassCode.replace(/@ccclass/, `@ccclass('${baseClassName}')`));
|
||||
content = addCode(content, otherDecoratorCode);
|
||||
// content = addCode(content, exportClassCode);
|
||||
content = addCode(content, contentCode);
|
||||
|
||||
return {
|
||||
content: content,
|
||||
};
|
||||
}
|
||||
846
extensions/plugin-import-2x/creator/common/utlis.ts
Normal file
846
extensions/plugin-import-2x/creator/common/utlis.ts
Normal file
@@ -0,0 +1,846 @@
|
||||
'use strict';
|
||||
// @ts-ignore
|
||||
import { readdirSync, statSync, readJSONSync, readFileSync, ensureDirSync, copyFileSync, existsSync } from 'fs-extra';
|
||||
import { join, dirname, basename, relative, extname } from 'path';
|
||||
import { ImporterBase } from "./base";
|
||||
import { createReadStream } from 'fs';
|
||||
import { createInterface } from 'readline';
|
||||
// @ts-ignore
|
||||
import { DOMParser } from "xmldom";
|
||||
import { createHash } from 'crypto';
|
||||
const lodash = require('lodash');
|
||||
|
||||
export const SKIPS_SCRIPT = [
|
||||
'use_reversed_rotateBy.js',
|
||||
'use_reversed_rotateTo.js',
|
||||
'use_v2.0.x_cc.Toggle_event.js',
|
||||
'use_v2.1-2.2.1_cc.Toggle_event.js',
|
||||
];
|
||||
|
||||
// 优化原本的 localeCompare 方法,性能提升:1000 空节点 1103ms -> 31ms
|
||||
export const collator = new Intl.Collator('en', {
|
||||
numeric: true,
|
||||
sensitivity: 'base',
|
||||
});
|
||||
|
||||
// 2d 的分组
|
||||
export let layerToGroupMap: Map<number, number> = new Map();
|
||||
let groupList: string[] = [];
|
||||
export async function initGroupList(path: string) {
|
||||
try {
|
||||
const project = readJSONSync(join(path, '../settings/project.json'));
|
||||
groupList = project['group-list'] || [];
|
||||
for (let i = 0; i < groupList.length; ++i) {
|
||||
let group = groupList[i];
|
||||
await setGroupLayerByIndex(i, group);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
groupList = [];
|
||||
// console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getGroupLayerByIndex(index: number) {
|
||||
if (groupList.length === 0) {
|
||||
return 1 << 25; // 默认为 UI_2D
|
||||
}
|
||||
const group = groupList[index];
|
||||
if (group) {
|
||||
return await setGroupLayerByIndex(index, group);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function setGroupLayerByIndex(index: number, group: string) {
|
||||
let userLayers = await Editor.Profile.getProject('project', 'layer');
|
||||
let layer;
|
||||
if (!userLayers) {
|
||||
userLayers = [];
|
||||
} else {
|
||||
if (group === 'default') {
|
||||
group = 'Default';
|
||||
}
|
||||
layer = userLayers.find((layer: any) => layer.name === group);
|
||||
}
|
||||
if (!layer) {
|
||||
const length = userLayers.length;
|
||||
layer = {
|
||||
name: group,
|
||||
value: (1 << length),
|
||||
};
|
||||
userLayers.push(layer);
|
||||
// console.log('layer: ' + layer.name + ' ' + layer.value);
|
||||
let key = 1 << index;
|
||||
layerToGroupMap.set(key, layer.value);
|
||||
await Editor.Profile.setProject('project', 'layer', userLayers);
|
||||
}
|
||||
return layer.value;
|
||||
}
|
||||
|
||||
// 替换 fbx sub meta 中的 uuid
|
||||
export const replaceFbxUuidMap: Map<string, any> = new Map<string, any>();
|
||||
// 存储导入项目所有资源
|
||||
export const importProjectAssets: Map<string, any> = new Map<string, any>();
|
||||
export const importSubAssets: Map<string, any> = new Map<string, any>();
|
||||
// 存储 uuid 列表,处理 uuid 冲突,确保 uuid 都是唯一的
|
||||
export const uuidList: Map<string, string> = new Map<string, string>();
|
||||
// 脚本名
|
||||
export const scriptList: Map<string, string> = new Map<string, string>();
|
||||
export let replaceScriptList = [];
|
||||
export function updateReplaceScriptList(list: []) {
|
||||
replaceScriptList = list;
|
||||
}
|
||||
|
||||
export function saveUuid(oldUuid: string, newUuid: string) {
|
||||
uuidList.set(oldUuid, newUuid);
|
||||
}
|
||||
export function getNewUuid(oldUuid: string) {
|
||||
let uuid = uuidList.get(oldUuid);
|
||||
if (!uuid) {
|
||||
let info = importProjectAssets.get(oldUuid);
|
||||
if (info && info.outUuid) {
|
||||
uuid = info.outUuid;
|
||||
}
|
||||
if (!uuid) {
|
||||
info = importSubAssets.get(oldUuid);
|
||||
if (info && info.uuid) {
|
||||
uuid = info.uuid;
|
||||
}
|
||||
}
|
||||
}
|
||||
return uuid || oldUuid;
|
||||
}
|
||||
|
||||
export function clear() {
|
||||
scriptList.clear();
|
||||
replaceScriptList.length = 0;
|
||||
replaceFbxUuidMap.clear();
|
||||
}
|
||||
|
||||
|
||||
// 存储 2D 默认资源的信息列表
|
||||
interface DefaultAssets2D {
|
||||
type: string,
|
||||
path: string,
|
||||
baseUuid: string,
|
||||
}
|
||||
|
||||
const defaultAssets2DList: Map<string, DefaultAssets2D> = new Map<string, DefaultAssets2D>();
|
||||
export function getDefaultAssets2D(uuid: string) {
|
||||
return defaultAssets2DList.get(uuid);
|
||||
}
|
||||
|
||||
export function scanningDefaultAssets2D() {
|
||||
const default_asset_root = join(__dirname, '../../static');
|
||||
const rootPath = join(__dirname, '../../static/migrate-resources/default-assets-2d');
|
||||
defaultAssets2DList.clear();
|
||||
function step(path: string) {
|
||||
try {
|
||||
if (path.endsWith('.DS_Store')) {
|
||||
return;
|
||||
}
|
||||
const stat = statSync(path);
|
||||
if (stat.isDirectory()) {
|
||||
const names = readdirSync(path);
|
||||
names.forEach((name: string) => {
|
||||
const tempPath = join(path, name);
|
||||
if (name.endsWith('.meta')) {
|
||||
addImportProjectAssets(default_asset_root, tempPath, true);
|
||||
return;
|
||||
}
|
||||
step(tempPath);
|
||||
});
|
||||
}
|
||||
else {
|
||||
const metaPath = join(dirname(path), basename(path) + '.meta');
|
||||
const meta = readJSONSync(metaPath);
|
||||
defaultAssets2DList.set(meta.uuid, {
|
||||
path: path,
|
||||
type: meta.type,
|
||||
baseUuid: meta.uuid,
|
||||
});
|
||||
for (const key in meta.subMetas) {
|
||||
const subMeta = meta.subMetas[key];
|
||||
if (subMeta) {
|
||||
defaultAssets2DList.set(subMeta.uuid, {
|
||||
path: path,
|
||||
type: meta.type,
|
||||
baseUuid: meta.uuid,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
step(rootPath);
|
||||
}
|
||||
|
||||
export function isFbxMultKey(subMetas: any, key: string) {
|
||||
if (key.includes('-')) {
|
||||
const elements = key.split('-');
|
||||
const modeName = elements[0];
|
||||
const keys = Object.keys(subMetas).map((key) => {
|
||||
return key.includes(modeName + '-');
|
||||
}).filter(Boolean);
|
||||
return keys.length > 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function addImportProjectAssets(root: string, path: string, isDefaultAssets: boolean = false) {
|
||||
try {
|
||||
let base = path.replace('.meta', '');
|
||||
if (base.endsWith('.fire')) {
|
||||
base = base.replace(/.fire+$/g, '.scene');
|
||||
} else if (base.endsWith('.js')) {
|
||||
base = base.replace(/.js+$/g, '.ts');
|
||||
}
|
||||
const meta = readJSONSync(path);
|
||||
let outPath;
|
||||
if (isDefaultAssets) {
|
||||
outPath = join(Editor.Project.path, 'assets', relative(root, base + '.meta'));
|
||||
}
|
||||
else {
|
||||
outPath = join(Editor.Project.path, relative(root, base + '.meta'));
|
||||
}
|
||||
if (existsSync(outPath)) {
|
||||
const type = extname(base);
|
||||
if (type === '.fbx' || type === '.FBX') {
|
||||
for (let key in meta.subMetas) {
|
||||
const subMeta = meta.subMetas[key];
|
||||
if (subMeta) {
|
||||
const isMult = isFbxMultKey(meta.subMetas, key);
|
||||
// console.log('修改前:' + key + ' ' + isMult);
|
||||
key = getFBXSubMetaNewName(path.replace('.meta', ''), key, isMult);
|
||||
// console.log('修改后:' + key + ' ' + ImporterBase.getNameByID(key));
|
||||
importSubAssets.set(subMeta.uuid, {
|
||||
baseUuid: meta.uuid,
|
||||
uuid: `${meta.uuid}@${ImporterBase.getNameByID(key)}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (meta.type === 'Texture Packer') {
|
||||
for (let key in meta.subMetas) {
|
||||
const subMeta = meta.subMetas[key];
|
||||
if (subMeta) {
|
||||
key = basename(key, extname(key));
|
||||
importSubAssets.set(subMeta.uuid, {
|
||||
baseUuid: meta.uuid,
|
||||
uuid: `${meta.uuid}@${ImporterBase.getNameByID(key)}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (meta.type === 'sprite') {
|
||||
for (const key in meta.subMetas) {
|
||||
const subMeta = meta.subMetas[key];
|
||||
if (subMeta) {
|
||||
importSubAssets.set(subMeta.uuid, {
|
||||
baseUuid: meta.uuid,
|
||||
uuid: `${meta.uuid}@${ImporterBase.getNameByID('spriteFrame')}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (meta.type === 'raw') {
|
||||
importSubAssets.set(meta.uuid, {
|
||||
baseUuid: meta.uuid,
|
||||
uuid: `${meta.uuid}@${ImporterBase.getNameByID('texture')}`,
|
||||
});
|
||||
}
|
||||
importProjectAssets.set(meta.uuid, {
|
||||
type: type,
|
||||
basePath: path,
|
||||
outPath: outPath,
|
||||
outUuid: meta.uuid,
|
||||
meta: meta,
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
|
||||
export let chunksCacheBy2D: Map<string, any> = new Map<string, any>();
|
||||
|
||||
const getChunks = (path: string, regexp: RegExp, extname: string) => {
|
||||
const chunksMap: Map<string, any> = new Map<string, any>();
|
||||
function step(dir: string) {
|
||||
const names = readdirSync(dir);
|
||||
names.forEach((name: string) => {
|
||||
const file = join(dir, name);
|
||||
if (regexp.test(name)) {
|
||||
const name = basename(file, extname);
|
||||
const content = readFileSync(file, { encoding: 'utf8' });
|
||||
chunksMap.set(name, {
|
||||
from: file, // 源文件
|
||||
to: join(Editor.Project.path, 'assets', 'migrate-resources', 'chunks', name + '.chunk'), // 导入到项目到
|
||||
content: content,
|
||||
getIncludePath(effectPath: string) {
|
||||
return relative(effectPath, this.to);
|
||||
},
|
||||
});
|
||||
} else if (statSync(file).isDirectory()) {
|
||||
step(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
step(path);
|
||||
return chunksMap;
|
||||
};
|
||||
|
||||
export function init2DChunks() {
|
||||
chunksCacheBy2D = getChunks(join(__dirname, '../../static/migrate-resources/chunks'), /\.inc$/, '.inc');
|
||||
}
|
||||
export function import2DChunks(noRefres?: boolean): Promise<boolean> {
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
return new Promise(async (resolve) => {
|
||||
let idx = 0;
|
||||
let open = false;
|
||||
for (const [key, value] of chunksCacheBy2D) {
|
||||
if (!existsSync(value.to)) {
|
||||
// console.log('导入:' + value.to);
|
||||
ensureDirSync(dirname(value.to));
|
||||
copyFileSync(value.from, value.to);
|
||||
open = true;
|
||||
}
|
||||
idx++;
|
||||
if (idx >= chunksCacheBy2D.size) {
|
||||
if (open && !noRefres) {
|
||||
await Editor.Message.request('asset-db', 'refresh-asset', 'db://assets');
|
||||
}
|
||||
resolve(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* comporess texture */
|
||||
const migrateMap: Record<string, string> = {
|
||||
pvrtc_4bits: 'pvrtc_4bits_rgba',
|
||||
pvrtc_2bits: 'pvrtc_2bits_rgba',
|
||||
etc2: 'etc2_rgba',
|
||||
etc1: 'etc1_rgb_a',
|
||||
};
|
||||
|
||||
const PLATFORMS = ['miniGame', 'web', 'android', 'ios', 'pc'];
|
||||
|
||||
export async function migratePlatformSettings(platformSettings: any) {
|
||||
if (!platformSettings || Object.keys(platformSettings).length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const result = {
|
||||
useCompressTexture: true,
|
||||
presetId: '',
|
||||
};
|
||||
if (platformSettings.default && Object.keys(platformSettings).length === 1) {
|
||||
// 只有默认配置需要全部平台都配一遍
|
||||
PLATFORMS.forEach((platformType) => {
|
||||
const config = {};
|
||||
platformSettings.default.formats.forEach((format: any) => {
|
||||
// @ts-ignore
|
||||
config[format.name] = format.quality;
|
||||
});
|
||||
|
||||
platformSettings[platformType] = config;
|
||||
});
|
||||
} else {
|
||||
Object.keys(platformSettings).forEach((platformType) => {
|
||||
if (platformType === 'default') {
|
||||
return;
|
||||
}
|
||||
if (platformType !== 'default') {
|
||||
const defaultConfig: any = {};
|
||||
if (platformSettings.default) {
|
||||
const defaultData = JSON.parse(JSON.stringify(platformSettings.default));
|
||||
|
||||
if (defaultData.formats) {
|
||||
defaultData.formats.forEach((format: any) => {
|
||||
defaultConfig[format.name] = format.quality;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const otherConfig: any = {};
|
||||
platformSettings[platformType].formats.forEach((format: any) => {
|
||||
otherConfig[format.name] = format.quality;
|
||||
});
|
||||
|
||||
platformSettings[platformType] = Object.assign(defaultConfig, otherConfig);
|
||||
}
|
||||
|
||||
migrateCompressTextureType(platformSettings[platformType]);
|
||||
|
||||
if (platformType === 'minigame') {
|
||||
platformSettings.miniGame = platformSettings.minigame;
|
||||
delete platformSettings.minigame;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
delete platformSettings.default;
|
||||
if (Object.keys(platformSettings).length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
result.presetId = await getPresetId(platformSettings);
|
||||
return result;
|
||||
}
|
||||
|
||||
function migrateCompressTextureType(config: any) {
|
||||
if (!config) {
|
||||
return;
|
||||
}
|
||||
Object.keys(config).forEach((name: string) => {
|
||||
if (!migrateMap[name]) {
|
||||
return;
|
||||
}
|
||||
config[migrateMap[name]] = config[name];
|
||||
delete config[name];
|
||||
});
|
||||
}
|
||||
|
||||
async function getPresetId(platformSettings: any) {
|
||||
const presetId = 'presetId' + Date.now();
|
||||
// @ts-ignore
|
||||
let userPreset = await Editor.Profile.getProject('builder', 'textureCompressConfig.userPreset');
|
||||
if (!userPreset) {
|
||||
userPreset = {
|
||||
[presetId]: {
|
||||
name: presetId,
|
||||
options: platformSettings,
|
||||
},
|
||||
};
|
||||
// @ts-ignore
|
||||
await Editor.Profile.setProject('builder', `textureCompressConfig.userPreset`, userPreset);
|
||||
return presetId;
|
||||
}
|
||||
|
||||
for (const Id of Object.keys(userPreset)) {
|
||||
if (lodash.isEqual(userPreset[Id].options, platformSettings)) {
|
||||
return Id;
|
||||
}
|
||||
}
|
||||
// @ts-ignore
|
||||
await Editor.Profile.setProject('builder', `textureCompressConfig.userPreset.${presetId}`, {
|
||||
name: presetId,
|
||||
options: platformSettings,
|
||||
});
|
||||
return presetId;
|
||||
}
|
||||
|
||||
export function getBlendFactor2DTo3D(value: number) {
|
||||
switch (value) {
|
||||
case 0: // ZERO
|
||||
return 0;
|
||||
case 1: // ONE
|
||||
return 1;
|
||||
case 0x302:// SRC_ALPHA
|
||||
return 2;
|
||||
case 0x304:// DST_ALPHA
|
||||
return 3;
|
||||
case 0x303:// ONE_MINUS_SRC_ALPHA
|
||||
return 4;
|
||||
case 0x305:// ONE_MINUS_DST_ALPHA
|
||||
return 5;
|
||||
case 0x300:// SRC_COLOR
|
||||
return 6;
|
||||
case 0x306:// DST_COLOR
|
||||
return 7;
|
||||
case 0x301:// ONE_MINUS_SRC_COLOR
|
||||
return 8;
|
||||
case 0x307:// ONE_MINUS_DST_COLOR
|
||||
return 9;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function hasComponent(target: any, json3D: any, type: string) {
|
||||
for (const component of target._components) {
|
||||
const id = component.__id__;
|
||||
if (json3D[id].__type__ === type) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const UI_COMPONENT = [
|
||||
'cc.Canvas',
|
||||
'cc.Widget',
|
||||
'cc.Sprite',
|
||||
'cc.Label',
|
||||
'cc.LabelOutline',
|
||||
'cc.LabelShadow',
|
||||
'cc.RichText',
|
||||
'cc.ParticleSystem',
|
||||
'cc.TiledMap',
|
||||
'cc.TiledTile',
|
||||
'cc.TiledLayer',
|
||||
'cc.TiledObjectGroup',
|
||||
'cc.Layout',
|
||||
'cc.Button',
|
||||
'cc.ScrollView',
|
||||
'cc.Slider',
|
||||
'cc.PageView',
|
||||
'cc.ProgressBar',
|
||||
'cc.Toggle',
|
||||
'cc.ToggleContainer',
|
||||
'cc.ToggleGroup',
|
||||
'cc.EditBox',
|
||||
'cc.VideoPlayer',
|
||||
'cc.WebView',
|
||||
'cc.UITransform',
|
||||
'cc.UIOpacity',
|
||||
'sp.Skeleton',
|
||||
'dragonBones.ArmatureDisplay',
|
||||
];
|
||||
export function hasUIRenderComponent(target: any, json: any) {
|
||||
if (!target._is3DNode) {
|
||||
return true;
|
||||
}
|
||||
// 如果是自动同步的 prefab 是没有 _components 的
|
||||
if (!target._components) {
|
||||
return false;
|
||||
}
|
||||
for (const componentData of target._components) {
|
||||
const id = componentData.__id__;
|
||||
const component = json[id];
|
||||
if (component) {
|
||||
const __type__ = component.__type__;
|
||||
if (UI_COMPONENT.includes(__type__)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const childData of target._children) {
|
||||
const id = childData.__id__;
|
||||
const child = json[id];
|
||||
if (hasUIRenderComponent(child, json)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function hasCanvasComponent(node: any, json2D: any) {
|
||||
for (const componentData of node._components) {
|
||||
const id = componentData.__id__;
|
||||
const component = json2D[id];
|
||||
if (component) {
|
||||
const __type__ = component.__type__;
|
||||
if (__type__ === 'cc.Canvas') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function setColor(uiComponent: any, nodeID: any, json2D: any) {
|
||||
if (nodeID) {
|
||||
const node = json2D[nodeID];
|
||||
if (node && node._color) {
|
||||
uiComponent._color.r = node._color.r;
|
||||
uiComponent._color.g = node._color.g;
|
||||
uiComponent._color.b = node._color.b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getFBXSubMetaNewName(fsPath: string, baseName: string, isMult: boolean) {
|
||||
let ext = extname(baseName);
|
||||
const elements = baseName.split('-');
|
||||
let name = elements && elements[0];
|
||||
const modelName = basename(fsPath, extname(fsPath));
|
||||
if (name && (modelName === name)) {
|
||||
switch (ext) {
|
||||
case '.sac':
|
||||
name = `UnnamedAnimation`;
|
||||
break;
|
||||
case '.image':
|
||||
name = `UnnamedImage`;
|
||||
break;
|
||||
case '.mesh':
|
||||
name = `UnnamedMesh`;
|
||||
break;
|
||||
case '.mtl':
|
||||
name = `UnnamedMaterial`;
|
||||
break;
|
||||
case '.skeleton':
|
||||
name = `UnnamedSkeleton`;
|
||||
break;
|
||||
case '.texture':
|
||||
name = `UnnamedTexture`;
|
||||
break;
|
||||
default:
|
||||
name = `Unnamed`;
|
||||
}
|
||||
if (isMult) {
|
||||
name = name + '-' + elements[1];
|
||||
}
|
||||
}
|
||||
name = name.replace(ext, '');
|
||||
switch (ext) {
|
||||
case '.sac':
|
||||
ext = '.animation';
|
||||
break;
|
||||
case '.mtl':
|
||||
ext = '.material';
|
||||
break;
|
||||
}
|
||||
return name + ext;
|
||||
}
|
||||
|
||||
export async function readWriteFileByLineWithProcess(readName: any, callback: any) {
|
||||
await new Promise((resolve) => {
|
||||
const readStream = createReadStream(readName);
|
||||
const readLine = createInterface({
|
||||
input: readStream,
|
||||
});
|
||||
readLine.on('line', (line: string) => {
|
||||
callback(line);
|
||||
});
|
||||
readLine.on('close', () => {
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 读取 tmx 文件内容,查找依赖的 texture 文件信息
|
||||
* @param tmxFile tmx 文件路径
|
||||
* @param tmxFileData tmx 文件内容
|
||||
* @returns imageFullPaths
|
||||
*/
|
||||
export async function searchTmxDependImages(tmxFile: string, tmxFileData: string) {
|
||||
// 读取 xml 数据
|
||||
const doc = new DOMParser().parseFromString(tmxFileData);
|
||||
if (!doc) {
|
||||
console.error(`TiledMap import failed: failed to parser ${tmxFile}`);
|
||||
return;
|
||||
}
|
||||
let imgFullPaths: string[] = [];
|
||||
const rootElement = doc.documentElement;
|
||||
const tilesetElements = rootElement.getElementsByTagName('tileset');
|
||||
// 读取内部的 source 数据
|
||||
for (let i = 0; i < tilesetElements.length; i++) {
|
||||
const tileset = tilesetElements[i];
|
||||
const sourceTSXAttr = tileset.getAttribute('source');
|
||||
if (sourceTSXAttr) {
|
||||
// 获取 texture 路径
|
||||
const tsxAbsPath = join(dirname(tmxFile), sourceTSXAttr);
|
||||
if (existsSync(tsxAbsPath)) {
|
||||
const tsxContent = readFileSync(tsxAbsPath, 'utf-8');
|
||||
const tsxDoc = new DOMParser().parseFromString(tsxContent);
|
||||
if (tsxDoc) {
|
||||
const imageFullPath = await parseTilesetImages(tsxDoc, tsxAbsPath);
|
||||
imgFullPaths = imgFullPaths.concat(imageFullPath);
|
||||
} else {
|
||||
console.warn('Parse %s failed.', tsxAbsPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
// import images
|
||||
const imageFullPath = await parseTilesetImages(tileset, tmxFile);
|
||||
imgFullPaths = imgFullPaths.concat(imageFullPath);
|
||||
}
|
||||
|
||||
const imageLayerTextures: string[] = [];
|
||||
const imageLayerElements = rootElement.getElementsByTagName('imagelayer');
|
||||
for (let ii = 0, nn = imageLayerElements.length; ii < nn; ii++) {
|
||||
const imageLayer = imageLayerElements[ii];
|
||||
const imageInfos = imageLayer.getElementsByTagName('image');
|
||||
if (imageInfos && imageInfos.length > 0) {
|
||||
const imageInfo = imageInfos[0];
|
||||
const imageSource = imageInfo.getAttribute('source');
|
||||
const imgPath = join(dirname(tmxFile), imageSource!);
|
||||
if (existsSync(imgPath)) {
|
||||
imageLayerTextures.push(imgPath);
|
||||
} else {
|
||||
console.warn('Parse %s failed.', imgPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
return imgFullPaths.concat(imageLayerTextures);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取文件路径下 image 的 source 路径信息以及对应的文件名
|
||||
* @param tsxDoc
|
||||
* @param tsxPath
|
||||
* @returns imageFullPath
|
||||
*/
|
||||
export async function parseTilesetImages(tsxDoc: Element | Document, tsxPath: string) {
|
||||
const images = tsxDoc.getElementsByTagName('image');
|
||||
const imageFullPath: string[] = [];
|
||||
for (let i = 0; i < images.length; i++) {
|
||||
const image = images[i];
|
||||
const imageCfg = image.getAttribute('source');
|
||||
if (imageCfg) {
|
||||
const imgPath = join(dirname(tsxPath), imageCfg);
|
||||
imageFullPath.push(imgPath);
|
||||
}
|
||||
}
|
||||
return imageFullPath;
|
||||
}
|
||||
|
||||
export function getColor(node: any) {
|
||||
if (node && node._color) {
|
||||
return {
|
||||
"__type__": "cc.Color",
|
||||
"r": node._color.r,
|
||||
"g": node._color.g,
|
||||
"b": node._color.b,
|
||||
"a": node._color.a,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const halfToRad = 0.5 * Math.PI / 180.0;
|
||||
export function fromEuler(out: any, x: number, y: number, z: number) {
|
||||
x *= halfToRad;
|
||||
y *= halfToRad;
|
||||
z *= halfToRad;
|
||||
|
||||
const sx = Math.sin(x);
|
||||
const cx = Math.cos(x);
|
||||
const sy = Math.sin(y);
|
||||
const cy = Math.cos(y);
|
||||
const sz = Math.sin(z);
|
||||
const cz = Math.cos(z);
|
||||
|
||||
out.x = sx * cy * cz + cx * sy * sz;
|
||||
out.y = cx * sy * cz + sx * cy * sz;
|
||||
out.z = cx * cy * sz - sx * sy * cz;
|
||||
out.w = cx * cy * cz - sx * sy * sz;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 项目内的脚本文件名称不能重复
|
||||
*/
|
||||
export const scriptName = {
|
||||
allScripts: null,
|
||||
allClassNames: [],
|
||||
timer: 0,
|
||||
fileName: '',
|
||||
className: '',
|
||||
async isValid(fileName: string) {
|
||||
const className = this.getValidClassName(fileName);
|
||||
|
||||
if (!className) {
|
||||
return { state: 'errorScriptClassName' };
|
||||
}
|
||||
|
||||
const exist = await Editor.Message.request('scene', 'query-component-has-script', className);
|
||||
if (!exist) {
|
||||
return { state: '' };
|
||||
}
|
||||
|
||||
return { state: 'errorScriptClassNameExist', message: className };
|
||||
},
|
||||
async getValidFileName(fileName: string) {
|
||||
fileName = fileName.trim().replace(/[^a-zA-Z0-9_-]/g, '');
|
||||
const baseName = fileName;
|
||||
let index = 0;
|
||||
while ((await this.isValid(fileName)).state) {
|
||||
index++;
|
||||
const padString = `-${index.toString().padStart(3, '0')}`;
|
||||
fileName = `${baseName}${padString}`;
|
||||
}
|
||||
|
||||
return fileName;
|
||||
},
|
||||
getValidClassName(fileName: string) {
|
||||
/**
|
||||
* 类名转为大驼峰格式:
|
||||
* 头部不能有数字
|
||||
* 不含特殊字符
|
||||
* 符号和空格作为间隔,每个间隔后的首字母大写,如:
|
||||
* 0my class_name-for#demo! 转后为 MyClassNameForDemo
|
||||
*/
|
||||
fileName = fileName.trim().replace(/^[^a-zA-Z]+/g, '');
|
||||
const parts = fileName.match(/[a-zA-Z0-9]+/g);
|
||||
if (parts) {
|
||||
return parts
|
||||
.filter(Boolean)
|
||||
.map((part) => part[0].toLocaleUpperCase() + part.substr(1))
|
||||
.join('');
|
||||
}
|
||||
|
||||
return '';
|
||||
},
|
||||
};
|
||||
|
||||
// 排序
|
||||
export function sizeSorting(a: any, b: any) {
|
||||
const aID = a.__id__;
|
||||
const bID = b.__id__;
|
||||
return bID - aID;
|
||||
}
|
||||
|
||||
// 比对版本号
|
||||
export function compareVersion(versionA: string, versionB: string) {
|
||||
const a = versionA.split('.');
|
||||
const b = versionB.split('.');
|
||||
|
||||
const length = Math.max(a.length, b.length);
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
const an = a[i] || 0;
|
||||
const bn = b[i] || 0;
|
||||
|
||||
if (Number(an) < Number(bn)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (Number(an) > Number(bn)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function getComponentByType(nodeID: number, componentType: string, json: any) {
|
||||
const node = json[nodeID];
|
||||
const components = node._components.map((component: any) => json[component.__id__]);
|
||||
return components.find((component: any) => component.__type__ === componentType);
|
||||
}
|
||||
|
||||
export async function getDesignResolution() {
|
||||
const width = await Editor.Profile.getProject('project', 'general.designResolution.width');
|
||||
const height = await Editor.Profile.getProject('project', 'general.designResolution.height');
|
||||
return {
|
||||
width: width || 960,
|
||||
height: height || 640,
|
||||
}
|
||||
}
|
||||
|
||||
const _extendIndex = [
|
||||
1, 2, 3, 4, 5,
|
||||
7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
17, 18, 19, 20, 21, 22, 23, 24,
|
||||
26, 27, 28, 29, 30
|
||||
];
|
||||
export function nameToId(name: string, extend?: number) {
|
||||
if (!extend) {
|
||||
extend = 0;
|
||||
}
|
||||
const md5 = createHash('md5').update(name).digest('hex');
|
||||
let id = md5[0] + md5[6] + md5[16] + md5[25] + md5[31];
|
||||
for (let i = 0; i < extend; i++) {
|
||||
id += md5[_extendIndex[i]];
|
||||
}
|
||||
return id;
|
||||
}
|
||||
29
extensions/plugin-import-2x/creator/components/AlphaKey.ts
Normal file
29
extensions/plugin-import-2x/creator/components/AlphaKey.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
export const ALPHAKEY = {
|
||||
"__type__": "cc.AlphaKey",
|
||||
"alpha": 1,
|
||||
"time": 0,
|
||||
};
|
||||
|
||||
export class AlphaKey {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(ALPHAKEY));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(ALPHAKEY));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await AlphaKey.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
35
extensions/plugin-import-2x/creator/components/Animation.ts
Normal file
35
extensions/plugin-import-2x/creator/components/Animation.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
export const ANIMATION = {
|
||||
"__type__": "cc.Animation",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"playOnLoad": false,
|
||||
"_clips": [],
|
||||
"_defaultClip": null,
|
||||
};
|
||||
|
||||
export class Animation {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(ANIMATION));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(ANIMATION));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Animation.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
export const ANIMATIONCLIP = {
|
||||
"__type__": "cc.AnimationClip",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"sample": 60,
|
||||
"speed": 1,
|
||||
"wrapMode": 1,
|
||||
"events": [],
|
||||
"_duration": 0,
|
||||
"_keys": [],
|
||||
"_stepness": 0,
|
||||
"_curves": [],
|
||||
"_commonTargets": [],
|
||||
"_hash": 0,
|
||||
};
|
||||
|
||||
export class AnimationClip {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(ANIMATIONCLIP));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(ANIMATIONCLIP));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await AnimationClip.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
export const ANIMATIONCURVE = {
|
||||
"__type__": "cc.AnimationCurve",
|
||||
"preWrapMode": 2,
|
||||
"postWrapMode": 8,
|
||||
"keyFrames": [
|
||||
{
|
||||
"time": 0,
|
||||
"value": 1,
|
||||
"inTangent": 0,
|
||||
"outTangent": 0,
|
||||
},
|
||||
{
|
||||
"time": 1,
|
||||
"value": 1,
|
||||
"inTangent": 0,
|
||||
"outTangent": 0,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export class AnimationCurve {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(ANIMATIONCURVE));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(ANIMATIONCURVE));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await AnimationCurve.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
'use strict';
|
||||
import { getBlendFactor2DTo3D } from "../common/utlis";
|
||||
import { ImporterBase } from "../common/base";
|
||||
|
||||
export const ARMATUREDISPLAY = {
|
||||
"__type__": "dragonBones.ArmatureDisplay",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_visFlags": 0,
|
||||
"_customMaterial": null,
|
||||
"_srcBlendFactor": 2,
|
||||
"_dstBlendFactor": 4,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255,
|
||||
},
|
||||
"playTimes": -1,
|
||||
"premultipliedAlpha": false,
|
||||
"_defaultArmatureIndexValue": -1,
|
||||
"_dragonAsset": null,
|
||||
"_dragonAtlasAsset": null,
|
||||
"_armatureName": "weapon_1005",
|
||||
"_animationName": "",
|
||||
"_animationIndexValue": 0,
|
||||
"_defaultCacheModeValue": 0,
|
||||
"_timeScale": 1,
|
||||
"_playTimes": -1,
|
||||
"_debugBones": false,
|
||||
"_enableBatch": false,
|
||||
"_sockets": [],
|
||||
};
|
||||
|
||||
export class ArmatureDisplay {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(ARMATUREDISPLAY));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(ARMATUREDISPLAY));
|
||||
for (let key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) {
|
||||
continue;
|
||||
}
|
||||
if (key.startsWith('_N$')) {
|
||||
key = key.replace(/N\$/, '');
|
||||
}
|
||||
if (key === '_materials') {
|
||||
let material = value[0];
|
||||
if (material) {
|
||||
material = {
|
||||
__uuid__: await ImporterBase.getUuid(material.__uuid__),
|
||||
};
|
||||
}
|
||||
source._customMaterial = material;
|
||||
}
|
||||
else if (key === '_dragonAsset') {
|
||||
source._dragonAsset = {
|
||||
__uuid__: await ImporterBase.getUuid(value.__uuid__),
|
||||
};
|
||||
}
|
||||
else if (key === '_dragonAtlasAsset') {
|
||||
source._dragonAtlasAsset = {
|
||||
__uuid__: await ImporterBase.getUuid(value.__uuid__),
|
||||
};
|
||||
}
|
||||
else if (key === '_srcBlendFactor') {
|
||||
source._srcBlendFactor = getBlendFactor2DTo3D(value);
|
||||
} else if (key === '_dstBlendFactor') {
|
||||
source._dstBlendFactor = getBlendFactor2DTo3D(value);
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await ArmatureDisplay.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
30
extensions/plugin-import-2x/creator/components/Asset.ts
Normal file
30
extensions/plugin-import-2x/creator/components/Asset.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
export const ASSET = {
|
||||
"__type__": "cc.Asset",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
};
|
||||
|
||||
export class Asset {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(ASSET));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(ASSET));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Asset.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
32
extensions/plugin-import-2x/creator/components/AudioClip.ts
Normal file
32
extensions/plugin-import-2x/creator/components/AudioClip.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
export const AUDIOCLIP = {
|
||||
"__type__": "cc.AudioClip",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"_duration": 0,
|
||||
"_loadMode": 3,
|
||||
};
|
||||
|
||||
export class AudioClip {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(AUDIOCLIP));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(AUDIOCLIP));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await AudioClip.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
export const AUDIOSOURCE = {
|
||||
"__type__": "cc.AudioSource",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_clip": null,
|
||||
"_loop": false,
|
||||
"_playOnAwake": true,
|
||||
"_volume": 1,
|
||||
};
|
||||
|
||||
export class AudioSource {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(AUDIOSOURCE));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(AUDIOSOURCE));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await AudioSource.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
34
extensions/plugin-import-2x/creator/components/BaseNode.ts
Normal file
34
extensions/plugin-import-2x/creator/components/BaseNode.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
export const BASENODE = {
|
||||
"__type__": "cc.BaseNode",
|
||||
"_name": "New Node",
|
||||
"_objFlags": 0,
|
||||
"_parent": null,
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_components": [],
|
||||
"_prefab": null,
|
||||
};
|
||||
|
||||
export class BaseNode {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(BASENODE));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(BASENODE));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await BaseNode.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
36
extensions/plugin-import-2x/creator/components/Billboard.ts
Normal file
36
extensions/plugin-import-2x/creator/components/Billboard.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
export const BILLBOARD = {
|
||||
"__type__": "cc.Billboard",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_texture": null,
|
||||
"_height": 0,
|
||||
"_width": 0,
|
||||
"_rotation": 0,
|
||||
};
|
||||
|
||||
export class Billboard {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(BILLBOARD));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(BILLBOARD));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Billboard.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
34
extensions/plugin-import-2x/creator/components/BitmapFont.ts
Normal file
34
extensions/plugin-import-2x/creator/components/BitmapFont.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
export const BITMAPFONT = {
|
||||
"__type__": "cc.BitmapFont",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"fntDataStr": "",
|
||||
"spriteFrame": null,
|
||||
"fontSize": -1,
|
||||
"fntConfig": null,
|
||||
};
|
||||
|
||||
export class BitmapFont {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(BITMAPFONT));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(BITMAPFONT));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await BitmapFont.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
export const BLOCKINPUTEVENTS = {
|
||||
"__type__": "cc.BlockInputEvents",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
};
|
||||
|
||||
export class BlockInputEvents {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(BLOCKINPUTEVENTS));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(BLOCKINPUTEVENTS));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await BlockInputEvents.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
|
||||
export const BOXCOLLIDER = {
|
||||
"__type__": "cc.BoxCollider",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_material": null,
|
||||
"_isTrigger": false,
|
||||
"_center": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
"_size": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"z": 1,
|
||||
},
|
||||
};
|
||||
|
||||
export class BoxCollider {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(BOXCOLLIDER));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(BOXCOLLIDER));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === '_materials') {
|
||||
source._materials = [];
|
||||
for (let i = 0; i < value.length; ++i) {
|
||||
let material = value[0];
|
||||
if (material) {
|
||||
material = {
|
||||
__uuid__: await ImporterBase.getUuid(material.__uuid__),
|
||||
};
|
||||
source._materials.push(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await BoxCollider.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
export const BOXCOLLIDER2D = {
|
||||
"__type__": "cc.BoxCollider2D",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"tag": 0,
|
||||
"_group": 1,
|
||||
"_density": 1,
|
||||
"_sensor": false,
|
||||
"_friction": 0.2,
|
||||
"_restitution": 0,
|
||||
"_offset": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"_size": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 1,
|
||||
"height": 1,
|
||||
},
|
||||
};
|
||||
|
||||
export class BoxCollider2D {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(BOXCOLLIDER2D));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(BOXCOLLIDER2D));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await BoxCollider2D.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
export const BUFFERASSET = {
|
||||
"__type__": "cc.BufferAsset",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
};
|
||||
|
||||
export class BufferAsset {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(BUFFERASSET));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(BUFFERASSET));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await BufferAsset.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
33
extensions/plugin-import-2x/creator/components/Burst.ts
Normal file
33
extensions/plugin-import-2x/creator/components/Burst.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
export const BURST = {
|
||||
"__type__": "cc.Burst",
|
||||
"_time": 0,
|
||||
"_repeatCount": 1,
|
||||
"repeatInterval": 1,
|
||||
"count": {
|
||||
"__id__": 1,
|
||||
},
|
||||
};
|
||||
|
||||
export class Burst {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(BURST));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(BURST));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Burst.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
130
extensions/plugin-import-2x/creator/components/Button.ts
Normal file
130
extensions/plugin-import-2x/creator/components/Button.ts
Normal file
@@ -0,0 +1,130 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
|
||||
export const BUTTON = {
|
||||
"__type__": "cc.Button",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"clickEvents": [],
|
||||
"_interactable": true,
|
||||
"_transition": 0,
|
||||
"_normalColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 214,
|
||||
"g": 214,
|
||||
"b": 214,
|
||||
"a": 255,
|
||||
},
|
||||
"_hoverColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 211,
|
||||
"g": 211,
|
||||
"b": 211,
|
||||
"a": 255,
|
||||
},
|
||||
"_pressedColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255,
|
||||
},
|
||||
"_disabledColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 124,
|
||||
"g": 124,
|
||||
"b": 124,
|
||||
"a": 255,
|
||||
},
|
||||
"_normalSprite": null,
|
||||
"_hoverSprite": null,
|
||||
"_pressedSprite": null,
|
||||
"_disabledSprite": null,
|
||||
"_duration": 0.1,
|
||||
"_zoomScale": 1.2,
|
||||
"_target": null,
|
||||
};
|
||||
|
||||
export class Button {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(BUTTON));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(BUTTON));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
switch (key) {
|
||||
case '_normalMaterial':
|
||||
case '_grayMaterial':
|
||||
case '_N$enableAutoGrayEffect':
|
||||
break;
|
||||
case 'duration':
|
||||
source._duration = value;
|
||||
break;
|
||||
case 'zoomScale':
|
||||
source._zoomScale = value;
|
||||
break;
|
||||
case '_N$interactable':
|
||||
source._interactable = value;
|
||||
break;
|
||||
case '_N$transition':
|
||||
case 'transition':
|
||||
source._transition = value;
|
||||
break;
|
||||
case '_N$normalColor':
|
||||
source._normalColor = value;
|
||||
break;
|
||||
case '_N$pressedColor':
|
||||
case 'pressedColor':
|
||||
source._pressedColor = value;
|
||||
break;
|
||||
case '_N$hoverColor':
|
||||
case 'hoverColor':
|
||||
source._hoverColor = value;
|
||||
break;
|
||||
case '_N$disabledColor':
|
||||
source._disabledColor = value;
|
||||
break;
|
||||
case '_N$normalSprite':
|
||||
source._normalSprite = {
|
||||
__uuid__: await ImporterBase.getUuid(value.__uuid__, 'spriteFrame'),
|
||||
};
|
||||
break;
|
||||
case '_N$pressedSprite':
|
||||
source._pressedSprite = {
|
||||
__uuid__: await ImporterBase.getUuid(value.__uuid__, 'spriteFrame'),
|
||||
};
|
||||
break;
|
||||
case '_N$hoverSprite':
|
||||
source._hoverSprite = {
|
||||
__uuid__: await ImporterBase.getUuid(value.__uuid__, 'spriteFrame'),
|
||||
};
|
||||
break;
|
||||
case '_N$disabledSprite':
|
||||
source._disabledSprite = {
|
||||
__uuid__: await ImporterBase.getUuid(value.__uuid__, 'spriteFrame'),
|
||||
};
|
||||
break;
|
||||
case '_N$target':
|
||||
source._target = value;
|
||||
break;
|
||||
default:
|
||||
source[key] = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Button.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
111
extensions/plugin-import-2x/creator/components/Camera.ts
Normal file
111
extensions/plugin-import-2x/creator/components/Camera.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
'use strict';
|
||||
import { Node } from "./Node";
|
||||
import { layerToGroupMap } from '../common/utlis';
|
||||
|
||||
export const CAMERA = {
|
||||
"__type__": "cc.Camera",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_projection": 1,
|
||||
"_priority": 0,
|
||||
"_fov": 45,
|
||||
"_fovAxis": 0,
|
||||
"_orthoHeight": 10,
|
||||
"_near": 1,
|
||||
"_far": 1000,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 51,
|
||||
"g": 51,
|
||||
"b": 51,
|
||||
"a": 255,
|
||||
},
|
||||
"_depth": 1,
|
||||
"_stencil": 0,
|
||||
"_clearFlags": 7,
|
||||
"_rect": {
|
||||
"__type__": "cc.Rect",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"width": 1,
|
||||
"height": 1,
|
||||
},
|
||||
"_aperture": 19,
|
||||
"_shutter": 7,
|
||||
"_iso": 0,
|
||||
"_screenScale": 1,
|
||||
"_visibility": -325058561,
|
||||
"_targetTexture": null,
|
||||
};
|
||||
|
||||
export class Camera {
|
||||
|
||||
static addToScene(canvas: any, json3D: any) {
|
||||
const canvasID = canvas.node.__id__;
|
||||
const canvasNode = json3D[canvasID];
|
||||
const cameraNode = Node.create(`UICamera_${canvasNode._name}`, canvasID);
|
||||
json3D.push(cameraNode);
|
||||
const cameraNodeID = json3D.length - 1;
|
||||
canvasNode._children.push({
|
||||
__id__: cameraNodeID,
|
||||
});
|
||||
const camera = Camera.create(cameraNodeID);
|
||||
json3D.push(camera);
|
||||
const cameraID = json3D.length - 1;
|
||||
Node.addComponents(cameraNode, cameraID);
|
||||
canvas._cameraComponent = {
|
||||
__id__: cameraID,
|
||||
};
|
||||
}
|
||||
|
||||
static create(nodeID: number) {
|
||||
const camera = JSON.parse(JSON.stringify(CAMERA));
|
||||
camera.node = {
|
||||
__id__: nodeID,
|
||||
};
|
||||
return camera;
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(CAMERA));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === '_cullingMask') {
|
||||
source._visibility = value;
|
||||
}
|
||||
else if (key === '_depth') {
|
||||
source._priority = value;
|
||||
}
|
||||
else if (key === '_backgroundColor') {
|
||||
source._color = value;
|
||||
}
|
||||
else if (key === '_ortho') {
|
||||
// ORTHO = 0, PERSPECTIVE = 1
|
||||
source._projection = value === true ? 0 : 1;
|
||||
}
|
||||
else if (key === '_nearClip') {
|
||||
source._near = value;
|
||||
}
|
||||
else if (key === '_farClip') {
|
||||
source._far = value;
|
||||
}
|
||||
else if (key === '_orthoSize') {
|
||||
source._orthoHeight = value;
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Camera.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
179
extensions/plugin-import-2x/creator/components/Canvas.ts
Normal file
179
extensions/plugin-import-2x/creator/components/Canvas.ts
Normal file
@@ -0,0 +1,179 @@
|
||||
'use strict';
|
||||
import { Node } from "./Node";
|
||||
import { UITransform } from "./UITransform";
|
||||
import { Widget } from "./Widget";
|
||||
import {
|
||||
hasComponent,
|
||||
setColor,
|
||||
hasUIRenderComponent,
|
||||
getComponentByType,
|
||||
getDesignResolution
|
||||
} from "../common/utlis";
|
||||
import { Camera } from "./Camera";
|
||||
|
||||
export const CANVAS = {
|
||||
"__type__": "cc.Canvas",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"_cameraComponent": null,
|
||||
"_alignCanvasWithScreen": true,
|
||||
"_id": "e6QojeC9FOBZjtx9CZWAUA"
|
||||
};
|
||||
|
||||
const NAME = 'RenderRoot2D';
|
||||
|
||||
export const RENDER2D = {
|
||||
"__type__": `cc.${NAME}`,
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
};
|
||||
|
||||
export class Canvas {
|
||||
|
||||
static async checkDesignResolution (json: any, sceneName: any) {
|
||||
const canvasNodeIDs = json.map((item: any) => {
|
||||
if (item.__type__ === 'cc.Canvas') {
|
||||
return item.node.__id__;
|
||||
}
|
||||
return null
|
||||
}).filter(Boolean);
|
||||
|
||||
for (let canvasNodeID of canvasNodeIDs) {
|
||||
const canvasName = json[canvasNodeID] && json[canvasNodeID]._name;
|
||||
const component = getComponentByType(canvasNodeID, 'cc.UITransform', json);
|
||||
if (component) {
|
||||
const { width, height } = await getDesignResolution();
|
||||
if (component._contentSize.width !== width || component._contentSize.height !== height) {
|
||||
console.warn(Editor.I18n.t('plugin-import-2x.canvas_tips', { scene: sceneName +'.scene', name: canvasName }));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static getCameraIDByCanvasChildren(canvas: any, json3D: any) {
|
||||
const node = json3D[canvas.node.__id__];
|
||||
for (let child of node._children) {
|
||||
const item = json3D[child.__id__];
|
||||
if (item._name === 'Main Camera') {
|
||||
for (let childComponent of item._components) {
|
||||
const component = json3D[childComponent.__id__];
|
||||
if (component.__type__ === 'cc.Camera') {
|
||||
return childComponent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static async updateCameraComponent(json3D: any, json2D: any) {
|
||||
for (let i = 0; i < json3D.length; ++i) {
|
||||
const target = json3D[i];
|
||||
if (target.__type__ === 'cc.Canvas') {
|
||||
const item = Canvas.getCameraIDByCanvasChildren(target, json3D);
|
||||
if (item) {
|
||||
target._cameraComponent = item;
|
||||
const camera = json2D[item.__id__];
|
||||
target._alignCanvasWithScreen = camera._alignWithScreen;
|
||||
}
|
||||
else {
|
||||
Camera.addToScene(target, json3D);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async insert(json3D: any) {
|
||||
// 把放在 Canvas 外的 ui 组件都归位新的 Canvas 中
|
||||
const scene = json3D[1];
|
||||
const children = scene._children.slice();
|
||||
let node;
|
||||
let renderNodeID;
|
||||
for (const child of children) {
|
||||
const item = json3D[child.__id__];
|
||||
if (!hasComponent(item, json3D, 'cc.Canvas') && hasUIRenderComponent(item, json3D)) {
|
||||
const width = await Editor.Profile.getProject('project', 'general.designResolution.width');
|
||||
const height = await Editor.Profile.getProject('project', 'general.designResolution.height');
|
||||
if (!node) {
|
||||
node = Node.create(NAME, 1);
|
||||
json3D.push(node);
|
||||
renderNodeID = json3D.length - 1;
|
||||
scene._children.push({
|
||||
__id__: renderNodeID,
|
||||
});
|
||||
// add Render2D component
|
||||
const render2D = Canvas.create(renderNodeID, NAME, true);
|
||||
json3D.push(render2D);
|
||||
const render2DID = json3D.length - 1;
|
||||
Node.addComponents(node, render2DID);
|
||||
|
||||
// add uitransform component
|
||||
const uiTransform = UITransform.create(renderNodeID);
|
||||
uiTransform._contentSize.width = width;
|
||||
uiTransform._contentSize.height = height;
|
||||
uiTransform._anchorPoint.x = 0;
|
||||
uiTransform._anchorPoint.y = 0;
|
||||
json3D.push(uiTransform);
|
||||
Node.addComponents(node, json3D.length - 1);
|
||||
|
||||
// add widget component
|
||||
const widget = Widget.create(renderNodeID);
|
||||
widget._alignFlags = 45;
|
||||
json3D.push(widget);
|
||||
Node.addComponents(node, json3D.length - 1);
|
||||
}
|
||||
item._parent = {
|
||||
__id__: renderNodeID,
|
||||
};
|
||||
Node.addChildren(node, child.__id__);
|
||||
const index = scene._children.indexOf(child);
|
||||
scene._children.splice(index, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static create(nodeID?: number, name?: string, isRender2D?: boolean) {
|
||||
let component;
|
||||
if (isRender2D) {
|
||||
component = JSON.parse(JSON.stringify(RENDER2D));
|
||||
}
|
||||
else {
|
||||
component = JSON.parse(JSON.stringify(CANVAS));
|
||||
}
|
||||
if (name) {
|
||||
component._name = name;
|
||||
}
|
||||
if (nodeID) {
|
||||
component.node = {
|
||||
__id__: nodeID,
|
||||
};
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(CANVAS));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === 'node') {
|
||||
source.node = value;
|
||||
setColor(source, value.__id__, json2D);
|
||||
}
|
||||
else if (key === '_name' || key === '_id' || key === '_objFlags' || key === '_enabled') {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Canvas.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
|
||||
export const CAPSULECOLLIDER = {
|
||||
"__type__": "cc.CapsuleCollider",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_material": null,
|
||||
"_isTrigger": false,
|
||||
"_center": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
"_radius": 0.5,
|
||||
"_cylinderHeight": 1,
|
||||
"_direction": 1,
|
||||
};
|
||||
|
||||
export class CapsuleCollider {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(CAPSULECOLLIDER));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(CAPSULECOLLIDER));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === '_materials') {
|
||||
source._materials = [];
|
||||
for (let i = 0; i < value.length; ++i) {
|
||||
let material = value[0];
|
||||
if (material) {
|
||||
material = {
|
||||
__uuid__: await ImporterBase.getUuid(material.__uuid__),
|
||||
};
|
||||
source._materials.push(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await CapsuleCollider.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
export const CIRCLECOLLIDER2D = {
|
||||
"__type__": "cc.CircleCollider2D",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"tag": 0,
|
||||
"_group": 1,
|
||||
"_density": 1,
|
||||
"_sensor": false,
|
||||
"_friction": 0.2,
|
||||
"_restitution": 0,
|
||||
"_offset": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"_radius": 1,
|
||||
};
|
||||
|
||||
export class CircleCollider2D {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(CIRCLECOLLIDER2D));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(CIRCLECOLLIDER2D));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await CircleCollider2D.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
56
extensions/plugin-import-2x/creator/components/Collider.ts
Normal file
56
extensions/plugin-import-2x/creator/components/Collider.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
|
||||
export const COLLIDER = {
|
||||
"__type__": "cc.Collider",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_material": null,
|
||||
"_isTrigger": false,
|
||||
"_center": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
};
|
||||
|
||||
export class Collider {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(COLLIDER));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(COLLIDER));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === '_materials') {
|
||||
source._materials = [];
|
||||
for (let i = 0; i < value.length; ++i) {
|
||||
let material = value[0];
|
||||
if (material) {
|
||||
material = {
|
||||
__uuid__: await ImporterBase.getUuid(material.__uuid__),
|
||||
};
|
||||
source._materials.push(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Collider.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
43
extensions/plugin-import-2x/creator/components/Collider2D.ts
Normal file
43
extensions/plugin-import-2x/creator/components/Collider2D.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
export const COLLIDER2D = {
|
||||
"__type__": "cc.Collider2D",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"tag": 0,
|
||||
"_group": 1,
|
||||
"_density": 1,
|
||||
"_sensor": false,
|
||||
"_friction": 0.2,
|
||||
"_restitution": 0,
|
||||
"_offset": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
};
|
||||
|
||||
export class Collider2D {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(COLLIDER2D));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(COLLIDER2D));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Collider2D.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
35
extensions/plugin-import-2x/creator/components/ColorKey.ts
Normal file
35
extensions/plugin-import-2x/creator/components/ColorKey.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
export const COLORKEY = {
|
||||
"__type__": "cc.ColorKey",
|
||||
"color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255,
|
||||
},
|
||||
"time": 0,
|
||||
};
|
||||
|
||||
export class ColorKey {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(COLORKEY));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(COLORKEY));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await ColorKey.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
export const COLOROVERTIMEMODULE = {
|
||||
"__type__": "cc.ColorOvertimeModule",
|
||||
"_enable": false,
|
||||
"color": {
|
||||
"__id__": 1,
|
||||
},
|
||||
};
|
||||
|
||||
export class ColorOvertimeModule {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(COLOROVERTIMEMODULE));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(COLOROVERTIMEMODULE));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === 'enable') {
|
||||
source._enable = value;
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await ColorOvertimeModule.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
export const COMPPREFABINFO = {
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "",
|
||||
};
|
||||
|
||||
export class CompPrefabInfo {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(COMPPREFABINFO));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(COMPPREFABINFO));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await CompPrefabInfo.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
export const COMPACTVALUETYPEARRAY = {
|
||||
"__type__": "cc.CompactValueTypeArray",
|
||||
"_byteOffset": 0,
|
||||
"_unitCount": 0,
|
||||
"_unitElement": 0,
|
||||
"_length": 0,
|
||||
};
|
||||
|
||||
export class CompactValueTypeArray {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(COMPACTVALUETYPEARRAY));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(COMPACTVALUETYPEARRAY));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await CompactValueTypeArray.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
32
extensions/plugin-import-2x/creator/components/Component.ts
Normal file
32
extensions/plugin-import-2x/creator/components/Component.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
export const COMPONENT = {
|
||||
"__type__": "cc.Component",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
};
|
||||
|
||||
export class Component {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(COMPONENT));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(COMPONENT));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Component.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
export const COMPONENTMODIFIER = {
|
||||
"__type__": "cc.ComponentModifier",
|
||||
"component": "",
|
||||
};
|
||||
|
||||
export class ComponentModifier {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(COMPONENTMODIFIER));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(COMPONENTMODIFIER));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await ComponentModifier.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
|
||||
export const CONECOLLIDER = {
|
||||
"__type__": "cc.ConeCollider",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_material": null,
|
||||
"_isTrigger": false,
|
||||
"_center": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
"_radius": 0.5,
|
||||
"_height": 1,
|
||||
"_direction": 1,
|
||||
};
|
||||
|
||||
export class ConeCollider {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(CONECOLLIDER));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(CONECOLLIDER));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === '_materials') {
|
||||
source._materials = [];
|
||||
for (let i = 0; i < value.length; ++i) {
|
||||
let material = value[0];
|
||||
if (material) {
|
||||
material = {
|
||||
__uuid__: await ImporterBase.getUuid(material.__uuid__),
|
||||
};
|
||||
source._materials.push(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await ConeCollider.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
export const CONSTANTFORCE = {
|
||||
"__type__": "cc.ConstantForce",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_force": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
"_localForce": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
"_torque": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
"_localTorque": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
};
|
||||
|
||||
export class ConstantForce {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(CONSTANTFORCE));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(CONSTANTFORCE));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await ConstantForce.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
34
extensions/plugin-import-2x/creator/components/Constraint.ts
Normal file
34
extensions/plugin-import-2x/creator/components/Constraint.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
export const CONSTRAINT = {
|
||||
"__type__": "cc.Constraint",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_enableCollision": true,
|
||||
"_connectedBody": null,
|
||||
};
|
||||
|
||||
export class Constraint {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(CONSTRAINT));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(CONSTRAINT));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Constraint.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
export const CUBICSPLINENUMBERVALUE = {
|
||||
"__type__": "cc.CubicSplineNumberValue",
|
||||
};
|
||||
|
||||
export class CubicSplineNumberValue {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(CUBICSPLINENUMBERVALUE));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(CUBICSPLINENUMBERVALUE));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await CubicSplineNumberValue.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
export const CUBICSPLINEVALUECLASS = {
|
||||
"__type__": "cc.CubicSplineVec2Value",
|
||||
"dataPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"inTangent": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"outTangent": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
};
|
||||
|
||||
export class CubicSplineValueClass {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(CUBICSPLINEVALUECLASS));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(CUBICSPLINEVALUECLASS));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await CubicSplineValueClass.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
32
extensions/plugin-import-2x/creator/components/CurveRange.ts
Normal file
32
extensions/plugin-import-2x/creator/components/CurveRange.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
export const CURVERANGE = {
|
||||
"__type__": "cc.CurveRange",
|
||||
"mode": 0,
|
||||
"constant": 0,
|
||||
"constantMin": 0,
|
||||
"constantMax": 0,
|
||||
"multiplier": 1,
|
||||
};
|
||||
|
||||
export class CurveRange {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(CURVERANGE));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(CURVERANGE));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await CurveRange.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
export const CURVEVALUEADAPTER = {
|
||||
"__type__": "cc.CurveValueAdapter",
|
||||
};
|
||||
|
||||
export class CurveValueAdapter {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(CURVEVALUEADAPTER));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(CURVEVALUEADAPTER));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await CurveValueAdapter.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
|
||||
export const CYLINDERCOLLIDER = {
|
||||
"__type__": "cc.CylinderCollider",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_material": null,
|
||||
"_isTrigger": false,
|
||||
"_center": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
"_radius": 0.5,
|
||||
"_height": 2,
|
||||
"_direction": 1,
|
||||
};
|
||||
|
||||
export class CylinderCollider {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(CYLINDERCOLLIDER));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(CYLINDERCOLLIDER));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === '_materials') {
|
||||
source._materials = [];
|
||||
for (let i = 0; i < value.length; ++i) {
|
||||
let material = value[0];
|
||||
if (material) {
|
||||
material = {
|
||||
__uuid__: await ImporterBase.getUuid(material.__uuid__),
|
||||
};
|
||||
source._materials.push(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await CylinderCollider.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
export const DIRECTIONALLIGHT = {
|
||||
"__type__": "cc.DirectionalLight",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255,
|
||||
},
|
||||
"_useColorTemperature": false,
|
||||
"_colorTemperature": 6550,
|
||||
"_staticSettings": {
|
||||
"__id__": 1,
|
||||
},
|
||||
"_illuminance": 65000,
|
||||
};
|
||||
|
||||
export class DirectionalLight {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(DIRECTIONALLIGHT));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(DIRECTIONALLIGHT));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await DirectionalLight.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
export const DISTANCEJOINT2D = {
|
||||
"__type__": "cc.DistanceJoint2D",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"anchor": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"connectedAnchor": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"collideConnected": false,
|
||||
"connectedBody": null,
|
||||
"_maxLength": 5,
|
||||
"_autoCalcDistance": true,
|
||||
};
|
||||
|
||||
export class DistanceJoint2D {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(DISTANCEJOINT2D));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(DISTANCEJOINT2D));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await DistanceJoint2D.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
49
extensions/plugin-import-2x/creator/components/EditBox.ts
Normal file
49
extensions/plugin-import-2x/creator/components/EditBox.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
'use strict';
|
||||
export const EDITBOX = {
|
||||
"__type__": "cc.EditBox",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"editingDidBegan": [],
|
||||
"textChanged": [],
|
||||
"editingDidEnded": [],
|
||||
"editingReturn": [],
|
||||
"_textLabel": null,
|
||||
"_placeholderLabel": null,
|
||||
"_returnType": 0,
|
||||
"_useOriginalSize": true,
|
||||
"_string": "",
|
||||
"_tabIndex": 0,
|
||||
"_backgroundImage": null,
|
||||
"_inputFlag": 5,
|
||||
"_inputMode": 0,
|
||||
"_maxLength": 20,
|
||||
};
|
||||
|
||||
export class EditBox {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(EDITBOX));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(EDITBOX));
|
||||
for (let key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key.startsWith('_N$')) {
|
||||
key = key.replace(/N\$/, '');
|
||||
}
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await EditBox.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
export const EFFECTASSET = {
|
||||
"__type__": "cc.EffectAsset",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"techniques": [],
|
||||
"shaders": [],
|
||||
"combinations": [],
|
||||
};
|
||||
|
||||
export class EffectAsset {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(EFFECTASSET));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(EFFECTASSET));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await EffectAsset.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
export const EVENTHANDLER = {
|
||||
"__type__": "cc.ClickEvent",
|
||||
"target": null,
|
||||
"component": "",
|
||||
"_componentId": "",
|
||||
"handler": "",
|
||||
"customEventData": "",
|
||||
};
|
||||
|
||||
export class EventHandler {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(EVENTHANDLER));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(EVENTHANDLER));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await EventHandler.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
export const FIXEDJOINT2D = {
|
||||
"__type__": "cc.FixedJoint2D",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"anchor": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"connectedAnchor": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"collideConnected": false,
|
||||
"connectedBody": null,
|
||||
"_frequency": 0.7,
|
||||
"_dampingRatio": 0.5,
|
||||
};
|
||||
|
||||
export class FixedJoint2D {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(FIXEDJOINT2D));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(FIXEDJOINT2D));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await FixedJoint2D.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
30
extensions/plugin-import-2x/creator/components/Font.ts
Normal file
30
extensions/plugin-import-2x/creator/components/Font.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
export const FONT = {
|
||||
"__type__": "cc.Font",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
};
|
||||
|
||||
export class Font {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(FONT));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(FONT));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Font.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
export const FORCEOVERTIMEMODULE = {
|
||||
"__type__": "cc.ForceOvertimeModule",
|
||||
"_enable": false,
|
||||
"x": {
|
||||
"__id__": 1,
|
||||
},
|
||||
"y": {
|
||||
"__id__": 2,
|
||||
},
|
||||
"z": {
|
||||
"__id__": 3,
|
||||
},
|
||||
"space": 1,
|
||||
};
|
||||
|
||||
export class ForceOvertimeModule {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(FORCEOVERTIMEMODULE));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(FORCEOVERTIMEMODULE));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await ForceOvertimeModule.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
export const FORWARDFLOW = {
|
||||
"__type__": "ForwardFlow",
|
||||
"_name": "",
|
||||
"_priority": 0,
|
||||
"_tag": 0,
|
||||
"_stages": [],
|
||||
};
|
||||
|
||||
export class ForwardFlow {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(FORWARDFLOW));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(FORWARDFLOW));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await ForwardFlow.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
export const FORWARDPIPELINE = {
|
||||
"__type__": "ForwardPipeline",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"_tag": 0,
|
||||
"_flows": [],
|
||||
"renderTextures": [],
|
||||
"materials": [],
|
||||
};
|
||||
|
||||
export class ForwardPipeline {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(FORWARDPIPELINE));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(FORWARDPIPELINE));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await ForwardPipeline.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
export const FORWARDSTAGE = {
|
||||
"__type__": "ForwardStage",
|
||||
"_name": "",
|
||||
"_priority": 0,
|
||||
"_tag": 0,
|
||||
"renderQueues": [],
|
||||
};
|
||||
|
||||
export class ForwardStage {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(FORWARDSTAGE));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(FORWARDSTAGE));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await ForwardStage.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
30
extensions/plugin-import-2x/creator/components/Gradient.ts
Normal file
30
extensions/plugin-import-2x/creator/components/Gradient.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
export const GRADIENT = {
|
||||
"__type__": "cc.Gradient",
|
||||
"colorKeys": [],
|
||||
"alphaKeys": [],
|
||||
"mode": 0,
|
||||
};
|
||||
|
||||
export class Gradient {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(GRADIENT));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(GRADIENT));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Gradient.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
export const GRADIENTRANGE = {
|
||||
"__type__": "cc.GradientRange",
|
||||
"_mode": 0,
|
||||
"color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255,
|
||||
},
|
||||
};
|
||||
|
||||
export class GradientRange {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(GRADIENTRANGE));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(GRADIENTRANGE));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await GradientRange.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
80
extensions/plugin-import-2x/creator/components/Graphics.ts
Normal file
80
extensions/plugin-import-2x/creator/components/Graphics.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
import { getBlendFactor2DTo3D } from "../common/utlis";
|
||||
|
||||
export const GRAPHICS = {
|
||||
"__type__": "cc.Graphics",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_customMaterial": null,
|
||||
"_visFlags": 0,
|
||||
"_srcBlendFactor": 2,
|
||||
"_dstBlendFactor": 4,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255,
|
||||
},
|
||||
"_lineWidth": 1,
|
||||
"_strokeColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 0,
|
||||
"g": 0,
|
||||
"b": 0,
|
||||
"a": 255,
|
||||
},
|
||||
"_lineJoin": 2,
|
||||
"_lineCap": 0,
|
||||
"_fillColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255,
|
||||
},
|
||||
"_miterLimit": 10,
|
||||
};
|
||||
|
||||
export class Graphics {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(GRAPHICS));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(GRAPHICS));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) {
|
||||
continue;
|
||||
}
|
||||
if (key === '_materials') {
|
||||
let material = value[0];
|
||||
if (material) {
|
||||
material = {
|
||||
__uuid__: await ImporterBase.getUuid(material.__uuid__),
|
||||
};
|
||||
}
|
||||
source._customMaterial = material;
|
||||
} else if (key === '_srcBlendFactor') {
|
||||
source._srcBlendFactor = getBlendFactor2DTo3D(value);
|
||||
} else if (key === '_dstBlendFactor') {
|
||||
source._dstBlendFactor = getBlendFactor2DTo3D(value);
|
||||
} else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Graphics.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
export const HIERACHYMODIFIER = {
|
||||
"__type__": "cc.HierachyModifier",
|
||||
"path": "",
|
||||
};
|
||||
|
||||
export class HierachyModifier {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(HIERACHYMODIFIER));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(HIERACHYMODIFIER));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await HierachyModifier.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
'use strict';
|
||||
export const HINGECONSTRAINT = {
|
||||
"__type__": "cc.HingeConstraint",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_enableCollision": true,
|
||||
"_connectedBody": null,
|
||||
"axisA": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
"axisB": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
"pivotA": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
"pivotB": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
};
|
||||
|
||||
export class HingeConstraint {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(HINGECONSTRAINT));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(HINGECONSTRAINT));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await HingeConstraint.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
'use strict';
|
||||
export const HINGEJOINT2D = {
|
||||
"__type__": "cc.HingeJoint2D",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"anchor": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"connectedAnchor": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"collideConnected": false,
|
||||
"connectedBody": null,
|
||||
"_enableLimit": false,
|
||||
"_lowerAngle": 0,
|
||||
"_upperAngle": 0,
|
||||
"_enableMotor": false,
|
||||
"_maxMotorTorque": 1000,
|
||||
"_motorSpeed": 0,
|
||||
};
|
||||
|
||||
export class HingeJoint2D {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(HINGEJOINT2D));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(HINGEJOINT2D));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await HingeJoint2D.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
28
extensions/plugin-import-2x/creator/components/ImageAsset.ts
Normal file
28
extensions/plugin-import-2x/creator/components/ImageAsset.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
export const IMAGEASSET = {
|
||||
"__type__": "cc.ImageAsset",
|
||||
"content": "",
|
||||
};
|
||||
|
||||
export class ImageAsset {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(IMAGEASSET));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(IMAGEASSET));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await ImageAsset.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
30
extensions/plugin-import-2x/creator/components/JavaScript.ts
Normal file
30
extensions/plugin-import-2x/creator/components/JavaScript.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
export const JAVASCRIPT = {
|
||||
"__type__": "cc.JavaScript",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
};
|
||||
|
||||
export class JavaScript {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(JAVASCRIPT));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(JAVASCRIPT));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await JavaScript.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
44
extensions/plugin-import-2x/creator/components/Joint2D.ts
Normal file
44
extensions/plugin-import-2x/creator/components/Joint2D.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
export const JOINT2D = {
|
||||
"__type__": "cc.Joint2D",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"anchor": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"connectedAnchor": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"collideConnected": false,
|
||||
"connectedBody": null,
|
||||
};
|
||||
|
||||
export class Joint2D {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(JOINT2D));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(JOINT2D));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Joint2D.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
31
extensions/plugin-import-2x/creator/components/JsonAsset.ts
Normal file
31
extensions/plugin-import-2x/creator/components/JsonAsset.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
export const JSONASSET = {
|
||||
"__type__": "cc.JsonAsset",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"json": null,
|
||||
};
|
||||
|
||||
export class JsonAsset {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(JSONASSET));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(JSONASSET));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await JsonAsset.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
31
extensions/plugin-import-2x/creator/components/Keyframe.ts
Normal file
31
extensions/plugin-import-2x/creator/components/Keyframe.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
export const KEYFRAME = {
|
||||
"__type__": "cc.Keyframe",
|
||||
"time": 0,
|
||||
"value": 0,
|
||||
"inTangent": 0,
|
||||
"outTangent": 0,
|
||||
};
|
||||
|
||||
export class Keyframe {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(KEYFRAME));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(KEYFRAME));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Keyframe.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
100
extensions/plugin-import-2x/creator/components/Label.ts
Normal file
100
extensions/plugin-import-2x/creator/components/Label.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
import { getBlendFactor2DTo3D, setColor } from "../common/utlis";
|
||||
|
||||
export const LABEL = {
|
||||
"__type__": "cc.Label",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_customMaterial": null,
|
||||
"_visFlags": 0,
|
||||
"_srcBlendFactor": 2,
|
||||
"_dstBlendFactor": 4,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255,
|
||||
},
|
||||
"_useOriginalSize": true,
|
||||
"_string": "label",
|
||||
"_horizontalAlign": 1,
|
||||
"_verticalAlign": 1,
|
||||
"_actualFontSize": 0,
|
||||
"_fontSize": 40,
|
||||
"_fontFamily": "Arial",
|
||||
"_lineHeight": 40,
|
||||
"_overflow": 0,
|
||||
"_enableWrapText": true,
|
||||
"_font": null,
|
||||
"_isSystemFontUsed": true,
|
||||
"_isItalic": false,
|
||||
"_isBold": false,
|
||||
"_isUnderline": false,
|
||||
"_underlineHeight": 0,
|
||||
"_cacheMode": 0,
|
||||
};
|
||||
|
||||
export class Label {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(LABEL));
|
||||
}
|
||||
|
||||
static async migrate(index: number, json2D: any, json3D: any) {
|
||||
const source = JSON.parse(JSON.stringify(LABEL));
|
||||
const label = json2D[index];
|
||||
for (const key in label) {
|
||||
const value = label[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === 'node') {
|
||||
source.node = value;
|
||||
setColor(source, value.__id__, json2D);
|
||||
}
|
||||
else if (key === '_materials') {
|
||||
// for (let i = 0; i < value.length; ++i) {
|
||||
let material = value[0];
|
||||
if (material) {
|
||||
material = {
|
||||
__uuid__: await ImporterBase.getUuid(material.__uuid__),
|
||||
};
|
||||
}
|
||||
source._customMaterial = material;
|
||||
// }
|
||||
} else if (key === '_N$file') {
|
||||
source._font = {
|
||||
__uuid__: await ImporterBase.getUuid(value.__uuid__),
|
||||
};
|
||||
} else if (key === '_N$string') {
|
||||
source._string = value;
|
||||
} else if (key === '_N$fontFamily') {
|
||||
source._fontFamily = value;
|
||||
} else if (key === '_N$overflow') {
|
||||
source._overflow = value;
|
||||
} else if (key === '_N$cacheMode') {
|
||||
source._cacheMode = value;
|
||||
} else if (key === '_N$horizontalAlign') {
|
||||
source._horizontalAlign = value;
|
||||
} else if (key === '_N$verticalAlign') {
|
||||
source._verticalAlign = value;
|
||||
} else if (key === '_srcBlendFactor') {
|
||||
source._srcBlendFactor = getBlendFactor2DTo3D(value);
|
||||
} else if (key === '_dstBlendFactor') {
|
||||
source._dstBlendFactor = getBlendFactor2DTo3D(value);
|
||||
} else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Label.migrate(index, json2D, json3D);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
34
extensions/plugin-import-2x/creator/components/LabelAtlas.ts
Normal file
34
extensions/plugin-import-2x/creator/components/LabelAtlas.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
export const LABELATLAS = {
|
||||
"__type__": "cc.LabelAtlas",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"fntDataStr": "",
|
||||
"spriteFrame": null,
|
||||
"fontSize": -1,
|
||||
"fntConfig": null,
|
||||
};
|
||||
|
||||
export class LabelAtlas {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(LABELATLAS));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(LABELATLAS));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await LabelAtlas.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
import { setColor } from "../common/utlis";
|
||||
|
||||
export const LABELOUTLINE = {
|
||||
"__type__": "cc.LabelOutline",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 0,
|
||||
"g": 0,
|
||||
"b": 0,
|
||||
"a": 255,
|
||||
},
|
||||
"_width": 2,
|
||||
};
|
||||
|
||||
export class LabelOutline {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(LABELOUTLINE));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any, json3D: any) {
|
||||
const source = JSON.parse(JSON.stringify(LABELOUTLINE));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === 'node') {
|
||||
source.node = value;
|
||||
setColor(source, value.__id__, json2D);
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await LabelOutline.migrate(json2D[index], json3D);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
import { setColor } from "../common/utlis";
|
||||
|
||||
export const LABELSHADOW = {
|
||||
"__type__": "cc.LabelShadow",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 0,
|
||||
"g": 0,
|
||||
"b": 0,
|
||||
"a": 255,
|
||||
},
|
||||
"_offset": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 2,
|
||||
"y": 2,
|
||||
},
|
||||
"_blur": 2,
|
||||
};
|
||||
|
||||
export class LabelShadow {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(LABELSHADOW));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any, json3D: any) {
|
||||
const source = JSON.parse(JSON.stringify(LABELSHADOW));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === 'node') {
|
||||
source.node = value;
|
||||
setColor(source, value.__id__, json2D);
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await LabelShadow.migrate(json2D[index], json3D);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
59
extensions/plugin-import-2x/creator/components/Layout.ts
Normal file
59
extensions/plugin-import-2x/creator/components/Layout.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
export const LAYOUT = {
|
||||
"__type__": "cc.Layout",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_resizeMode": 0,
|
||||
"_N$layoutType": 0,
|
||||
"_N$padding": 0,
|
||||
"_cellSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 40,
|
||||
"height": 40,
|
||||
},
|
||||
"_startAxis": 0,
|
||||
"_paddingLeft": 0,
|
||||
"_paddingRight": 0,
|
||||
"_paddingTop": 0,
|
||||
"_paddingBottom": 0,
|
||||
"_spacingX": 0,
|
||||
"_spacingY": 0,
|
||||
"_verticalDirection": 1,
|
||||
"_horizontalDirection": 0,
|
||||
"_affectedByScale": false,
|
||||
};
|
||||
|
||||
export class Layout {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(LAYOUT));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(LAYOUT));
|
||||
for (let key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key.startsWith('_N$')) {
|
||||
key = key.replace(/N\$/, '');
|
||||
}
|
||||
if (key === '_padding') {
|
||||
source._paddingLeft = source._paddingRight = source._paddingTop = source._paddingBottom = value;
|
||||
} else if (key === '_resize') {
|
||||
source._resizeMode = value;
|
||||
} else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Layout.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
51
extensions/plugin-import-2x/creator/components/Light.ts
Normal file
51
extensions/plugin-import-2x/creator/components/Light.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
import { StaticLightSettings } from "./StaticLightSettings";
|
||||
|
||||
export const LIGHT = {
|
||||
"__type__": "cc.Light",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255,
|
||||
},
|
||||
"_useColorTemperature": false,
|
||||
"_colorTemperature": 6550,
|
||||
"_staticSettings": {
|
||||
"__id__": 1,
|
||||
},
|
||||
};
|
||||
|
||||
export class Light {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(LIGHT));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(LIGHT));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Light.migrate(json2D[index]);
|
||||
const settings = StaticLightSettings.create();
|
||||
json3D.push(settings);
|
||||
source._staticSettings = {
|
||||
__id__: json3D.length - 1,
|
||||
};
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
export const LIMITVELOCITYOVERTIMEMODULE = {
|
||||
"__type__": "cc.LimitVelocityOvertimeModule",
|
||||
"_enable": false,
|
||||
"limitX": {
|
||||
"__id__": 1,
|
||||
},
|
||||
"limitY": {
|
||||
"__id__": 2,
|
||||
},
|
||||
"limitZ": {
|
||||
"__id__": 3,
|
||||
},
|
||||
"limit": {
|
||||
"__id__": 4,
|
||||
},
|
||||
"dampen": 3,
|
||||
"separateAxes": false,
|
||||
"space": 1,
|
||||
};
|
||||
|
||||
export class LimitVelocityOvertimeModule {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(LIMITVELOCITYOVERTIMEMODULE));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(LIMITVELOCITYOVERTIMEMODULE));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await LimitVelocityOvertimeModule.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
51
extensions/plugin-import-2x/creator/components/Line.ts
Normal file
51
extensions/plugin-import-2x/creator/components/Line.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
export const LINE = {
|
||||
"__type__": "cc.Line",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_texture": null,
|
||||
"_worldSpace": false,
|
||||
"_positions": [],
|
||||
"_width": {
|
||||
"__id__": 1,
|
||||
},
|
||||
"_tile": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
},
|
||||
"_offset": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"_color": {
|
||||
"__id__": 2,
|
||||
},
|
||||
};
|
||||
|
||||
export class Line {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(LINE));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(LINE));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Line.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
84
extensions/plugin-import-2x/creator/components/Mask.ts
Normal file
84
extensions/plugin-import-2x/creator/components/Mask.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
import { getBlendFactor2DTo3D, setColor } from "../common/utlis";
|
||||
|
||||
export const MASK = {
|
||||
"__type__": "cc.Mask",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_materials": [],
|
||||
"_visFlags": 0,
|
||||
"_srcBlendFactor": 2,
|
||||
"_dstBlendFactor": 4,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255,
|
||||
},
|
||||
"_type": 0,
|
||||
"_inverted": false,
|
||||
"_segments": 64,
|
||||
"_spriteFrame": null,
|
||||
"_alphaThreshold": 0.1,
|
||||
};
|
||||
|
||||
export class Mask {
|
||||
|
||||
static typeTo2D(type: number) {
|
||||
switch (type) {
|
||||
case 2: // IMAGE_STENCIL
|
||||
return 3; // IMAGE_STENCIL
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(MASK));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(MASK));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === 'node') {
|
||||
source.node = value;
|
||||
setColor(source, value.__id__, json2D);
|
||||
}
|
||||
else if (key === '_type') {
|
||||
source._type = Mask.typeTo2D(value);
|
||||
}
|
||||
else if (key === '_N$alphaThreshold') {
|
||||
source._alphaThreshold = value;
|
||||
}
|
||||
else if (key === '_spriteFrame') {
|
||||
source._spriteFrame = {
|
||||
__uuid__: await ImporterBase.getUuid(value.__uuid__, 'spriteFrame'),
|
||||
};
|
||||
}
|
||||
else if (key === '_N$inverted') {
|
||||
source._inverted = value;
|
||||
} else if (key === '_srcBlendFactor') {
|
||||
source._srcBlendFactor = getBlendFactor2DTo3D(value);
|
||||
} else if (key === '_dstBlendFactor') {
|
||||
source._dstBlendFactor = getBlendFactor2DTo3D(value);
|
||||
} else if (key === '_materials') {
|
||||
source._materials = [];
|
||||
} else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Mask.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
77
extensions/plugin-import-2x/creator/components/Material.ts
Normal file
77
extensions/plugin-import-2x/creator/components/Material.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
|
||||
export const MATERIAL = {
|
||||
"__type__": "cc.Material",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"_effectAsset": null,
|
||||
"_techIdx": 0,
|
||||
"_defines": [],
|
||||
"_states": [],
|
||||
"_props": [],
|
||||
};
|
||||
|
||||
export class Material {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(MATERIAL));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(MATERIAL));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === '_effectAsset') {
|
||||
source._effectAsset = {
|
||||
"__uuid__": await ImporterBase.getUuid(json2D._effectAsset.__uuid__),
|
||||
};
|
||||
}
|
||||
else if (key === '_techniqueData') {
|
||||
for (const key in json2D._techniqueData) {
|
||||
const data = json2D._techniqueData[key];
|
||||
if (data.defines) {
|
||||
const defines: any = {};
|
||||
for (let defineKey in data.defines) {
|
||||
let va = data.defines[defineKey];
|
||||
if (defineKey === 'USE_DIFFUSE_TEXTURE') {
|
||||
defineKey = 'USE_TEXTURE';
|
||||
}
|
||||
defines[defineKey] = va;
|
||||
}
|
||||
source._defines.push(defines);
|
||||
}
|
||||
if (data.props) {
|
||||
const props: any = {};
|
||||
for (let propKey in data.props) {
|
||||
const value = data.props[propKey];
|
||||
if (propKey === 'mainTexture' || propKey === 'texture' || propKey === 'diffuseTexture') {
|
||||
// 由于 texture 是关键字,所有都改成 mainTexture
|
||||
propKey = 'mainTexture';
|
||||
props[propKey] = {
|
||||
__uuid__: await ImporterBase.getUuid(value.__uuid__, 'texture'),
|
||||
};
|
||||
}
|
||||
else {
|
||||
props[propKey] = value;
|
||||
}
|
||||
}
|
||||
data.props && source._props.push(props);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Material.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
36
extensions/plugin-import-2x/creator/components/Mesh.ts
Normal file
36
extensions/plugin-import-2x/creator/components/Mesh.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
export const MESH = {
|
||||
"__type__": "cc.Mesh",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"_struct": {
|
||||
"vertexBundles": [],
|
||||
"primitives": [],
|
||||
},
|
||||
"_dataLength": 0,
|
||||
"_hash": 0,
|
||||
};
|
||||
|
||||
export class Mesh {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(MESH));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(MESH));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Mesh.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
|
||||
export const MESHCOLLIDER = {
|
||||
"__type__": "cc.MeshCollider",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_material": null,
|
||||
"_isTrigger": false,
|
||||
"_center": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
"_mesh": null,
|
||||
"_convex": false,
|
||||
};
|
||||
|
||||
export class MeshCollider {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(MESHCOLLIDER));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(MESHCOLLIDER));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === '_materials') {
|
||||
source._materials = [];
|
||||
for (let i = 0; i < value.length; ++i) {
|
||||
let material = value[0];
|
||||
if (material) {
|
||||
material = {
|
||||
__uuid__: await ImporterBase.getUuid(material.__uuid__),
|
||||
};
|
||||
source._materials.push(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (key === '_mesh') {
|
||||
source._mesh = {
|
||||
__uuid__: await ImporterBase.getUuid(value.__uuid__),
|
||||
};
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await MeshCollider.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
import { ModelLightmapSettings } from "./ModelLightmapSettings";
|
||||
|
||||
export const MESHRENDERER = {
|
||||
"__type__": "cc.MeshRenderer",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_materials": [],
|
||||
"_visFlags": 0,
|
||||
"lightmapSettings": null,
|
||||
"_mesh": null,
|
||||
"_shadowCastingMode": 0,
|
||||
"_shadowReceivingMode": 1,
|
||||
"_enableMorph": true,
|
||||
};
|
||||
|
||||
export class MeshRenderer {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(MESHRENDERER));
|
||||
}
|
||||
|
||||
static async migrate(index: any, json2D: any) {
|
||||
const json = json2D[index];
|
||||
const source = JSON.parse(JSON.stringify(MESHRENDERER));
|
||||
for (const key in json) {
|
||||
const value = json[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === '_materials') {
|
||||
source._materials = [];
|
||||
for (let i = 0; i < value.length; ++i) {
|
||||
let material = value[0];
|
||||
if (material) {
|
||||
material = {
|
||||
__uuid__: await ImporterBase.getUuid(material.__uuid__),
|
||||
};
|
||||
source._materials.push(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (key === '_receiveShadows') {
|
||||
// 1 = ON, 0 = OFF
|
||||
source._shadowReceivingMode = value === 'true' ? 1 : 0;
|
||||
}
|
||||
else if (key === '_mesh') {
|
||||
source._mesh = {
|
||||
__uuid__: await ImporterBase.getUuid(value.__uuid__),
|
||||
};
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await MeshRenderer.migrate(index, json2D);
|
||||
const modelLightmapSettings = ModelLightmapSettings.create();
|
||||
json3D.push(modelLightmapSettings);
|
||||
source.lightmapSettings = {
|
||||
__id__: json3D.length - 1,
|
||||
};
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
422
extensions/plugin-import-2x/creator/components/MigrateManager.ts
Normal file
422
extensions/plugin-import-2x/creator/components/MigrateManager.ts
Normal file
@@ -0,0 +1,422 @@
|
||||
import { Animation } from "./Animation";
|
||||
import { AnimationClip } from "./AnimationClip";
|
||||
import { Asset } from "./Asset";
|
||||
import { AudioClip } from "./AudioClip";
|
||||
import { AudioSource } from "./AudioSource";
|
||||
import { ArmatureDisplay } from "./ArmatureDisplay";// dragonBones.ArmatureDisplay
|
||||
import { BaseNode } from "./BaseNode";
|
||||
import { Billboard } from "./Billboard";
|
||||
import { BitmapFont } from "./BitmapFont";
|
||||
import { BlockInputEvents } from "./BlockInputEvents";
|
||||
import { BoxCollider } from "./BoxCollider";
|
||||
import { BoxCollider2D } from "./BoxCollider2D";
|
||||
import { BufferAsset } from "./BufferAsset";
|
||||
import { Button } from "./Button";
|
||||
import { Camera } from "./Camera";
|
||||
import { Canvas } from "./Canvas";
|
||||
import { CapsuleCollider } from "./CapsuleCollider";
|
||||
import { CircleCollider2D } from "./CircleCollider2D";
|
||||
import { Collider } from "./Collider";
|
||||
import { Collider2D } from "./Collider2D";
|
||||
import { CompPrefabInfo } from "./CompPrefabInfo";
|
||||
import { CompactValueTypeArray } from "./CompactValueTypeArray";
|
||||
import { Component } from "./Component";
|
||||
import { ComponentModifier } from "./ComponentModifier";
|
||||
import { ConeCollider } from "./ConeCollider";
|
||||
import { ConstantForce } from "./ConstantForce";
|
||||
import { Constraint } from "./Constraint";
|
||||
import { CubicSplineNumberValue } from "./CubicSplineNumberValue";
|
||||
import { CubicSplineValueClass } from "./CubicSplineValueClass";
|
||||
import { CurveRange } from "./CurveRange";
|
||||
import { CurveValueAdapter } from "./CurveValueAdapter";
|
||||
import { CylinderCollider } from "./CylinderCollider";
|
||||
import { DirectionalLight } from "./DirectionalLight";
|
||||
import { DistanceJoint2D } from "./DistanceJoint2D";
|
||||
import { EditBox } from "./EditBox";
|
||||
import { EffectAsset } from "./EffectAsset";
|
||||
import { EventHandler } from "./EventHandler";
|
||||
import { FixedJoint2D } from "./FixedJoint2D";
|
||||
import { Font } from "./Font";
|
||||
import { ForwardFlow } from "./ForwardFlow";
|
||||
import { ForwardPipeline } from "./ForwardPipeline";
|
||||
import { ForwardStage } from "./ForwardStage";
|
||||
import { Graphics } from "./Graphics";
|
||||
import { HierachyModifier } from "./HierachyModifier";
|
||||
import { HingeConstraint } from "./HingeConstraint";
|
||||
import { HingeJoint2D } from "./HingeJoint2D";
|
||||
import { ImageAsset } from "./ImageAsset";
|
||||
import { JavaScript } from "./JavaScript";
|
||||
import { Joint2D } from "./Joint2D";
|
||||
import { JsonAsset } from "./JsonAsset";
|
||||
import { Label } from "./Label";
|
||||
import { LabelAtlas } from "./LabelAtlas";
|
||||
import { LabelOutline } from "./LabelOutline";
|
||||
import { LabelShadow } from "./LabelShadow";
|
||||
import { Layout } from "./Layout";
|
||||
import { Light } from "./Light";
|
||||
import { Line } from "./Line";
|
||||
import { Mask } from "./Mask";
|
||||
import { Material } from "./Material";
|
||||
import { Mesh } from "./Mesh";
|
||||
import { MeshCollider } from "./MeshCollider";
|
||||
import { MeshRenderer } from "./MeshRenderer";
|
||||
import { ModelLightmapSettings } from "./ModelLightmapSettings";
|
||||
import { MissingScript } from "./MissingScript";
|
||||
import { MotionStreak } from "./MotionStreak";
|
||||
import { MouseJoint2D } from "./MouseJoint2D";
|
||||
import { Node } from "./Node";
|
||||
import { PageView } from "./PageView";
|
||||
import { PageViewIndicator } from "./PageViewIndicator";
|
||||
import { ParticleAsset } from "./ParticleAsset";
|
||||
import { ParticleSystem } from "./ParticleSystem";
|
||||
import { ParticleSystem2D } from "./ParticleSystem2D";
|
||||
import { PhysicsMaterial } from "./PhysicsMaterial";
|
||||
import { PlaneCollider } from "./PlaneCollider";
|
||||
import { PointToPointConstraint } from "./PointToPointConstraint";
|
||||
import { PolygonCollider2D } from "./PolygonCollider2D";
|
||||
import { Prefab } from "./Prefab";
|
||||
import { PrefabInfo } from "./PrefabInfo";
|
||||
import { Primitive } from "./Primitive";
|
||||
import { PrivateNode } from "./PrivateNode";
|
||||
import { ProgressBar } from "./ProgressBar";
|
||||
import { RawAsset } from "./RawAsset";
|
||||
import { RelativeJoint2D } from "./RelativeJoint2D";
|
||||
import { RenderFlow } from "./RenderFlow";
|
||||
import { RenderPipeline } from "./RenderPipeline";
|
||||
import { RenderStage } from "./RenderStage";
|
||||
import { RenderTexture } from "./RenderTexture";
|
||||
import { RenderableComponent } from "./RenderableComponent";
|
||||
import { RichText } from "./RichText";
|
||||
import { RigidBody } from "./RigidBody";
|
||||
import { RigidBody2D } from "./RigidBody2D";
|
||||
import { SafeArea } from "./SafeArea";
|
||||
import { Scene } from "./Scene";
|
||||
import { SceneAsset } from "./SceneAsset";
|
||||
import { Script } from "./Script";
|
||||
import { Scrollbar } from "./ScrollBar";
|
||||
import { ScrollView } from "./ScrollView";
|
||||
import { ShadowFlow } from "./ShadowFlow";
|
||||
import { ShadowStage } from "./ShadowStage";
|
||||
import { SimplexCollider } from "./SimplexCollider";
|
||||
import { Skeleton } from "./Skeleton";
|
||||
import { SkeletalAnimation } from "./SkeletalAnimation";
|
||||
import { SkinnedMeshBatchRenderer } from "./SkinnedMeshBatchRenderer";
|
||||
import { SkinnedMeshRenderer } from "./SkinnedMeshRenderer";
|
||||
import { SkinnedMeshUnit } from "./SkinnedMeshUnit";
|
||||
import { Slider } from "./Slider";
|
||||
import { SliderJoint2D } from "./SliderJoint2D";
|
||||
import { SphereCollider } from "./SphereCollider";
|
||||
import { SphereLight } from "./SphereLight";
|
||||
import { SpotLight } from "./SpotLight";
|
||||
import { SpringJoint2D } from "./SpringJoint2D";
|
||||
import { Sprite } from "./Sprite";
|
||||
import { SpriteAtlas } from "./SpriteAtlas";
|
||||
import { SpriteFrame } from "./SpriteFrame";
|
||||
import { SubContextView } from "./SubContextView";
|
||||
import { TTFFont } from "./TTFFont";
|
||||
import { TextAsset } from "./TextAsset";
|
||||
import { Texture2D } from "./Texture2D";
|
||||
import { TextureCube } from "./TextureCube";
|
||||
import { TiledLayer } from "./TiledLayer";
|
||||
import { TiledMap } from "./TiledMap";
|
||||
import { TiledMapAsset } from "./TiledMapAsset";
|
||||
import { TiledObjectGroup } from "./TiledObjectGroup";
|
||||
import { TiledTile } from "./TiledTile";
|
||||
import { TiledUserNodeData } from "./TiledUserNodeData";
|
||||
import { Toggle } from "./Toggle";
|
||||
import { ToggleContainer } from "./ToggleContainer";
|
||||
import { TypeScript } from "./TypeScript";
|
||||
import { UIComponent } from "./UIComponent";
|
||||
import { UICoordinateTracker } from "./UICoordinateTracker";
|
||||
import { UIMeshRenderer } from "./UIMeshRenderer";
|
||||
import { UIOpacity } from "./UIOpacity";
|
||||
import { UIRenderable } from "./UIRenderable";
|
||||
import { UIReorderComponent } from "./UIReorderComponent";
|
||||
import { UIStaticBatch } from "./UIStaticBatch";
|
||||
import { UITransform } from "./UITransform";
|
||||
import { UniformCurveValueAdapter } from "./UniformCurveValueAdapter";
|
||||
import { VideoClip } from "./VideoClip";
|
||||
import { VideoPlayer } from "./VideoPlayer";
|
||||
import { ViewGroup } from "./ViewGroup";
|
||||
import { WebView } from "./WebView";
|
||||
import { WheelJoint2D } from "./WheelJoint2D";
|
||||
import { Widget } from "./Widget";
|
||||
import { AnimationCurve } from "./AnimationCurve";
|
||||
import { Keyframe } from "./Keyframe";
|
||||
import { AlphaKey } from "./AlphaKey";
|
||||
import { Gradient } from "./Gradient";
|
||||
import { GradientRange } from "./GradientRange";
|
||||
import { Burst } from "./Burst";
|
||||
import { ShapeModule } from "./ShapeModule";
|
||||
import { ColorOvertimeModule } from "./ColorOvertimeModule";
|
||||
import { SizeOvertimeModule } from "./SizeOvertimeModule";
|
||||
import { VelocityOvertimeModule } from "./VelocityOvertimeModule";
|
||||
import { ForceOvertimeModule } from "./ForceOvertimeModule";
|
||||
import { LimitVelocityOvertimeModule } from "./LimitVelocityOvertimeModule";
|
||||
import { RotationOvertimeModule } from "./RotationOvertimeModule";
|
||||
import { TextureAnimationModule } from "./TextureAnimationModule";
|
||||
import { ColorKey } from "./ColorKey";
|
||||
import { TrailModule } from "./TrailModule";
|
||||
import { ImporterBase } from "../common/base";
|
||||
import { Sp_Skeleton } from "./SpSkeleton";
|
||||
import { StudioComponent } from "./StudioComponent";
|
||||
import { StudioWidget } from "./StudioWidget";
|
||||
import { getBlendFactor2DTo3D, getColor } from "../common/utlis";
|
||||
|
||||
const CCCLASS_LIST = {
|
||||
'cc.Animation': Animation,
|
||||
'cc.AnimationClip': AnimationClip,
|
||||
'cc.AnimationCurve': AnimationCurve,
|
||||
'cc.Asset': Asset,
|
||||
'cc.AlphaKey': AlphaKey,
|
||||
'cc.AudioClip': AudioClip,
|
||||
'cc.AudioSource': AudioSource,
|
||||
'cc.Burst': Burst,
|
||||
'cc.Button': Button,
|
||||
'cc.BaseNode': BaseNode,
|
||||
'cc.Billboard': Billboard,
|
||||
'cc.BitmapFont': BitmapFont,
|
||||
'cc.BoxCollider2D': BoxCollider2D,
|
||||
'cc.BlockInputEvents': BlockInputEvents,
|
||||
'cc.BufferAsset': BufferAsset,
|
||||
'cc.BoxCollider': BoxCollider,
|
||||
'cc.ColorKey': ColorKey,
|
||||
'cc.Camera': Camera,
|
||||
'cc.Canvas': Canvas,
|
||||
'cc.CapsuleCollider': CapsuleCollider,
|
||||
'cc.CircleCollider2D': CircleCollider2D,
|
||||
'cc.Collider': Collider,
|
||||
'cc.Collider2D': Collider2D,
|
||||
'cc.CompPrefabInfo': CompPrefabInfo,
|
||||
'cc.CompactValueTypeArray': CompactValueTypeArray,
|
||||
'cc.Component': Component,
|
||||
'cc.ComponentModifier': ComponentModifier,
|
||||
'cc.ConeCollider': ConeCollider,
|
||||
'cc.ConstantForce': ConstantForce,
|
||||
'cc.Constraint': Constraint,
|
||||
'cc.CubicSplineNumberValue': CubicSplineNumberValue,
|
||||
'cc.CubicSplineValueClass': CubicSplineValueClass,
|
||||
'cc.CurveRange': CurveRange,
|
||||
'cc.CurveValueAdapter': CurveValueAdapter,
|
||||
'cc.CylinderCollider': CylinderCollider,
|
||||
'cc.ColorOvertimeModule': ColorOvertimeModule,
|
||||
'cc.DirectionalLight': DirectionalLight,
|
||||
'cc.DistanceJoint2D': DistanceJoint2D,
|
||||
'cc.EditBox': EditBox,
|
||||
'cc.EffectAsset': EffectAsset,
|
||||
'cc.EventHandler': EventHandler,
|
||||
'cc.FixedJoint2D': FixedJoint2D,
|
||||
'cc.Font': Font,
|
||||
'cc.ForwardFlow': ForwardFlow,
|
||||
'cc.ForwardPipeline': ForwardPipeline,
|
||||
'cc.ForwardStage': ForwardStage,
|
||||
'cc.ForceOvertimeModule': ForceOvertimeModule,
|
||||
'cc.Graphics': Graphics,
|
||||
'cc.Gradient': Gradient,
|
||||
'cc.GradientRange': GradientRange,
|
||||
'cc.HierachyModifier': HierachyModifier,
|
||||
'cc.HingeConstraint': HingeConstraint,
|
||||
'cc.HingeJoint2D': HingeJoint2D,
|
||||
'cc.ImageAsset': ImageAsset,
|
||||
'cc.JavaScript': JavaScript,
|
||||
'cc.Joint2D': Joint2D,
|
||||
'cc.JsonAsset': JsonAsset,
|
||||
'cc.Keyframe': Keyframe,
|
||||
'cc.Label': Label,
|
||||
'cc.LabelAtlas': LabelAtlas,
|
||||
'cc.LabelOutline': LabelOutline,
|
||||
'cc.LabelShadow': LabelShadow,
|
||||
'cc.Layout': Layout,
|
||||
'cc.Light': Light,
|
||||
'cc.Line': Line,
|
||||
'cc.LimitVelocityOvertimeModule': LimitVelocityOvertimeModule,
|
||||
'cc.Mask': Mask,
|
||||
'cc.Material': Material,
|
||||
'cc.Mesh': Mesh,
|
||||
'cc.MeshCollider': MeshCollider,
|
||||
'cc.MeshRenderer': MeshRenderer,
|
||||
'cc.ModelLightmapSettings': ModelLightmapSettings,
|
||||
'cc.MissingScript': MissingScript,
|
||||
'cc.MotionStreak': MotionStreak,
|
||||
'cc.MouseJoint2D': MouseJoint2D,
|
||||
'cc.Node': Node,
|
||||
'cc.PageView': PageView,
|
||||
'cc.PageViewIndicator': PageViewIndicator,
|
||||
'cc.ParticleAsset': ParticleAsset,
|
||||
'cc.ParticleSystem': ParticleSystem,
|
||||
'cc.ParticleSystem2D': ParticleSystem2D,
|
||||
'cc.PhysicsMaterial': PhysicsMaterial,
|
||||
'cc.PlaneCollider': PlaneCollider,
|
||||
'cc.PointToPointConstraint': PointToPointConstraint,
|
||||
'cc.PolygonCollider2D': PolygonCollider2D,
|
||||
'cc.Prefab': Prefab,
|
||||
'cc.PrefabInfo': PrefabInfo,
|
||||
'cc.Primitive': Primitive,
|
||||
'cc.PrivateNode': PrivateNode,
|
||||
'cc.ProgressBar': ProgressBar,
|
||||
'cc.RawAsset': RawAsset,
|
||||
'cc.RenderFlow': RenderFlow,
|
||||
'cc.RenderStage': RenderStage,
|
||||
'cc.RichText': RichText,
|
||||
'cc.RigidBody': RigidBody,
|
||||
'cc.RigidBody2D': RigidBody2D,
|
||||
'cc.RenderTexture': RenderTexture,
|
||||
'cc.RenderPipeline': RenderPipeline,
|
||||
'cc.RelativeJoint2D': RelativeJoint2D,
|
||||
'cc.RenderableComponent': RenderableComponent,
|
||||
'cc.RotationOvertimeModule': RotationOvertimeModule,
|
||||
'cc.ShapeModule': ShapeModule,
|
||||
'cc.SafeArea': SafeArea,
|
||||
'cc.Scene': Scene,
|
||||
'cc.SceneAsset': SceneAsset,
|
||||
'cc.Script': Script,
|
||||
'cc.Scrollbar': Scrollbar,
|
||||
'cc.ScrollView': ScrollView,
|
||||
'cc.ShadowFlow': ShadowFlow,
|
||||
'cc.ShadowStage': ShadowStage,
|
||||
'cc.SimplexCollider': SimplexCollider,
|
||||
'cc.Skeleton': Skeleton,
|
||||
'cc.SkeletalAnimation': SkeletalAnimation,
|
||||
'cc.SkinnedMeshBatchRenderer': SkinnedMeshBatchRenderer,
|
||||
'cc.SkinnedMeshRenderer': SkinnedMeshRenderer,
|
||||
'cc.SkinnedMeshUnit': SkinnedMeshUnit,
|
||||
'cc.Slider': Slider,
|
||||
'cc.SliderJoint2D': SliderJoint2D,
|
||||
'cc.SphereCollider': SphereCollider,
|
||||
'cc.SphereLight': SphereLight,
|
||||
'cc.SpotLight': SpotLight,
|
||||
'cc.SpringJoint2D': SpringJoint2D,
|
||||
'cc.Sprite': Sprite,
|
||||
'cc.SpriteAtlas': SpriteAtlas,
|
||||
'cc.SpriteFrame': SpriteFrame,
|
||||
'cc.SubContextView': SubContextView,
|
||||
'cc.SizeOvertimeModule': SizeOvertimeModule,
|
||||
'cc.TTFFont': TTFFont,
|
||||
'cc.TextAsset': TextAsset,
|
||||
'cc.Texture2D': Texture2D,
|
||||
'cc.TextureCube': TextureCube,
|
||||
'cc.TiledLayer': TiledLayer,
|
||||
'cc.TiledMap': TiledMap,
|
||||
'cc.TiledMapAsset': TiledMapAsset,
|
||||
'cc.TiledObjectGroup': TiledObjectGroup,
|
||||
'cc.TiledTile': TiledTile,
|
||||
'cc.TiledUserNodeData': TiledUserNodeData,
|
||||
'cc.Toggle': Toggle,
|
||||
'cc.ToggleContainer': ToggleContainer,
|
||||
'cc.TypeScript': TypeScript,
|
||||
'cc.TextureAnimationModule': TextureAnimationModule,
|
||||
'cc.TrailModule': TrailModule,
|
||||
'cc.UIComponent': UIComponent,
|
||||
'cc.UICoordinateTracker': UICoordinateTracker,
|
||||
'cc.UIMeshRenderer': UIMeshRenderer,
|
||||
'cc.UIOpacity': UIOpacity,
|
||||
'cc.UIRenderable': UIRenderable,
|
||||
'cc.UIReorderComponent': UIReorderComponent,
|
||||
'cc.UIStaticBatch': UIStaticBatch,
|
||||
'cc.UITransform': UITransform,
|
||||
'cc.UniformCurveValueAdapter': UniformCurveValueAdapter,
|
||||
'cc.VideoClip': VideoClip,
|
||||
'cc.VideoPlayer': VideoPlayer,
|
||||
'cc.ViewGroup': ViewGroup,
|
||||
'cc.VelocityOvertimeModule': VelocityOvertimeModule,
|
||||
'cc.WebView': WebView,
|
||||
'cc.WheelJoint2D': WheelJoint2D,
|
||||
'cc.Widget': Widget,
|
||||
'dragonBones.ArmatureDisplay': ArmatureDisplay,
|
||||
'sp.Skeleton': Sp_Skeleton,
|
||||
'cc.StudioComponent': StudioComponent,
|
||||
'cc.StudioWidget': StudioWidget,
|
||||
};
|
||||
|
||||
const RENAME_COMPONENT: any = {
|
||||
'cc.BoxCollider3D': 'cc.BoxCollider',
|
||||
'cc.BoxCollider': 'cc.BoxCollider2D',
|
||||
'cc.PhysicsBoxCollider': 'cc.BoxCollider2D',
|
||||
'cc.CircleCollider': 'cc.CircleCollider2D',
|
||||
'cc.PhysicsCircleCollider': 'cc.CircleCollider2D',
|
||||
'cc.Collider': 'cc.Collider2D',
|
||||
'cc.PhysicsCollider': 'cc.Collider2D',
|
||||
'cc.PhysicsChainCollider': 'cc.Collider2D',
|
||||
'cc.Collider3D': 'cc.Collider',
|
||||
'cc.DistanceJoint': 'cc.DistanceJoint2D',
|
||||
'cc.ClickEvent': 'cc.EventHandler',
|
||||
'cc.MouseJoint': 'cc.MouseJoint2D',
|
||||
'cc.WheelJoint': 'cc.WheelJoint2D',
|
||||
'cc.PolygonCollider': 'cc.PolygonCollider2D',
|
||||
'cc.PhysicsPolygonCollider': 'cc.PolygonCollider2D',
|
||||
'cc.ParticleSystem': 'cc.ParticleSystem2D',
|
||||
'cc.ParticleSystem3D': 'cc.ParticleSystem',
|
||||
'cc.Joint': 'cc.Joint2D',
|
||||
'cc.RigidBody': 'cc.RigidBody2D',
|
||||
'cc.RigidBody3D': 'cc.RigidBody',
|
||||
'cc.SphereCollider3D': 'cc.SphereCollider',
|
||||
'cc.RenderComponent': 'cc.UIRenderable',
|
||||
'cc.SkeletonAnimation': 'cc.SkeletalAnimation',
|
||||
'cc.StudioWidget': 'cc.Widget',
|
||||
};
|
||||
|
||||
export class MigrateManager {
|
||||
static logs: string[] = [];
|
||||
|
||||
static async migrate(index: number, json2D: any, json3D: any) {
|
||||
const element2D = json2D[index];
|
||||
let type = element2D.__type__ || element2D[0].__type__;// 粒子存的是数组
|
||||
|
||||
if (type === 'cc.Light') {
|
||||
switch (element2D._type) {
|
||||
case 0:
|
||||
type = 'cc.DirectionalLight';
|
||||
break;
|
||||
case 1:
|
||||
type = 'cc.PointLight';
|
||||
break;
|
||||
case 2:
|
||||
type = 'cc.SpotLight';
|
||||
break;
|
||||
case 3:// 环境不支持,已导入到场景中,而且实现也不一样
|
||||
break;
|
||||
}
|
||||
}
|
||||
const renameTyep = RENAME_COMPONENT[type];
|
||||
if (renameTyep) {
|
||||
type = renameTyep;
|
||||
}
|
||||
// @ts-ignore
|
||||
const CCClass = CCCLASS_LIST[type];
|
||||
if (CCClass) {
|
||||
return await CCClass.apply(index, json2D, json3D);
|
||||
}
|
||||
else {
|
||||
if (type.startsWith('cc.')) {
|
||||
if (!MigrateManager.logs.includes(type)) {
|
||||
MigrateManager.logs.push(type);
|
||||
}
|
||||
// console.log('未适配类型:' + type + ' ' + index);
|
||||
}
|
||||
let source: any = {};
|
||||
for (const key in element2D) {
|
||||
let value = element2D[key];
|
||||
if (value && value.__uuid__) {
|
||||
value.__uuid__ = await ImporterBase.getUuid(value.__uuid__);
|
||||
}
|
||||
else if (key === '_srcBlendFactor' || key === '_dstBlendFactor') {
|
||||
value = getBlendFactor2DTo3D(value);
|
||||
if (!source._color) {
|
||||
source._color = getColor(json2D[element2D.node.__id__]);
|
||||
}
|
||||
}
|
||||
source[key] = value;
|
||||
}
|
||||
let content = JSON.stringify(source, undefined, 2);
|
||||
const __uuids__ = content.match(/(?<=__uuid__": ")(.*)(?=")/g) || [];
|
||||
for (let uuid of __uuids__) {
|
||||
const oldUuid = uuid;
|
||||
uuid = await ImporterBase.getUuid(uuid) as string;
|
||||
content = content.replace(oldUuid, uuid);
|
||||
}
|
||||
source = JSON.parse(content);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
export const MISSINGSCRIPT = {
|
||||
"__type__": "cc.MissingScript",
|
||||
};
|
||||
|
||||
export class MissingScript {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(MISSINGSCRIPT));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(MISSINGSCRIPT));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await MissingScript.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
export const MODELLIGHTMAPSETTINGS = {
|
||||
"__type__": "cc.ModelLightmapSettings",
|
||||
"texture": null,
|
||||
"uvParam": {
|
||||
"__type__": "cc.Vec4",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 0,
|
||||
},
|
||||
"_bakeable": false,
|
||||
"_castShadow": false,
|
||||
"_receiveShadow": false,
|
||||
"_recieveShadow": false,
|
||||
"_lightmapSize": 64,
|
||||
};
|
||||
|
||||
export class ModelLightmapSettings {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(MODELLIGHTMAPSETTINGS));
|
||||
}
|
||||
|
||||
static async migrate(index: any, json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(MODELLIGHTMAPSETTINGS));
|
||||
const json = json2D[index];
|
||||
for (const key in json) {
|
||||
const value = json[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await ModelLightmapSettings.migrate(index, json2D);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
'use strict';
|
||||
import { getBlendFactor2DTo3D } from "../common/utlis";
|
||||
import { ImporterBase } from "../common/base";
|
||||
|
||||
export const MOTIONSTREAK = {
|
||||
"__type__": "cc.MotionStreak",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_materials": [],
|
||||
"_visFlags": 0,
|
||||
"_srcBlendFactor": 2,
|
||||
"_dstBlendFactor": 4,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255,
|
||||
},
|
||||
"_preview": false,
|
||||
"_fadeTime": 1,
|
||||
"_minSeg": 1,
|
||||
"_stroke": 64,
|
||||
"_texture": null,
|
||||
"_fastMode": false,
|
||||
};
|
||||
|
||||
export class MotionStreak {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(MOTIONSTREAK));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(MOTIONSTREAK));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === '_srcBlendFactor') {
|
||||
source._srcBlendFactor = getBlendFactor2DTo3D(value);
|
||||
} else if (key === '_dstBlendFactor') {
|
||||
source._dstBlendFactor = getBlendFactor2DTo3D(value);
|
||||
} else if (key === '_texture') {
|
||||
source._texture = {
|
||||
__uuid__: await ImporterBase.getUuid(value.__uuid__, 'texture'),
|
||||
};
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await MotionStreak.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
export const MOUSEJOINT2D = {
|
||||
"__type__": "cc.MouseJoint2D",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"anchor": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"connectedAnchor": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"collideConnected": false,
|
||||
"connectedBody": null,
|
||||
"_maxForce": 1000,
|
||||
"_dampingRatio": 0.7,
|
||||
"_frequency": 5,
|
||||
};
|
||||
|
||||
export class MouseJoint2D {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(MOUSEJOINT2D));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(MOUSEJOINT2D));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await MouseJoint2D.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
152
extensions/plugin-import-2x/creator/components/Node.ts
Normal file
152
extensions/plugin-import-2x/creator/components/Node.ts
Normal file
@@ -0,0 +1,152 @@
|
||||
'use strict';
|
||||
import { getGroupLayerByIndex, fromEuler, hasUIRenderComponent, hasCanvasComponent } from '../common/utlis';
|
||||
import { UITransform } from "./UITransform";
|
||||
import { UIOpacity } from "./UIOpacity";
|
||||
|
||||
export const NODE = {
|
||||
"__type__": "cc.Node",
|
||||
"_name": "New Node",
|
||||
"_objFlags": 0,
|
||||
"_parent": null,
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_components": [],
|
||||
"_prefab": null,
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
"_lrot": {
|
||||
"__type__": "cc.Quat",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 1,
|
||||
},
|
||||
"_lscale": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"z": 1,
|
||||
},
|
||||
"_layer": 1073741824,
|
||||
"_euler": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
};
|
||||
|
||||
export class Node {
|
||||
|
||||
static create(name?: string, parentID?: number) {
|
||||
const node = JSON.parse(JSON.stringify(NODE));
|
||||
if (name) {
|
||||
node._name = name;
|
||||
}
|
||||
if (parentID) {
|
||||
node._parent = {
|
||||
__id__: parentID,
|
||||
};
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
static addComponents(node: any, componentID: number) {
|
||||
node._components.push({
|
||||
__id__: componentID,
|
||||
});
|
||||
}
|
||||
|
||||
static addChildren(node: any, childID: number) {
|
||||
node._children.push({
|
||||
__id__: childID,
|
||||
});
|
||||
}
|
||||
|
||||
static async migrate(index: number, json2D: any, json3D: any) {
|
||||
const source = JSON.parse(JSON.stringify(NODE));
|
||||
const node = json2D[index];
|
||||
// 先导入 components
|
||||
if (node._components) {
|
||||
for (const component of node._components) {
|
||||
const element = source._components.find((obj: any) => {
|
||||
return obj.__id__ === component.__id__;
|
||||
});
|
||||
if (!element) {
|
||||
source._components.push(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const key in node) {
|
||||
const value = node[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === '_groupIndex' || key === 'groupIndex') {
|
||||
let layer = await getGroupLayerByIndex(value);
|
||||
// 如果是 Canvas 并且 layer 是默认的,就设置为 UI_2D
|
||||
if (layer === 1 && hasCanvasComponent(node, json2D)) {
|
||||
layer = 1 << 25;
|
||||
}
|
||||
if (!layer) {
|
||||
console.warn(`The group layer: ${layer} no found. node name: ${node._name}`);
|
||||
layer = value;
|
||||
}
|
||||
source._layer = layer;
|
||||
}
|
||||
else if (key === '_color' || key === '_components') {
|
||||
continue;
|
||||
}
|
||||
else if (key === '_trs') {
|
||||
const trs = value.array;
|
||||
source._lpos.x = trs[0];
|
||||
source._lpos.y = trs[1];
|
||||
source._lpos.z = trs[2];
|
||||
source._lrot.x = trs[3];
|
||||
source._lrot.y = trs[4];
|
||||
source._lrot.z = trs[5];
|
||||
source._lrot.w = trs[6] === 0 ? 1 : trs[6];
|
||||
source._lscale.x = trs[7];
|
||||
source._lscale.y = trs[8];
|
||||
// 如果不是 3d 节点并且 scale z 是 0,就默认设置为 1
|
||||
if (!node['_is3DNode'] && trs[9] === 0) {
|
||||
trs[9] = 1;
|
||||
}
|
||||
source._lscale.z = trs[9];
|
||||
}
|
||||
else if (key === '_eulerAngles') {
|
||||
source._euler.x = value.x;
|
||||
source._euler.y = value.y;
|
||||
source._euler.z = value.z;
|
||||
}
|
||||
else if (key === '_contentSize') {
|
||||
if (hasUIRenderComponent(source, json2D)) {
|
||||
UITransform.setContentSize(source, index, value, json3D);
|
||||
}
|
||||
}
|
||||
else if (key === '_anchorPoint') {
|
||||
if (hasUIRenderComponent(source, json2D)) {
|
||||
UITransform.setAnchorPoint(source, index, value, json3D);
|
||||
}
|
||||
}
|
||||
else if (key === '_opacity') {
|
||||
if (hasUIRenderComponent(source, json2D)) {
|
||||
UIOpacity.setOpacity(source, index, value, json3D);
|
||||
}
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
fromEuler(source._lrot, source._euler.x, source._euler.y, source._euler.z);
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Node.migrate(index, json2D, json3D);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
77
extensions/plugin-import-2x/creator/components/PageView.ts
Normal file
77
extensions/plugin-import-2x/creator/components/PageView.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
export const PAGEVIEW = {
|
||||
"__type__": "cc.PageView",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"bounceDuration": 1,
|
||||
"brake": 0.5,
|
||||
"elastic": true,
|
||||
"inertia": true,
|
||||
"horizontal": true,
|
||||
"vertical": true,
|
||||
"cancelInnerEvents": true,
|
||||
"scrollEvents": [],
|
||||
"_content": null,
|
||||
"_horizontalScrollBar": null,
|
||||
"_verticalScrollBar": null,
|
||||
"autoPageTurningThreshold": 100,
|
||||
"pageTurningSpeed": 0.3,
|
||||
"pageEvents": [],
|
||||
"_sizeMode": 0,
|
||||
"_direction": 0,
|
||||
"_scrollThreshold": 0.5,
|
||||
"_pageTurningEventTiming": 0.1,
|
||||
"_indicator": null,
|
||||
};
|
||||
|
||||
export class PageView {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(PAGEVIEW));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(PAGEVIEW));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
switch (key) {
|
||||
case '_N$content':
|
||||
case 'content':
|
||||
source._content = value;
|
||||
break;
|
||||
case 'scrollThreshold':
|
||||
source._scrollThreshold = value;
|
||||
break;
|
||||
case 'pageTurningEventTiming':
|
||||
source._pageTurningEventTiming = value;
|
||||
break;
|
||||
case '_N$sizeMode':
|
||||
case 'sizeMode':
|
||||
source._sizeMode = value;
|
||||
break;
|
||||
case '_N$direction':
|
||||
case 'direction':
|
||||
source._direction = value;
|
||||
break;
|
||||
case '_N$indicator':
|
||||
case 'indicator':
|
||||
source._indicator = value;
|
||||
break;
|
||||
default:
|
||||
source[key] = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await PageView.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
|
||||
export const PAGEVIEWINDICATOR = {
|
||||
"__type__": "cc.PageViewIndicator",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"spacing": 0,
|
||||
"_spriteFrame": null,
|
||||
"_direction": 0,
|
||||
"_cellSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 20,
|
||||
"height": 20,
|
||||
},
|
||||
};
|
||||
|
||||
export class PageViewIndicator {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(PAGEVIEWINDICATOR));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(PAGEVIEWINDICATOR));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === 'spriteFrame') {
|
||||
source._spriteFrame = {
|
||||
__uuid__: await ImporterBase.getUuid(value.__uuid__, 'spriteFrame'),
|
||||
};
|
||||
}
|
||||
else if (key === 'cellSize') {
|
||||
source._cellSize = value;
|
||||
}
|
||||
else if (key === 'direction') {
|
||||
source._direction = value;
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await PageViewIndicator.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
export const PARTICLEASSET = {
|
||||
"__type__": "cc.ParticleAsset",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"spriteFrame": null,
|
||||
};
|
||||
|
||||
export class ParticleAsset {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(PARTICLEASSET));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(PARTICLEASSET));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await ParticleAsset.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
171
extensions/plugin-import-2x/creator/components/ParticleSystem.ts
Normal file
171
extensions/plugin-import-2x/creator/components/ParticleSystem.ts
Normal file
@@ -0,0 +1,171 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
import {GradientRange} from "./GradientRange";
|
||||
import {CurveRange} from "./CurveRange";
|
||||
|
||||
export const PARTICLESYSTEM = {
|
||||
"__type__": "cc.ParticleSystem",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_materials": [],
|
||||
"_visFlags": 0,
|
||||
"startColor": {
|
||||
"__id__": -1,
|
||||
},
|
||||
"scaleSpace": 1,
|
||||
"startSize3D": false,
|
||||
"startSizeX": {
|
||||
"__id__": 2,
|
||||
},
|
||||
"startSize": {
|
||||
"__id__": 2,
|
||||
},
|
||||
"startSizeY": {
|
||||
"__id__": 3,
|
||||
},
|
||||
"startSizeZ": {
|
||||
"__id__": 4,
|
||||
},
|
||||
"startSpeed": {
|
||||
"__id__": 5,
|
||||
},
|
||||
"startRotation3D": false,
|
||||
"startRotationX": {
|
||||
"__id__": 6,
|
||||
},
|
||||
"startRotationY": {
|
||||
"__id__": 7,
|
||||
},
|
||||
"startRotationZ": {
|
||||
"__id__": 8,
|
||||
},
|
||||
"startRotation": {
|
||||
"__id__": 8,
|
||||
},
|
||||
"startDelay": {
|
||||
"__id__": 9,
|
||||
},
|
||||
"startLifetime": {
|
||||
"__id__": 10,
|
||||
},
|
||||
"duration": 5,
|
||||
"loop": true,
|
||||
"simulationSpeed": 1,
|
||||
"playOnAwake": true,
|
||||
"gravityModifier": {
|
||||
"__id__": 11,
|
||||
},
|
||||
"rateOverTime": {
|
||||
"__id__": 12,
|
||||
},
|
||||
"rateOverDistance": {
|
||||
"__id__": 13,
|
||||
},
|
||||
"bursts": [],
|
||||
"_colorOverLifetimeModule": null,
|
||||
"_shapeModule": null,
|
||||
"_sizeOvertimeModule": null,
|
||||
"_velocityOvertimeModule": null,
|
||||
"_forceOvertimeModule": null,
|
||||
"_limitVelocityOvertimeModule": null,
|
||||
"_rotationOvertimeModule": null,
|
||||
"_textureAnimationModule": null,
|
||||
"_trailModule": null,
|
||||
"renderer": {
|
||||
"__id__": 14,
|
||||
},
|
||||
"enableCulling": false,
|
||||
"_prewarm": false,
|
||||
"_capacity": 100,
|
||||
"_simulationSpace": 1,
|
||||
};
|
||||
|
||||
const PARTICLESYSTEMRENDERER = {
|
||||
"__type__": "cc.ParticleSystemRenderer",
|
||||
"_renderMode": 0,
|
||||
"_velocityScale": 1,
|
||||
"_lengthScale": 1,
|
||||
"_mesh": null,
|
||||
"_mainTexture": null,
|
||||
"_useGPU": false,
|
||||
};
|
||||
|
||||
export class ParticleSystem {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(PARTICLESYSTEM));
|
||||
}
|
||||
|
||||
static createRenderer() {
|
||||
return JSON.parse(JSON.stringify(PARTICLESYSTEMRENDERER));
|
||||
}
|
||||
|
||||
static async migrate(particleSystem: any) {
|
||||
const source = JSON.parse(JSON.stringify(PARTICLESYSTEM));
|
||||
for (const key in particleSystem) {
|
||||
const value = particleSystem[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === '_materials') {
|
||||
source._materials = [];
|
||||
for (let i = 0; i < value.length; ++i) {
|
||||
let material = value[i];
|
||||
if (material) {
|
||||
material = {
|
||||
__uuid__: await ImporterBase.getUuid(material.__uuid__),
|
||||
};
|
||||
source._materials.push(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (key === '_velocityScale' || key === '_lengthScale' || key === '_mesh' || key === '_renderMode') {
|
||||
// 不做处理
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const particleSystem = json2D[index];
|
||||
const source = await ParticleSystem.migrate(particleSystem);
|
||||
const renderer = ParticleSystem.createRenderer();
|
||||
renderer._velocityScale = particleSystem._velocityScale;
|
||||
renderer._lengthScale = particleSystem._lengthScale;
|
||||
renderer._renderMode = particleSystem._renderMode;
|
||||
if (particleSystem._mesh) {
|
||||
renderer._mesh = {
|
||||
__uuid__: await ImporterBase.getUuid(particleSystem._mesh.__uuid__),
|
||||
};
|
||||
}
|
||||
json3D.push(renderer);
|
||||
source.renderer.__id__ = json3D.length - 1;
|
||||
const gr = GradientRange.create();
|
||||
json3D.push(gr);
|
||||
let cr = CurveRange.create();
|
||||
json3D.push(cr);
|
||||
source.startSizeX = json3D.length - 1;
|
||||
cr = CurveRange.create();
|
||||
json3D.push(cr);
|
||||
source.startSizeY = json3D.length - 1;
|
||||
cr = CurveRange.create();
|
||||
json3D.push(cr);
|
||||
source.startSizeZ = json3D.length - 1;
|
||||
cr = CurveRange.create();
|
||||
json3D.push(cr);
|
||||
source.startRotationX = json3D.length - 1;
|
||||
cr = CurveRange.create();
|
||||
json3D.push(cr);
|
||||
source.startRotationY = json3D.length - 1;
|
||||
cr = CurveRange.create();
|
||||
json3D.push(cr);
|
||||
source.startRotationZ = json3D.length - 1;
|
||||
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
import { getBlendFactor2DTo3D, setColor } from "../common/utlis";
|
||||
|
||||
export const PARTICLESYSTEM2D = {
|
||||
"__type__": "cc.ParticleSystem2D",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_materials": null,
|
||||
"_visFlags": 0,
|
||||
"_srcBlendFactor": 2,
|
||||
"_dstBlendFactor": 4,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255,
|
||||
},
|
||||
"preview": true,
|
||||
"_custom": false,
|
||||
"_file": null,
|
||||
"_spriteFrame": null,
|
||||
"_texture": null,
|
||||
"playOnLoad": true,
|
||||
"autoRemoveOnFinish": false,
|
||||
"_totalParticles": 150,
|
||||
"duration": -1,
|
||||
"emissionRate": 10,
|
||||
"life": 1,
|
||||
"lifeVar": 0,
|
||||
"_startColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255,
|
||||
},
|
||||
"_startColorVar": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 0,
|
||||
"g": 0,
|
||||
"b": 0,
|
||||
"a": 0,
|
||||
},
|
||||
"_endColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 0,
|
||||
},
|
||||
"_endColorVar": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 0,
|
||||
"g": 0,
|
||||
"b": 0,
|
||||
"a": 0,
|
||||
},
|
||||
"angle": 90,
|
||||
"angleVar": 20,
|
||||
"startSize": 50,
|
||||
"startSizeVar": 0,
|
||||
"endSize": 0,
|
||||
"endSizeVar": 0,
|
||||
"startSpin": 0,
|
||||
"startSpinVar": 0,
|
||||
"endSpin": 0,
|
||||
"endSpinVar": 0,
|
||||
"sourcePos": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"posVar": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"_positionType": 0,
|
||||
"emitterMode": 0,
|
||||
"gravity": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"speed": 180,
|
||||
"speedVar": 50,
|
||||
"tangentialAccel": 80,
|
||||
"tangentialAccelVar": 0,
|
||||
"radialAccel": 0,
|
||||
"radialAccelVar": 0,
|
||||
"rotationIsDir": false,
|
||||
"startRadius": 0,
|
||||
"startRadiusVar": 0,
|
||||
"endRadius": 0,
|
||||
"endRadiusVar": 0,
|
||||
"rotatePerS": 0,
|
||||
"rotatePerSVar": 0,
|
||||
};
|
||||
|
||||
export class ParticleSystem2D {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(PARTICLESYSTEM2D));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any, json3D: any) {
|
||||
const source = JSON.parse(JSON.stringify(PARTICLESYSTEM2D));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === 'node') {
|
||||
source.node = value;
|
||||
setColor(source, value.__id__, json2D);
|
||||
}
|
||||
else if (key === '_N$preview') {
|
||||
source.preview = value;
|
||||
}
|
||||
else if (key === '_materials') {
|
||||
if (key === '_materials') {
|
||||
source._materials = [];
|
||||
for (let i = 0; i < value.length; ++i) {
|
||||
let material = value[i];
|
||||
if (material) {
|
||||
material = {
|
||||
__uuid__: await ImporterBase.getUuid(material.__uuid__),
|
||||
};
|
||||
source._materials.push(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (key === '_totalParticles') {
|
||||
source.totalParticles = value;
|
||||
}
|
||||
else if (key === '_spriteFrame') {
|
||||
source._spriteFrame = {
|
||||
__uuid__: await ImporterBase.getUuid(value.__uuid__, 'spriteFrame'),
|
||||
};
|
||||
}
|
||||
else if (key === '_texture') {
|
||||
source._texture = {
|
||||
__uuid__: await ImporterBase.getUuid(value.__uuid__, 'texture'),
|
||||
};
|
||||
}
|
||||
else if (key === '_file') {
|
||||
source._file = {
|
||||
__uuid__: await ImporterBase.getUuid(value.__uuid__),
|
||||
};
|
||||
} else if (key === '_dstBlendFactor') {
|
||||
source._dstBlendFactor = getBlendFactor2DTo3D(value);
|
||||
} else if (key === '_srcBlendFactor') {
|
||||
source._srcBlendFactor = getBlendFactor2DTo3D(value);
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await ParticleSystem2D.migrate(json2D[index], json3D);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
export const PHYSICSMATERIAL = {
|
||||
"__type__": "cc.PhysicsMaterial",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"_friction": 0.5,
|
||||
"_rollingFriction": 0.1,
|
||||
"_spinningFriction": 0.1,
|
||||
"_restitution": 0.1,
|
||||
};
|
||||
|
||||
export class PhysicsMaterial {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(PHYSICSMATERIAL));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(PHYSICSMATERIAL));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await PhysicsMaterial.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
|
||||
export const PLANECOLLIDER = {
|
||||
"__type__": "cc.PlaneCollider",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_material": null,
|
||||
"_isTrigger": false,
|
||||
"_center": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
"_normal": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 1,
|
||||
"z": 0,
|
||||
},
|
||||
"_constant": 0,
|
||||
};
|
||||
|
||||
export class PlaneCollider {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(PLANECOLLIDER));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(PLANECOLLIDER));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === '_materials') {
|
||||
source._materials = [];
|
||||
for (let i = 0; i < value.length; ++i) {
|
||||
let material = value[0];
|
||||
if (material) {
|
||||
material = {
|
||||
__uuid__: await ImporterBase.getUuid(material.__uuid__),
|
||||
};
|
||||
source._materials.push(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await PlaneCollider.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
export const POINTTOPOINTCONSTRAINT = {
|
||||
"__type__": "cc.PointToPointConstraint",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_enableCollision": true,
|
||||
"_connectedBody": null,
|
||||
"_pivotA": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
"_pivotB": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
};
|
||||
|
||||
export class PointToPointConstraint {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(POINTTOPOINTCONSTRAINT));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(POINTTOPOINTCONSTRAINT));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await PointToPointConstraint.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
'use strict';
|
||||
export const POLYGONCOLLIDER2D = {
|
||||
"__type__": "cc.PolygonCollider2D",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"tag": 0,
|
||||
"_group": 1,
|
||||
"_density": 1,
|
||||
"_sensor": false,
|
||||
"_friction": 0.2,
|
||||
"_restitution": 0,
|
||||
"_offset": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"_points": [],
|
||||
};
|
||||
|
||||
export class PolygonCollider2D {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(POLYGONCOLLIDER2D));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(POLYGONCOLLIDER2D));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === 'points') {
|
||||
source._point = value;
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await PolygonCollider2D.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
33
extensions/plugin-import-2x/creator/components/Prefab.ts
Normal file
33
extensions/plugin-import-2x/creator/components/Prefab.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
export const PREFAB = {
|
||||
"__type__": "cc.Prefab",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"data": null,
|
||||
"optimizationPolicy": 0,
|
||||
"asyncLoadAssets": false,
|
||||
};
|
||||
|
||||
export class Prefab {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(PREFAB));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(PREFAB));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Prefab.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
59
extensions/plugin-import-2x/creator/components/PrefabInfo.ts
Normal file
59
extensions/plugin-import-2x/creator/components/PrefabInfo.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
import { ImporterBase } from "../common/base";
|
||||
|
||||
export const PREFABINFO = {
|
||||
"__type__": "cc.PrefabInfo",
|
||||
"root": null,
|
||||
"asset": null,
|
||||
"fileId": "",
|
||||
"sync": false,
|
||||
"_synced": {
|
||||
"default": false,
|
||||
"serializable": false,
|
||||
},
|
||||
};
|
||||
|
||||
export class PrefabInfo {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(PREFABINFO));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any, json3D: any) {
|
||||
const source = JSON.parse(JSON.stringify(PREFABINFO));
|
||||
let isPrefab = false;
|
||||
if (json3D && json3D[0]) {
|
||||
isPrefab = json3D[0].__type__ === 'cc.Prefab';
|
||||
}
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === 'asset') {
|
||||
if (value.__uuid__) {
|
||||
let __uuid__;
|
||||
if (isPrefab) {
|
||||
__uuid__ = ImporterBase.getNewUuid(value.__uuid__);
|
||||
} else {
|
||||
__uuid__ = await ImporterBase.getUuid(value.__uuid__);
|
||||
}
|
||||
source.asset = {
|
||||
__uuid__: __uuid__,
|
||||
};
|
||||
}
|
||||
else if (value.__id__) {
|
||||
source.asset = value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await PrefabInfo.migrate(json2D[index], json3D);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
38
extensions/plugin-import-2x/creator/components/Primitive.ts
Normal file
38
extensions/plugin-import-2x/creator/components/Primitive.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
export const PRIMITIVE = {
|
||||
"__type__": "cc.Primitive",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"_struct": {
|
||||
"vertexBundles": [],
|
||||
"primitives": [],
|
||||
},
|
||||
"_dataLength": 0,
|
||||
"_hash": 0,
|
||||
"type": 0,
|
||||
"info": {},
|
||||
};
|
||||
|
||||
export class Primitive {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(PRIMITIVE));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(PRIMITIVE));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await Primitive.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
137
extensions/plugin-import-2x/creator/components/PrivateNode.ts
Normal file
137
extensions/plugin-import-2x/creator/components/PrivateNode.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
'use strict';
|
||||
import { getGroupLayerByIndex } from "../common/utlis";
|
||||
import { UITransform } from "./UITransform";
|
||||
import { UIOpacity } from "./UIOpacity";
|
||||
|
||||
export const PRIVATENODE = {
|
||||
"__type__": "cc.PrivateNode",
|
||||
"_name": "New Node",
|
||||
"_objFlags": 1024,
|
||||
"_parent": null,
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_components": [],
|
||||
"_prefab": null,
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
"_lrot": {
|
||||
"__type__": "cc.Quat",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 1,
|
||||
},
|
||||
"_lscale": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"z": 1,
|
||||
},
|
||||
"_layer": 1073741824,
|
||||
"_euler": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
},
|
||||
};
|
||||
|
||||
export class PrivateNode {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(PRIVATENODE));
|
||||
}
|
||||
|
||||
static async migrate(index: number, json2D: any, json3D: any) {
|
||||
const source = JSON.parse(JSON.stringify(PRIVATENODE));
|
||||
const privateNode = json2D[index];
|
||||
for (const key in privateNode) {
|
||||
const value = privateNode[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key === '_groupIndex') {
|
||||
let layer = await getGroupLayerByIndex(value);
|
||||
if (!layer) {
|
||||
console.warn(`The group layer: ${index} no found. node name: ${privateNode._name}`);
|
||||
layer = value;
|
||||
}
|
||||
source._layer = layer;
|
||||
}
|
||||
else if (key === '_trs') {
|
||||
const trs = value.array;
|
||||
source._lpos.x = trs[0];
|
||||
source._lpos.y = trs[1];
|
||||
source._lpos.z = trs[2];
|
||||
source._lrot.x = trs[3];
|
||||
source._lrot.y = trs[4];
|
||||
source._lrot.z = trs[5];
|
||||
source._lrot.w = trs[6];
|
||||
source._lscale.x = trs[7];
|
||||
source._lscale.y = trs[8];
|
||||
source._lscale.z = trs[9];
|
||||
}
|
||||
else if (key === '_eulerAngles') {
|
||||
source._euler.x = value.x;
|
||||
source._euler.y = value.y;
|
||||
source._euler.z = value.z;
|
||||
}
|
||||
else if (key === '_contentSize' || key === '_anchorPoint') {
|
||||
let uiTransform: any = null;
|
||||
source._components.find((obj: any) => {
|
||||
const comp = json3D[obj.__id__];
|
||||
if (comp && comp.__type__ === 'cc.UITransform') {
|
||||
uiTransform = comp;
|
||||
return comp;
|
||||
}
|
||||
});
|
||||
if (!uiTransform) {
|
||||
uiTransform = UITransform.create();
|
||||
uiTransform.node = {
|
||||
__id__: index,
|
||||
};
|
||||
json3D.push(uiTransform);
|
||||
source._components.push({
|
||||
__id__: json3D.length - 1,
|
||||
});
|
||||
}
|
||||
if (key === '_contentSize') {
|
||||
uiTransform._contentSize = privateNode._contentSize;
|
||||
} else if (key === '_anchorPoint') {
|
||||
uiTransform._anchorPoint = privateNode._anchorPoint;
|
||||
}
|
||||
} else if (key === '_opacity') {
|
||||
let uiOpacity: any = null;
|
||||
source._components.find((obj: any) => {
|
||||
const comp = json3D[obj.__id__];
|
||||
if (comp && comp.__type__ === 'cc.UIOpacity') {
|
||||
uiOpacity = comp;
|
||||
return comp;
|
||||
}
|
||||
});
|
||||
if (!uiOpacity) {
|
||||
uiOpacity = UIOpacity.create();
|
||||
uiOpacity.node = {
|
||||
__id__: index,
|
||||
};
|
||||
json3D.push(uiOpacity);
|
||||
source._components.push({
|
||||
__id__: json3D.length - 1,
|
||||
});
|
||||
}
|
||||
uiOpacity._opacity = privateNode._opacity;
|
||||
} else {
|
||||
source[key] = value;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await PrivateNode.migrate(index, json2D, json3D);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
export const PROGRESSBAR = {
|
||||
"__type__": "cc.ProgressBar",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_barSprite": null,
|
||||
"_mode": 0,
|
||||
"_totalLength": 1,
|
||||
"_progress": 0.1,
|
||||
"_reverse": false,
|
||||
};
|
||||
|
||||
export class ProgressBar {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(PROGRESSBAR));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(PROGRESSBAR));
|
||||
for (let key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
if (key.startsWith('_N$')) {
|
||||
key = key.replace(/N\$/, '');
|
||||
}
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await ProgressBar.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
29
extensions/plugin-import-2x/creator/components/RawAsset.ts
Normal file
29
extensions/plugin-import-2x/creator/components/RawAsset.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
export const RAWASSET = {
|
||||
"__type__": "cc.RawAsset",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
};
|
||||
|
||||
export class RawAsset {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(RAWASSET));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(RAWASSET));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await RawAsset.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
'use strict';
|
||||
export const RELATIVEJOINT2D = {
|
||||
"__type__": "cc.RelativeJoint2D",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": null,
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"anchor": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"connectedAnchor": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"collideConnected": false,
|
||||
"connectedBody": null,
|
||||
"_maxForce": 5,
|
||||
"_maxTorque": 0.7,
|
||||
"_correctionFactor": 0.3,
|
||||
"_angularOffset": 0,
|
||||
"_linearOffset": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"_autoCalcOffset": true,
|
||||
};
|
||||
|
||||
export class RelativeJoint2D {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(RELATIVEJOINT2D));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(RELATIVEJOINT2D));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await RelativeJoint2D.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
31
extensions/plugin-import-2x/creator/components/RenderFlow.ts
Normal file
31
extensions/plugin-import-2x/creator/components/RenderFlow.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
export const RENDERFLOW = {
|
||||
"__type__": "RenderFlow",
|
||||
"_name": "",
|
||||
"_priority": 0,
|
||||
"_tag": 0,
|
||||
"_stages": [],
|
||||
};
|
||||
|
||||
export class RenderFlow {
|
||||
|
||||
static create() {
|
||||
return JSON.parse(JSON.stringify(RENDERFLOW));
|
||||
}
|
||||
|
||||
static async migrate(json2D: any) {
|
||||
const source = JSON.parse(JSON.stringify(RENDERFLOW));
|
||||
for (const key in json2D) {
|
||||
const value = json2D[key];
|
||||
if (key === '__type__' || value === undefined || value === null) { continue; }
|
||||
source[key] = value;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
static async apply(index: number, json2D: any, json3D: any) {
|
||||
const source = await RenderFlow.migrate(json2D[index]);
|
||||
json3D.splice(index, 1, source);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user