mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
@@ -13,3 +13,4 @@ node_modules
|
||||
/dist
|
||||
npm-debug.log
|
||||
DebugInfos.json
|
||||
/rollup/out
|
||||
|
||||
@@ -123,12 +123,7 @@ export class CameraComponent extends Component {
|
||||
|
||||
set projection (val) {
|
||||
this._projection = val;
|
||||
|
||||
let type = CameraProjection.PERSPECTIVE;
|
||||
if (this._projection === ProjectionType.ORTHO) {
|
||||
type = CameraProjection.ORTHO;
|
||||
}
|
||||
if (this._camera) { this._camera.projectionType = type; }
|
||||
if (this._camera) { this._camera.projectionType = val; }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,9 +221,7 @@ export class CameraComponent extends Component {
|
||||
|
||||
set depth (val) {
|
||||
this._depth = val;
|
||||
if (this._camera) {
|
||||
this._camera.clearDepth = val;
|
||||
}
|
||||
if (this._camera) { this._camera.clearDepth = val; }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,6 +280,7 @@ export class CameraComponent extends Component {
|
||||
}
|
||||
set targetDisplay (val) {
|
||||
this._targetDisplay = val;
|
||||
if (this._camera) { this._camera.changeTargetDisplay(val); }
|
||||
}
|
||||
|
||||
public onLoad () {
|
||||
|
||||
+24
-23
@@ -1,22 +1,23 @@
|
||||
import { Vec3 } from '../../core/value-types';
|
||||
import { vec3 } from '../../core/vmath';
|
||||
import { GFXPrimitiveMode } from '../../gfx/define';
|
||||
import { IGeometry, IGeometryOptions, normalizeGeometryOptions } from './defines';
|
||||
import { IGeometry, IGeometryOptions } from './defines';
|
||||
|
||||
interface IBoxOptions extends IGeometryOptions {
|
||||
/**
|
||||
* Box extent on X-axis.
|
||||
*/
|
||||
width: number;
|
||||
width?: number;
|
||||
|
||||
/**
|
||||
* Box extent on Y-axis.
|
||||
*/
|
||||
height: number;
|
||||
height?: number;
|
||||
|
||||
/**
|
||||
* Box extent on Z-axis.
|
||||
*/
|
||||
length: number;
|
||||
length?: number;
|
||||
|
||||
/**
|
||||
* Segment count on X-axis.
|
||||
@@ -39,15 +40,15 @@ interface IBoxOptions extends IGeometryOptions {
|
||||
* but may emplaced through `center` option).
|
||||
* @param options Options.
|
||||
*/
|
||||
export default function box (options: IBoxOptions): IGeometry {
|
||||
normalizeGeometryOptions(options);
|
||||
export default function box (options?: IBoxOptions): IGeometry {
|
||||
options = options || {};
|
||||
const ws = options.widthSegments || 1;
|
||||
const hs = options.heightSegments || 1;
|
||||
const ls = options.lengthSegments || 1;
|
||||
|
||||
const hw = options.width / 2;
|
||||
const hh = options.height / 2;
|
||||
const hl = options.length / 2;
|
||||
const hw = (options.width || 1) / 2;
|
||||
const hh = (options.height || 1) / 2;
|
||||
const hl = (options.length || 1) / 2;
|
||||
|
||||
const corners = [
|
||||
vec3.set(c0, -hw, -hh, hl),
|
||||
@@ -82,8 +83,8 @@ export default function box (options: IBoxOptions): IGeometry {
|
||||
const normals: number[] = [];
|
||||
const uvs: number[] = [];
|
||||
const indices: number[] = [];
|
||||
const minPos = vec3.create(-hw, -hh, -hl);
|
||||
const maxPos = vec3.create(hw, hh, hl);
|
||||
const minPos = new Vec3(-hw, -hh, -hl);
|
||||
const maxPos = new Vec3(hw, hh, hl);
|
||||
const boundingRadius = Math.sqrt(hw * hw + hh * hh + hl * hl);
|
||||
|
||||
function _buildPlane (side: number, uSegments: number, vSegments: number) {
|
||||
@@ -142,15 +143,15 @@ export default function box (options: IBoxOptions): IGeometry {
|
||||
};
|
||||
}
|
||||
|
||||
const temp1 = vec3.create(0, 0, 0);
|
||||
const temp2 = vec3.create(0, 0, 0);
|
||||
const temp3 = vec3.create(0, 0, 0);
|
||||
const r = vec3.create(0, 0, 0);
|
||||
const c0 = vec3.create(0, 0, 0);
|
||||
const c1 = vec3.create(0, 0, 0);
|
||||
const c2 = vec3.create(0, 0, 0);
|
||||
const c3 = vec3.create(0, 0, 0);
|
||||
const c4 = vec3.create(0, 0, 0);
|
||||
const c5 = vec3.create(0, 0, 0);
|
||||
const c6 = vec3.create(0, 0, 0);
|
||||
const c7 = vec3.create(0, 0, 0);
|
||||
const temp1 = new Vec3();
|
||||
const temp2 = new Vec3();
|
||||
const temp3 = new Vec3();
|
||||
const r = new Vec3();
|
||||
const c0 = new Vec3();
|
||||
const c1 = new Vec3();
|
||||
const c2 = new Vec3();
|
||||
const c3 = new Vec3();
|
||||
const c4 = new Vec3();
|
||||
const c5 = new Vec3();
|
||||
const c6 = new Vec3();
|
||||
const c7 = new Vec3();
|
||||
|
||||
@@ -7,12 +7,6 @@ export interface IGeometryOptions {
|
||||
includeNormal?: boolean;
|
||||
}
|
||||
|
||||
export function normalizeGeometryOptions (options: IGeometryOptions) {
|
||||
options.includeNormal = options.includeNormal === undefined ?
|
||||
true : options.includeNormal;
|
||||
return options;
|
||||
}
|
||||
|
||||
export interface IGeometry {
|
||||
/**
|
||||
* Topology of the geometry vertices.
|
||||
|
||||
@@ -684,9 +684,9 @@ export default class quat {
|
||||
*/
|
||||
public static toEuler<Out extends IQuatLike>(out: Out, q: quat) {
|
||||
const { x, y, z, w } = q;
|
||||
let heading: number = 0;
|
||||
let attitude: number = 0;
|
||||
let bank: number = 0;
|
||||
let heading: number = NaN;
|
||||
let attitude: number = NaN;
|
||||
let bank: number = NaN;
|
||||
const test = x * y + z * w;
|
||||
if (test > 0.499999) { // singularity at north pole
|
||||
heading = 2 * Math.atan2(x, w);
|
||||
|
||||
+5
-1
@@ -534,6 +534,7 @@ export interface IGFXFormatInfo {
|
||||
readonly isCompressed: boolean;
|
||||
}
|
||||
|
||||
// tslint:disable: max-line-length
|
||||
export const GFXFormatInfos: IGFXFormatInfo[] = [
|
||||
|
||||
{ name: 'UNKNOWN', size: 0, count: 0, isFloating: false, hasAlpha: false, hasDepth: false, hasStencil: false, isCompressed: false },
|
||||
@@ -639,6 +640,7 @@ export const GFXFormatInfos: IGFXFormatInfo[] = [
|
||||
{ name: 'PVRTC2_2BPP', size: 2, count: 4, isFloating: false, hasAlpha: true, hasDepth: false, hasStencil: false, isCompressed: true },
|
||||
{ name: 'PVRTC2_4BPP', size: 2, count: 4, isFloating: false, hasAlpha: true, hasDepth: false, hasStencil: false, isCompressed: true },
|
||||
];
|
||||
// tslint:enable: max-line-length
|
||||
|
||||
export function GFXFormatSize (format: GFXFormat, width: number, height: number, depth: number): number {
|
||||
|
||||
@@ -694,7 +696,9 @@ export function GFXFormatSize (format: GFXFormat, width: number, height: number,
|
||||
}
|
||||
}
|
||||
|
||||
export function GFXFormatSurfaceSize (format: GFXFormat, width: number, height: number, depth: number, mips: number): number {
|
||||
export function GFXFormatSurfaceSize (
|
||||
format: GFXFormat, width: number, height: number,
|
||||
depth: number, mips: number): number {
|
||||
|
||||
let size = 0;
|
||||
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import { GFXBindingType, GFXBufferTextureCopy, GFXBufferUsageBit, GFXColorMask, GFXCullMode, GFXFormat, GFXFormatInfos, GFXFormatSize, GFXLoadOp, GFXMemoryUsageBit, GFXShaderType, GFXTextureFlagBit, GFXTextureLayout, GFXTextureViewType, GFXType, IGFXColor, IGFXRect, WebGLEXT} from '../define';
|
||||
import { GFXBindingType, GFXBufferTextureCopy, GFXBufferUsageBit, GFXColorMask,
|
||||
GFXCullMode, GFXFormat, GFXFormatInfos, GFXFormatSize, GFXLoadOp, GFXMemoryUsageBit,
|
||||
GFXShaderType, GFXTextureFlagBit, GFXTextureLayout, GFXTextureViewType,
|
||||
GFXType, IGFXColor, IGFXRect, WebGLEXT} from '../define';
|
||||
import { WebGLGFXCommandAllocator } from './webgl-command-allocator';
|
||||
import { WebGLGFXDevice } from './webgl-device';
|
||||
import { WebGLAttrib, WebGLGPUBindingLayout, WebGLGPUBuffer, WebGLGPUFramebuffer, WebGLGPUInput, WebGLGPUInputAssembler, WebGLGPUPipelineState, WebGLGPUShader, WebGLGPUTexture, WebGLGPUUniform, WebGLGPUUniformBlock, WebGLGPUUniformSampler } from './webgl-gpu-objects';
|
||||
import { WebGLAttrib, WebGLGPUBindingLayout, WebGLGPUBuffer, WebGLGPUFramebuffer,
|
||||
WebGLGPUInput, WebGLGPUInputAssembler, WebGLGPUPipelineState, WebGLGPUShader,
|
||||
WebGLGPUTexture, WebGLGPUUniform, WebGLGPUUniformBlock, WebGLGPUUniformSampler } from './webgl-gpu-objects';
|
||||
import { IWebGLTexUnit } from './webgl-state-cache';
|
||||
|
||||
// tslint:disable: max-line-length
|
||||
|
||||
function CmpF32NotEuqal (a: number, b: number): boolean {
|
||||
const c = a - b;
|
||||
return (c > 0.000001 || c < -0.000001);
|
||||
|
||||
@@ -15,30 +15,34 @@ export interface IRenderViewInfo {
|
||||
|
||||
export class RenderView {
|
||||
|
||||
public get name (): string {
|
||||
public get name () {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public get window (): GFXWindow | null {
|
||||
public get window () {
|
||||
return this._window;
|
||||
}
|
||||
|
||||
public get priority (): number {
|
||||
public set window (val) {
|
||||
this._window = val;
|
||||
}
|
||||
|
||||
public get priority () {
|
||||
return this._priority;
|
||||
}
|
||||
|
||||
public set visibility (vis: number) {
|
||||
public set visibility (vis) {
|
||||
this._visibility = vis;
|
||||
}
|
||||
public get visibility (): number {
|
||||
public get visibility () {
|
||||
return this._visibility;
|
||||
}
|
||||
|
||||
public get camera (): Camera {
|
||||
public get camera () {
|
||||
return this._camera as Camera;
|
||||
}
|
||||
|
||||
public get scene (): RenderScene {
|
||||
public get scene () {
|
||||
return this._scene as RenderScene;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,23 +73,8 @@ export class Camera {
|
||||
this._clearStencil = info.stencil;
|
||||
this._clearFlag = info.clearFlags;
|
||||
|
||||
const win = scene.root.windows[info.targetDisplay - 1] || scene.root.mainWindow;
|
||||
if (win) {
|
||||
this._width = win.width;
|
||||
this._height = win.height;
|
||||
const view = this._view = scene.root.createView({
|
||||
name: `${name}View`,
|
||||
window: win,
|
||||
priority: RenderViewPriority.GENERAL,
|
||||
});
|
||||
if (view) { view.attach(this); }
|
||||
} else {
|
||||
this._width = 1;
|
||||
this._height = 1;
|
||||
}
|
||||
this._aspect = this._width / this._height;
|
||||
|
||||
this._visibility = 0;
|
||||
this._aspect = this._width = this._height = 1;
|
||||
this.changeTargetDisplay(info.targetDisplay);
|
||||
}
|
||||
|
||||
public resize (width: number, height: number) {
|
||||
@@ -282,6 +267,26 @@ export class Camera {
|
||||
return ray.fromPoints(out, v_b, v_a);
|
||||
}
|
||||
|
||||
public changeTargetDisplay (val: number) {
|
||||
const scene = this._scene;
|
||||
const win = scene.root.windows[val - 1] || scene.root.mainWindow;
|
||||
if (win) {
|
||||
this._width = win.width;
|
||||
this._height = win.height;
|
||||
if (!this._view) {
|
||||
this._view = scene.root.createView({
|
||||
name: this._name,
|
||||
window: win,
|
||||
priority: RenderViewPriority.GENERAL,
|
||||
});
|
||||
if (this._view) { this._view.attach(this); }
|
||||
} else {
|
||||
this._view.window = win;
|
||||
}
|
||||
}
|
||||
this._aspect = this._width / this._height;
|
||||
}
|
||||
|
||||
/**
|
||||
* transform a screen position to world space
|
||||
*/
|
||||
|
||||
+9
-2
@@ -13,7 +13,9 @@
|
||||
"build": "npm run build:dev && npm run build:min",
|
||||
"build:dev": "rollup -c ./rollup/config.js",
|
||||
"build:min": "uglifyjs ./bin/cocos-3d.dev.js --mangle --source-map -o ./bin/cocos-3d.min.js",
|
||||
"dev": "rollup -w -c ./rollup/config.js"
|
||||
"build-rollup": "tsc --build rollup/tsconfig.json",
|
||||
"dev": "rollup -w -c ./rollup/config.js",
|
||||
"postinstall": "npm run build-rollup"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -26,6 +28,9 @@
|
||||
"@babel/preset-env": "^7.2.0",
|
||||
"@babel/preset-typescript": "^7.1.0",
|
||||
"@types/cannon": "^0.1.3",
|
||||
"@types/fs-extra": "^5.0.4",
|
||||
"@types/uglify-js": "^3.0.4",
|
||||
"@types/yargs": "^12.0.5",
|
||||
"aliasify": "^2.1.0",
|
||||
"async": "1.5.2",
|
||||
"babel-preset-env": "^1.2.2",
|
||||
@@ -35,6 +40,7 @@
|
||||
"del": "1.2.0",
|
||||
"event-stream": "3.3.2",
|
||||
"fire-fs": "0.2.1",
|
||||
"fs-extra": "^7.0.1",
|
||||
"fs-jetpack": "^1.1.0",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-babel": "6.1.2",
|
||||
@@ -70,6 +76,7 @@
|
||||
"vinyl": "1.1.0",
|
||||
"vinyl-buffer": "1.0.0",
|
||||
"vinyl-source-stream": "1.0.0",
|
||||
"watchify": "^3.7.0"
|
||||
"watchify": "^3.7.0",
|
||||
"yargs": "^12.0.5"
|
||||
}
|
||||
}
|
||||
|
||||
+20
-65
@@ -28,8 +28,14 @@
|
||||
</canvas>
|
||||
|
||||
<script src="../bin/cocos-3d.dev.js"></script>
|
||||
<!-- <script src="./loadScene.js"></script> -->
|
||||
<script>
|
||||
function createTexture() {
|
||||
const imgElms = cc.game.canvas.getElementsByTagName('img');
|
||||
const textureAsset = new cc.Texture2D();
|
||||
textureAsset.image = new cc.ImageAsset(imgElms[0]);
|
||||
return textureAsset;
|
||||
}
|
||||
|
||||
function onStart() {
|
||||
const $body = document.body;
|
||||
const bcr = $body.getBoundingClientRect();
|
||||
@@ -39,79 +45,28 @@
|
||||
cc.view.setCanvasSize(bcr.width, bcr.height);
|
||||
});
|
||||
|
||||
/*
|
||||
let scene = new cc.Scene('testScene');
|
||||
scene._scene = scene;
|
||||
const root = cc.director.root;
|
||||
const scene = new cc.Scene();
|
||||
|
||||
let material = new cc.Material();
|
||||
material.effectName = 'test'; // parsed-effect file is embedded in cocos/3d/builtin/effects.js
|
||||
material.setProperty('u_color', cc.color('#ff0000'));
|
||||
material.passes[0].update();
|
||||
|
||||
let modelCom = scene.addComponent('cc.ModelComponent');
|
||||
modelCom.material = material;
|
||||
modelCom.mesh = cc.utils.createMesh(cc.game._renderContext, cc.primitives.box({length: 1, width: 1, height: 1}));
|
||||
scene.setRotationFromEuler(45, 45, 45);
|
||||
scene._rot = scene._lrot;
|
||||
*/
|
||||
|
||||
let root = cc.director.root;
|
||||
let scene = new cc.Scene();
|
||||
|
||||
let cameraNode = new cc.Node();
|
||||
const cameraNode = new cc.Node();
|
||||
cameraNode.parent = scene;
|
||||
let camComp = cameraNode.addComponent(cc.CameraComponent);
|
||||
let mainWindow = root.mainWindow;
|
||||
const camComp = cameraNode.addComponent(cc.CameraComponent);
|
||||
const mainWindow = root.mainWindow;
|
||||
|
||||
cc.director.runSceneImmediate(scene);
|
||||
|
||||
let material = new cc.Material();
|
||||
material.effectName = 'test'; // parsed-effect file is embedded in cocos/3d/builtin/effects.js
|
||||
const material = new cc.Material();
|
||||
material.effectName = 'test'; // parsed effect file is embedded in cocos/3d/builtin/effects.js
|
||||
material.setProperty('u_color', cc.color('#ff0000'));
|
||||
material.setProperty('u_sampler', createTexture());
|
||||
material.passes[0].update();
|
||||
|
||||
let modelCom = scene.addComponent('cc.ModelComponent');
|
||||
const modelNode = new cc.Node();
|
||||
modelNode.parent = scene;
|
||||
const modelCom = modelNode.addComponent('cc.ModelComponent');
|
||||
modelCom.material = material;
|
||||
modelCom.mesh = cc.utils.createMesh(cc.game._renderContext, cc.primitives.box({length: 1, width: 1, height: 1}));
|
||||
scene.setRotationFromEuler(45, 45, 45);
|
||||
scene._rot = scene._lrot;
|
||||
|
||||
|
||||
// let camera = scene.mainCamera;
|
||||
// camera.position = { x: 0.0, y: 0.0, z: 3.0 };
|
||||
// camera.direction = { x: 0.0, y: 0.0, z: -1.0 };
|
||||
// camera.update();
|
||||
|
||||
//todo initialization
|
||||
/*
|
||||
let scene = new cc.Scene();
|
||||
let node = new cc.Node();
|
||||
scene.addChild(node);
|
||||
node.addComponent('cc.CameraComponent');
|
||||
let modelNode = new cc.Node();
|
||||
modelNode.setPosition(0, 0, -10);
|
||||
scene.addChild(modelNode);
|
||||
let model = modelNode.addComponent('cc.ModelComponent');
|
||||
*/
|
||||
|
||||
// init mesh
|
||||
//model.mesh = cc.utils.createMesh(cc.game._renderContext, cc.primitives.box());
|
||||
/**
|
||||
// init effect
|
||||
let mtl = new cc.Material();
|
||||
let color = cc.color('#B58C42');
|
||||
mtl.effectName = cc.game._builtins['builtin-effect-unlit'];
|
||||
mtl.define('USE_COLOR', true);
|
||||
mtl.setProperty('color', color);
|
||||
/**
|
||||
mtl.effect = cc.game._builtins['builtin-effect-phong'];
|
||||
mtl.setProperty('diffuseColor', color);
|
||||
/**
|
||||
mtl.effect = cc.game._builtins['builtin-effect-pbr'];
|
||||
mtl.define('USE_EMISSIVE', true);
|
||||
mtl.setProperty('emissive', color);
|
||||
/**/
|
||||
// model.material = mtl;
|
||||
modelCom.mesh = cc.utils.createMesh(cc.game._renderContext, cc.primitives.box());
|
||||
modelNode.setRotationFromEuler(45, 45, 45);
|
||||
}
|
||||
cc.game.run({ id: 'canvas' }, onStart);
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
|
||||
import yargs from 'yargs';
|
||||
import { build } from './build-engine';
|
||||
|
||||
yargs.option('platform', { type: 'string', alias: 'p' });
|
||||
yargs.option('flags', { type: 'array', alias: 'f' });
|
||||
yargs.option('destination', { type: 'string', alias: 'd' });
|
||||
yargs.boolean('sourcemap');
|
||||
yargs.boolean('compress');
|
||||
|
||||
const flags: IFlags = {};
|
||||
const argvFlags = yargs.argv.flags as (string[] | undefined);
|
||||
if (argvFlags) {
|
||||
argvFlags.forEach((argvFlag) => flags[argvFlag as keyof IFlags] = true);
|
||||
}
|
||||
|
||||
const globalDefs = getGlobalDefs(yargs.argv.platform as Platform, flags);
|
||||
|
||||
build({
|
||||
compress: yargs.argv.compress as (boolean | undefined),
|
||||
globalDefines: globalDefs,
|
||||
inputPath: './index.js',
|
||||
outputPath: yargs.argv.destination as string,
|
||||
sourcemap: yargs.argv.sourcemap as (boolean | undefined),
|
||||
}).then(
|
||||
() => {
|
||||
console.log(`Build successful.`);
|
||||
},
|
||||
(reason: any) => {
|
||||
console.error(`Build failed, reason:\n ${reason}`);
|
||||
},
|
||||
);
|
||||
|
||||
type Platform = 'editor' | 'preview' | 'build' | 'test';
|
||||
|
||||
interface IFlags {
|
||||
jsb?: boolean;
|
||||
runtime?: boolean;
|
||||
wechatgame?: boolean;
|
||||
qqplay?: boolean;
|
||||
debug?: boolean;
|
||||
nativeRenderer?: boolean;
|
||||
}
|
||||
|
||||
interface IGlobaldefines {
|
||||
// Platform macros
|
||||
CC_EDITOR?: boolean;
|
||||
CC_PREVIEW?: boolean;
|
||||
CC_BUILD?: boolean;
|
||||
CC_TEST?: boolean;
|
||||
|
||||
// Flag macros
|
||||
CC_JSB?: boolean;
|
||||
CC_RUNTIME?: boolean;
|
||||
CC_WECHATGAME?: boolean;
|
||||
CC_WECHATGAMESUB?: boolean;
|
||||
CC_QQPLAY?: boolean;
|
||||
CC_DEBUG?: boolean;
|
||||
CC_NATIVERENDERER?: boolean;
|
||||
|
||||
// Debug macros
|
||||
CC_DEV?: boolean;
|
||||
CC_SUPPORT_JIT?: boolean;
|
||||
}
|
||||
|
||||
function getGlobalDefs (platform: Platform, flags?: IFlags): object {
|
||||
const PLATFORM_MACROS = ['CC_EDITOR', 'CC_PREVIEW', 'CC_BUILD', 'CC_TEST'];
|
||||
|
||||
const FLAGS = ['jsb', 'runtime', 'wechatgame', 'wechatgameSub', 'qqplay', 'debug', 'nativeRenderer'];
|
||||
|
||||
const platformMacro = 'CC_' + platform.toUpperCase();
|
||||
if (PLATFORM_MACROS.indexOf(platformMacro) === -1) {
|
||||
throw new Error(`Unknown platform ${platform}.`);
|
||||
}
|
||||
const result: IGlobaldefines = {};
|
||||
for (const macro of PLATFORM_MACROS) {
|
||||
result[macro as keyof IGlobaldefines] = (macro === platformMacro);
|
||||
}
|
||||
|
||||
if (flags) {
|
||||
for (const flag in flags) {
|
||||
if (flags.hasOwnProperty(flag) && flags[flag as keyof IFlags]) {
|
||||
if (FLAGS.indexOf(flag) === -1) {
|
||||
throw new Error('Unknown flag: ' + flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const flag of FLAGS) {
|
||||
const macro = 'CC_' + flag.toUpperCase();
|
||||
result[macro as keyof IGlobaldefines] = !!(flags && flags[flag as keyof IFlags]);
|
||||
}
|
||||
|
||||
result.CC_DEV = result.CC_EDITOR || result.CC_PREVIEW || result.CC_TEST;
|
||||
result.CC_DEBUG = result.CC_DEBUG || result.CC_DEV;
|
||||
result.CC_SUPPORT_JIT = !(result.CC_WECHATGAME || result.CC_QQPLAY || result.CC_RUNTIME);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
|
||||
import * as fs from 'fs-extra';
|
||||
import { rollup } from 'rollup';
|
||||
// @ts-ignore
|
||||
import babel from 'rollup-plugin-babel';
|
||||
// @ts-ignore
|
||||
import commonjs from 'rollup-plugin-commonjs';
|
||||
// @ts-ignore
|
||||
import json from 'rollup-plugin-json';
|
||||
// @ts-ignore
|
||||
import resolve from 'rollup-plugin-node-resolve';
|
||||
import { minify } from 'uglify-js';
|
||||
|
||||
export interface IBuildOptions {
|
||||
inputPath: string;
|
||||
outputPath: string;
|
||||
globalDefines: object;
|
||||
excludes?: string[];
|
||||
compress?: boolean;
|
||||
sourcemap?: boolean;
|
||||
}
|
||||
|
||||
export async function build (options: IBuildOptions) {
|
||||
console.log(`Options: ${JSON.stringify(options)}`);
|
||||
const result = await _doBundle(options);
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
fs.writeFileSync(options.outputPath, result.code);
|
||||
}
|
||||
|
||||
async function _doBundle (options: IBuildOptions) {
|
||||
let code = '';
|
||||
|
||||
const rollupPlugins = [
|
||||
resolve({
|
||||
extensions: ['.js', '.ts', '.json'],
|
||||
jsnext: true,
|
||||
main: true,
|
||||
}),
|
||||
|
||||
json({
|
||||
preferConst: true,
|
||||
}),
|
||||
|
||||
babel({
|
||||
extensions: ['.js', '.ts'],
|
||||
highlightCode: true,
|
||||
ignore: [
|
||||
'node_modules/**',
|
||||
],
|
||||
plugins: [
|
||||
['@babel/plugin-proposal-decorators', {
|
||||
legacy: true,
|
||||
}],
|
||||
['@babel/plugin-proposal-class-properties', {
|
||||
loose: true,
|
||||
}],
|
||||
],
|
||||
presets: [
|
||||
'@babel/preset-env',
|
||||
'@babel/preset-typescript',
|
||||
],
|
||||
}),
|
||||
|
||||
commonjs({
|
||||
namedExports: {
|
||||
cannon: ['CANNON', 'Shape'],
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
const rollupBuild = await rollup({
|
||||
input: options.inputPath,
|
||||
plugins: rollupPlugins,
|
||||
});
|
||||
|
||||
const generated = await rollupBuild.generate({
|
||||
format: 'iife',
|
||||
name: 'cc_modular',
|
||||
sourcemap: true,
|
||||
});
|
||||
|
||||
code = generated.code;
|
||||
|
||||
console.log(`Doing uglify...`);
|
||||
|
||||
const minifyOutput = minify(code, {
|
||||
compress: {
|
||||
global_defs: options.globalDefines,
|
||||
},
|
||||
});
|
||||
if (minifyOutput.error) {
|
||||
console.error(minifyOutput.error.stack);
|
||||
return null;
|
||||
} else {
|
||||
code = minifyOutput.code;
|
||||
}
|
||||
|
||||
return {
|
||||
code,
|
||||
};
|
||||
}
|
||||
+1
-1
@@ -6,7 +6,7 @@ import commonjs from 'rollup-plugin-commonjs';
|
||||
|
||||
const dest = './bin';
|
||||
const file = 'cocos-3d.dev';
|
||||
const moduleName = 'cocos3d';
|
||||
const moduleName = 'cc_modular';
|
||||
|
||||
fsJetpack.dir(dest);
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
"sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./out", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -16,8 +16,7 @@
|
||||
"object-literal-sort-keys": false,
|
||||
"ban-types": false,
|
||||
"no-bitwise": false,
|
||||
"max-line-length": false,
|
||||
"no-empty": false
|
||||
},
|
||||
"rulesDirectory": []
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user