diff --git a/cc.config.json b/cc.config.json index 8339a228dd3..6350fb18d1e 100644 --- a/cc.config.json +++ b/cc.config.json @@ -41,13 +41,25 @@ "overrides": { "cocos/core/pipeline/index.ts": "cocos/core/pipeline/index.jsb.ts", "cocos/core/renderer/core/native-pools.ts": "cocos/core/renderer/core/native-pools.jsb.ts", + "cocos/core/renderer/core/material-instance.ts": "cocos/core/renderer/core/material-instance.jsb.ts", + "cocos/core/renderer/core/pass.ts": "cocos/core/renderer/core/pass.jsb.ts", + "cocos/core/renderer/core/render-window.ts": "cocos/core/renderer/core/render-window.jsb.ts", + "cocos/core/renderer/core/samper-lib.ts": "cocos/core/renderer/core/sampler.jsb.ts", + "cocos/core/renderer/scene/camera.ts": "cocos/core/renderer/scene/camera.jsb.ts", + "cocos/core/renderer/scene/model.ts": "cocos/core/renderer/scene/model.jsb.ts", + "cocos/core/renderer/scene/render-scene.ts": "cocos/core/renderer/scene/render-scene.jsb.ts", + "cocos/core/renderer/scene/submodel.ts": "cocos/core/renderer/scene/submodel.jsb.ts", + "cocos/core/renderer/scene/index.ts": "cocos/core/renderer/scene/index.jsb.ts", "cocos/core/gfx/index.ts": "cocos/core/gfx/index.jsb.ts", "cocos/core/gfx/pipeline-state.ts": "cocos/core/gfx/pipeline-state.jsb.ts", "cocos/spine/index.ts": "cocos/spine/index.jsb.ts", "cocos/dragon-bones/index.ts": "cocos/dragon-bones/index.jsb.ts", "cocos/physics/physx/instantiate.ts": "cocos/physics/physx/instantiate.jsb.ts", - "cocos/core/scene-graph/index.ts": "cocos/core/scene-graph/index.jsb.ts", + "cocos/core/scene-graph/base-node.ts": "cocos/core/scene-graph/base-node.jsb.ts", "cocos/core/scene-graph/node.ts": "cocos/core/scene-graph/node.jsb.ts", + "cocos/core/scene-graph/find.ts": "cocos/core/scene-graph/find.jsb.ts", + "cocos/core/scene-graph/scene-globals.ts": "cocos/core/scene-graph/scene-globals.jsb.ts", + "cocos/core/scene-graph/index.ts": "cocos/core/scene-graph/index.jsb.ts", "cocos/core/root.ts": "cocos/core/root.jsb.ts" } }, diff --git a/cocos/2d/framework/renderable-2d.ts b/cocos/2d/framework/renderable-2d.ts index 61b2bf423e9..d40ad7f29aa 100644 --- a/cocos/2d/framework/renderable-2d.ts +++ b/cocos/2d/framework/renderable-2d.ts @@ -35,7 +35,6 @@ import { ccenum } from '../../core/value-types/enum'; import { builtinResMgr } from '../../core/builtin'; import { Material } from '../../core/assets'; import { BlendFactor, BlendState, BlendTarget } from '../../core/gfx'; -import { IMaterialInstanceInfo } from '../../core/renderer/core/material-instance'; import { IAssembler, IAssemblerManager } from '../renderer/base'; import { RenderData } from '../renderer/render-data'; import { Batcher2D } from '../renderer/batcher-2d'; diff --git a/cocos/core/renderer/core/material-instance.jsb.ts b/cocos/core/renderer/core/material-instance.jsb.ts new file mode 100644 index 00000000000..d99988caa89 --- /dev/null +++ b/cocos/core/renderer/core/material-instance.jsb.ts @@ -0,0 +1,34 @@ +/* + Copyright (c) 2021 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +import { Material } from "../../assets"; +import { RenderableComponent } from "../../components"; + +export interface IMaterialInstanceInfo { + parent: Material; + owner?: RenderableComponent; + subModelIdx?: number; +} +export const MaterialInstance = jsb.MaterialInstance; diff --git a/cocos/core/renderer/core/native-pools.jsb.ts b/cocos/core/renderer/core/native-pools.jsb.ts index 49b79129e09..82cacca2a8f 100644 --- a/cocos/core/renderer/core/native-pools.jsb.ts +++ b/cocos/core/renderer/core/native-pools.jsb.ts @@ -23,7 +23,6 @@ THE SOFTWARE. */ - declare const jsb: any; export const NativeBufferPool = jsb.NativeBufferPool; diff --git a/cocos/core/renderer/core/pass.jsb.ts b/cocos/core/renderer/core/pass.jsb.ts new file mode 100644 index 00000000000..2b8e069bebe --- /dev/null +++ b/cocos/core/renderer/core/pass.jsb.ts @@ -0,0 +1,48 @@ +/* + Copyright (c) 2021 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +import { IPassInfo, IPassStates } from "../../assets/effect-asset"; +import { MacroRecord } from "./pass-utils"; + +export interface IPassInfoFull extends IPassInfo { + // generated part + passIndex: number; + defines: MacroRecord; + stateOverrides?: PassOverrides; +} +export type PassOverrides = RecursivePartial; + +export interface IMacroPatch { + name: string; + value: boolean | number | string; +} + +export enum BatchingSchemes { + NONE = 0, + INSTANCING = 1, + VB_MERGING = 2, +} + +export const Pass = jsb.Pass; diff --git a/cocos/core/renderer/core/render-window.jsb.ts b/cocos/core/renderer/core/render-window.jsb.ts new file mode 100644 index 00000000000..6f3c107f1d4 --- /dev/null +++ b/cocos/core/renderer/core/render-window.jsb.ts @@ -0,0 +1,37 @@ +/* + Copyright (c) 2021 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +import { RenderPassInfo } from "../../gfx"; + +export interface IRenderWindowInfo { + title?: string; + width: number; + height: number; + renderPassInfo: RenderPassInfo; + swapchainBufferIndices?: number; + shouldSyncSizeWithSwapchain?: boolean; +} + +export const RenderWindow = jsb.RenderWindow; diff --git a/cocos/core/renderer/core/sampler-lib.jsb.ts b/cocos/core/renderer/core/sampler-lib.jsb.ts new file mode 100644 index 00000000000..69a29a83785 --- /dev/null +++ b/cocos/core/renderer/core/sampler-lib.jsb.ts @@ -0,0 +1,32 @@ +/* + Copyright (c) 2021 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +import { legacyCC } from "../../global-exports"; + +export const Pass = jsb.Pass; + +const SamplerLib = nr.SamplerLib; +export const samplerLib = new SamplerLib(); +legacyCC.samplerLib = samplerLib; diff --git a/cocos/core/renderer/index.jsb.ts b/cocos/core/renderer/index.jsb.ts new file mode 100644 index 00000000000..42627028e21 --- /dev/null +++ b/cocos/core/renderer/index.jsb.ts @@ -0,0 +1,57 @@ +/* + Copyright (c) 2021 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +import config from './config'; + +import * as scene from './scene'; + +import './scene/deprecated'; +import { legacyCC } from "../global-exports"; +import { RenderableComponent } from "../components"; + +export { createIA } from './utils'; + +const addStage = config.addStage; +export { addStage }; + +export * from './core/constants'; +export * from './core/pass-utils'; +export const Pass = jsb.Pass; +const ProgramLib = jsb.ProgramLib; +export const programLib = new ProgramLib(); +legacyCC.programLib = programLib; +export * from "./core/sampler-lib"; +export * from './core/texture-buffer-pool'; + + export interface IMaterialInstanceInfo { + parent: any; + owner?: RenderableComponent; + subModelIdx?: number; +} +export const MaterialInstance = jsb.MaterialInstance; +export const PassInstance = jsb.PassInstance; + +export * from './core/memory-pools'; +export { scene }; diff --git a/cocos/core/renderer/scene/camera.jsb.ts b/cocos/core/renderer/scene/camera.jsb.ts new file mode 100644 index 00000000000..7d24bc53fed --- /dev/null +++ b/cocos/core/renderer/scene/camera.jsb.ts @@ -0,0 +1,105 @@ +/* + Copyright (c) 2021 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +import { RenderWindow } from "../core/render-window"; +import { ClearFlagBit } from "../../gfx"; + +export enum CameraFOVAxis { + VERTICAL, + HORIZONTAL, +} + +export enum CameraProjection { + ORTHO, + PERSPECTIVE, +} + +export enum CameraAperture { + F1_8, + F2_0, + F2_2, + F2_5, + F2_8, + F3_2, + F3_5, + F4_0, + F4_5, + F5_0, + F5_6, + F6_3, + F7_1, + F8_0, + F9_0, + F10_0, + F11_0, + F13_0, + F14_0, + F16_0, + F18_0, + F20_0, + F22_0, +} + +export enum CameraISO { + ISO100, + ISO200, + ISO400, + ISO800, +} + +export enum CameraShutter { + D1, + D2, + D4, + D8, + D15, + D30, + D60, + D125, + D250, + D500, + D1000, + D2000, + D4000, +} + +const FSTOPS: number[] = [1.8, 2.0, 2.2, 2.5, 2.8, 3.2, 3.5, 4.0, 4.5, 5.0, 5.6, 6.3, 7.1, 8.0, 9.0, 10.0, 11.0, 13.0, 14.0, 16.0, 18.0, 20.0, 22.0]; +const SHUTTERS: number[] = [1.0, 1.0 / 2.0, 1.0 / 4.0, 1.0 / 8.0, 1.0 / 15.0, 1.0 / 30.0, 1.0 / 60.0, 1.0 / 125.0, + 1.0 / 250.0, 1.0 / 500.0, 1.0 / 1000.0, 1.0 / 2000.0, 1.0 / 4000.0]; +const ISOS: number[] = [100.0, 200.0, 400.0, 800.0]; + +export interface ICameraInfo { + name: string; + node: Node; + projection: number; + targetDisplay?: number; + window?: RenderWindow | null; + priority: number; + pipeline?: string; +} + +export const SKYBOX_FLAG = ClearFlagBit.STENCIL << 1; + +export const Camera = jsb.Camera; diff --git a/cocos/core/renderer/scene/index.jsb.ts b/cocos/core/renderer/scene/index.jsb.ts new file mode 100644 index 00000000000..2c5511fc152 --- /dev/null +++ b/cocos/core/renderer/scene/index.jsb.ts @@ -0,0 +1,38 @@ +/* + Copyright (c) 2021 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +export const Ambient = jsb.Ambient; +export const DirectionalLight = jsb.DirectionalLight; +export const Fog = jsb.Fog; +export const Light = jsb.Light; +export const Shadow = jsb.Shadow; +export const Skybox = jsb.Skybox; +export const SphereLight = jsb.SphereLight; +export const SpotLight = jsb.SpotLight; + +export * from './camera'; +export * from './model'; +export * from './render-scene'; +export * from './submodel'; diff --git a/cocos/core/renderer/scene/model.jsb.ts b/cocos/core/renderer/scene/model.jsb.ts new file mode 100644 index 00000000000..afec0d3e907 --- /dev/null +++ b/cocos/core/renderer/scene/model.jsb.ts @@ -0,0 +1,43 @@ +/* + Copyright (c) 2021 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +import { Attribute } from "../../gfx"; + +export interface IInstancedAttributeBlock { + buffer: Uint8Array; + views: TypedArray[]; + attributes: Attribute[]; +} + +export enum ModelType { + DEFAULT, + SKINNING, + BAKED_SKINNING, + BATCH_2D, + PARTICLE_BATCH, + LINE, +} + +export const Model = jsb.Model; diff --git a/cocos/core/renderer/scene/render-scene.jsb.ts b/cocos/core/renderer/scene/render-scene.jsb.ts new file mode 100644 index 00000000000..9d7f87152f5 --- /dev/null +++ b/cocos/core/renderer/scene/render-scene.jsb.ts @@ -0,0 +1,43 @@ +/* + Copyright (c) 2021 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +import { Node } from "../../scene-graph"; + +export interface IRenderSceneInfo { + name: string; +} + +export interface ISceneNodeInfo { + name: string; + isStatic?: boolean; + // parent: Node; +} + +export interface IRaycastResult { + node: Node; + distance: number; +} + +export const RenderScene = jsb.RenderScene; diff --git a/cocos/core/renderer/scene/submodel.jsb.ts b/cocos/core/renderer/scene/submodel.jsb.ts new file mode 100644 index 00000000000..a6a0c8ca512 --- /dev/null +++ b/cocos/core/renderer/scene/submodel.jsb.ts @@ -0,0 +1,26 @@ +/* + Copyright (c) 2021 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +export const SubModel = jsb.SubModel; diff --git a/cocos/core/root.jsb.ts b/cocos/core/root.jsb.ts index 01e7580e796..fefe0c12af1 100644 --- a/cocos/core/root.jsb.ts +++ b/cocos/core/root.jsb.ts @@ -3,7 +3,7 @@ import {warnID} from "./platform"; import { Batcher2D } from '../2d/renderer/batcher-2d'; import legacyCC from '../../predefine'; -declare const jsb: any; + export const Root = jsb.Root; diff --git a/cocos/core/scene-graph/base-node.jsb.ts b/cocos/core/scene-graph/base-node.jsb.ts new file mode 100644 index 00000000000..86b5cef6cab --- /dev/null +++ b/cocos/core/scene-graph/base-node.jsb.ts @@ -0,0 +1,26 @@ +/* + Copyright (c) 2021 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +export const BaseNode = jsb.Node; diff --git a/cocos/core/scene-graph/deprecated.ts b/cocos/core/scene-graph/deprecated.ts index 3a8ded8f366..14cd0f6b506 100644 --- a/cocos/core/scene-graph/deprecated.ts +++ b/cocos/core/scene-graph/deprecated.ts @@ -40,6 +40,19 @@ import { legacyCC } from '../global-exports'; import { CCObject } from '../data/object'; import { warnID } from '../platform/debug'; import { SceneGlobals } from './scene-globals'; +import { JSB } from "../default-constants"; + +if (JSB) { + replaceProperty(Node.prototype, 'Node', [ + { + name: 'childrenCount', + newName: 'children.length', + customGetter (this: Node) { + return this.children.length; + }, + }, + ]); +} replaceProperty(BaseNode.prototype, 'BaseNode', [ { diff --git a/cocos/core/scene-graph/find.jsb.ts b/cocos/core/scene-graph/find.jsb.ts new file mode 100644 index 00000000000..d8b3faf7af2 --- /dev/null +++ b/cocos/core/scene-graph/find.jsb.ts @@ -0,0 +1,29 @@ +/* + Copyright (c) 2021 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +import { legacyCC } from "../global-exports"; + +export const find = jsb.Node.find; +legacyCC.find = find; diff --git a/cocos/core/scene-graph/index.jsb.ts b/cocos/core/scene-graph/index.jsb.ts index 3f465891125..8f26bd3fc4e 100644 --- a/cocos/core/scene-graph/index.jsb.ts +++ b/cocos/core/scene-graph/index.jsb.ts @@ -1,11 +1,11 @@ -declare const jsb: any; - import './node-event-processor'; import './deprecated'; export const Node = jsb.Node; export const Scene = jsb.Scene; -export const NodeActivator = jsb.NodeActivator; -export const find = jsb.find; + export { Layers } from './layers'; export * from './deprecated'; +export * from './scene-globals'; +export * from './find'; +export { default as NodeActivator } from './node-activator'; diff --git a/cocos/core/scene-graph/node.jsb.ts b/cocos/core/scene-graph/node.jsb.ts index 415be16b676..4ef00b62839 100644 --- a/cocos/core/scene-graph/node.jsb.ts +++ b/cocos/core/scene-graph/node.jsb.ts @@ -1,5 +1,3 @@ -declare const jsb: any; - import * as js from '../utils/js'; import { legacyCC } from '../global-exports'; import { errorID, getError } from '../platform/debug'; @@ -8,6 +6,7 @@ import { NodeEventType } from './node-event'; import { CCObject } from '../data/object'; import { NodeUIProperties } from './node-ui-properties'; +const nodeProto: any = jsb.Node.prototype; export const TRANSFORM_ON = 1 << 0; const Destroying = CCObject.Flags.Destroying; @@ -22,14 +21,13 @@ function getConstructor (typeOrClassName) { return typeOrClassName; } - -jsb.Node.prototype._ctor = function (name?: string) { +nodeProto._ctor = function (name?: string) { this._components = []; this._eventProcessor = new legacyCC.NodeEventProcessor(this); this._uiProps = new NodeUIProperties(this); this._registerListeners(); -} +}; Object.defineProperties(jsb.Node.prototype, { '_components': { @@ -44,13 +42,13 @@ Object.defineProperties(jsb.Node.prototype, { } }); -jsb.Node.prototype.getComponent = function (typeOrClassName) { +nodeProto.getComponent = function (typeOrClassName) { const constructor = getConstructor(typeOrClassName); if (constructor) { return jsb.Node._findComponent(this, constructor); } return null; -} +}; jsb.Node.prototype.getComponents = function (typeOrClassName) { const constructor = getConstructor(typeOrClassName); @@ -59,17 +57,17 @@ jsb.Node.prototype.getComponents = function (typeOrClassName) { jsb.Node._findComponents(this, constructor, components); } return components; -} +}; -jsb.Node.prototype.getComponentInChildren = function (typeOrClassName) { +nodeProto.getComponentInChildren = function (typeOrClassName) { const constructor = getConstructor(typeOrClassName); if (constructor) { return jsb.Node._findChildComponent(this._children, constructor); } return null; -} +}; -jsb.Node.prototype.getComponentsInChildren = function (typeOrClassName) { +nodeProto.getComponentsInChildren = function (typeOrClassName) { const constructor = getConstructor(typeOrClassName); const components = []; if (constructor) { @@ -77,9 +75,9 @@ jsb.Node.prototype.getComponentsInChildren = function (typeOrClassName) { jsb.Node._findChildComponents(this.getChildren(), constructor, components); } return components; -} +}; -jsb.Node.prototype.addComponent = function (typeOrClassName) { +nodeProto.addComponent = function (typeOrClassName) { // if (EDITOR && (this._objFlags & Destroying)) { // throw Error('isDestroying'); // } @@ -144,9 +142,9 @@ jsb.Node.prototype.addComponent = function (typeOrClassName) { } return component; -} +}; -jsb.Node.prototype.removeComponent = function (component) { +nodeProto.removeComponent = function (component) { if (!component) { errorID(3813); return; @@ -160,9 +158,9 @@ jsb.Node.prototype.removeComponent = function (component) { if (componentInstance) { componentInstance.destroy(); } -} +}; -jsb.Node.prototype.on = function (type, callback, target, useCapture) { +nodeProto.on = function (type, callback, target, useCapture) { switch (type) { case NodeEventType.TRANSFORM_CHANGED: // this._eventMask |= TRANSFORM_ON; @@ -172,9 +170,9 @@ jsb.Node.prototype.on = function (type, callback, target, useCapture) { break; } this._eventProcessor.on(type, callback, target, useCapture); -} +}; -jsb.Node.prototype.off = function (type: string, callback?, target?, useCapture = false) { +nodeProto.off = function (type: string, callback?, target?, useCapture = false) { this._eventProcessor.off(type, callback, target, useCapture); const hasListeners = this._eventProcessor.hasEventListener(type); @@ -189,34 +187,34 @@ jsb.Node.prototype.off = function (type: string, callback?, target?, useCapture break; } } -} +}; -jsb.Node.prototype.once = function (type: string, callback, target?: unknown, useCapture?: any) { +nodeProto.once = function (type: string, callback, target?: unknown, useCapture?: any) { this._eventProcessor.once(type, callback, target, useCapture); -} +}; -jsb.Node.prototype.emit = function (type: string, arg0?: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any) { +nodeProto.emit = function (type: string, arg0?: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any) { this._eventProcessor.emit(type, arg0, arg1, arg2, arg3, arg4); -} +}; -jsb.Node.prototype.dispatchEvent = function (event: Event) { +nodeProto.dispatchEvent = function (event: Event) { this._eventProcessor.dispatchEvent(event); -} +}; -jsb.Node.prototype.hasEventListener = function (type: string, callback?, target?: unknown) { +nodeProto.hasEventListener = function (type: string, callback?, target?: unknown) { return this._eventProcessor.hasEventListener(type, callback, target); -} +}; -jsb.Node.prototype.targetOff = function (target: string | unknown) { +nodeProto.targetOff = function (target: string | unknown) { // Check for event mask reset let eventMask = this.getEventMask(); if ((eventMask & TRANSFORM_ON) && !this._eventProcessor.hasEventListener(NodeEventType.TRANSFORM_CHANGED)) { // this._eventMask &= ~TRANSFORM_ON; this.setEventMask(eventMask & ~TRANSFORM_ON); } -} +}; -jsb.Node.prototype._removeComponent = function (component: Component) { +nodeProto._removeComponent = function (component: Component) { if (!component) { errorID(3814); return; @@ -233,62 +231,62 @@ jsb.Node.prototype._removeComponent = function (component: Component) { errorID(3815); } } -} +}; // These functions are invoked by native Node object. -jsb.Node.prototype._onTransformChanged = function (transformType) { +nodeProto._onTransformChanged = function (transformType) { this._eventProcessor.dispatchEvent(NodeEventType.TRANSFORM_CHANGED, transformType); -} +}; -jsb.Node.prototype._onParentChanged = function (oldParent) { +nodeProto._onParentChanged = function (oldParent) { this._eventProcessor(NodeEventType.PARENT_CHANGED, oldParent); -} +}; -jsb.Node.prototype._onReattach = function () { +nodeProto._onReattach = function () { this._eventProcessor.reattach(); -} +}; -jsb.Node.prototype._onRemovePersistRootNode = function () { +nodeProto._onRemovePersistRootNode = function () { legacyCC.game.removePersistRootNode(this); -} +}; -jsb.Node.prototype._onDestroyComponents = function () { +nodeProto._onDestroyComponents = function () { const comps = this._components; for (let i = 0; i < comps.length; ++i) { // destroy immediate so its _onPreDestroy can be called // TO DO comps[i]._destroyImmediate(); } -} +}; -jsb.Node.prototype._onLayerChanged = function (layer) { +nodeProto._onLayerChanged = function (layer) { this.emit(NodeEventType.LAYER_CHANGED, layer); -} +}; -jsb.Node.prototype._onChildRemoved = function (child) { +nodeProto._onChildRemoved = function (child) { this.emit(NodeEventType.CHILD_REMOVED, child); -} +}; -jsb.Node.prototype._onChildAdded = function (child) { +nodeProto._onChildAdded = function (child) { this.emit(NodeEventType.CHILD_ADDED, child); -} +}; -jsb.Node.prototype._onNodeDestroyed = function () { +nodeProto._onNodeDestroyed = function () { this.emit(NodeEventType.NODE_DESTROYED, this); -} +}; -jsb.Node.prototype._onSiblingOrderChanged = function () { +nodeProto._onSiblingOrderChanged = function () { this.emit(NodeEventType.SIBLING_ORDER_CHANGED); -} +}; -jsb.Node.prototype._onUiTransformDirty = function () { +nodeProto._onUiTransformDirty = function () { this._uiProps.uiTransformDirty = true; -} +}; -jsb.Node.prototype._onActivateNode = function (shouldActiveNow) { +nodeProto._onActivateNode = function (shouldActiveNow) { legacyCC.director._nodeActivator.activateNode(this, shouldActiveNow); -} +}; // Static functions. @@ -311,7 +309,7 @@ jsb.Node._findComponent = function (node, constructor) { } } return null; -} +}; jsb.Node._findComponents = function (node, constructor, components) { const cls = constructor as any; @@ -331,7 +329,7 @@ jsb.Node._findComponents = function (node, constructor, components) { } } } -} +}; jsb.Node._findChildComponent = function (children, constructor) { for (let i = 0; i < children.length; ++i) { @@ -350,7 +348,7 @@ jsb.Node._findChildComponent = function (children, constructor) { } } return null; -} +}; jsb.Node._findChildComponents = function (children, constructor, components) { for (let i = 0; i < children.length; ++i) { @@ -362,6 +360,6 @@ jsb.Node._findChildComponents = function (children, constructor, components) { jsb.Node._findChildComponents(childChildren, constructor, components); } } -} +}; export const Node = jsb.Node; diff --git a/cocos/core/scene-graph/scene-globals.jsb.ts b/cocos/core/scene-graph/scene-globals.jsb.ts new file mode 100644 index 00000000000..560cc4a57dc --- /dev/null +++ b/cocos/core/scene-graph/scene-globals.jsb.ts @@ -0,0 +1,56 @@ +/* + Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd. + http://www.cocos.com + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +import { legacyCC } from "../global-exports"; + +/** + * @en Environment lighting information in the Scene + * @zh 场景的环境光照相关信息 + */ +export const AmbientInfo = jsb.AmbientInfo; +legacyCC.AmbientInfo = AmbientInfo; + +/** + * @en Skybox related information + * @zh 天空盒相关信息 + */ +export const SkyboxInfo = jsb.SkyboxInfo; +legacyCC.SkyboxInfo = SkyboxInfo; + +/** + * @zh 全局雾相关信息 + * @en Global fog info + */ +export const FogInfo = jsb.FogInfo; + +/** + * @en Scene level planar shadow related information + * @zh 平面阴影相关信息 + */ +export const ShadowsInfo = jsb.ShadowsInfo; +legacyCC.ShadowsInfo = ShadowsInfo; + +/** + * @en All scene related global parameters, it affects all content in the corresponding scene + * @zh 各类场景级别的渲染参数,将影响全场景的所有物体 + */ +export const SceneGlobals = jsb.SceneGlobals; +legacyCC.SceneGlobals = SceneGlobals; diff --git a/tsconfig.json b/tsconfig.json index 66f11ed1fd2..4cf761a0d6c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,6 +23,7 @@ "./@types/globals", "./@types/consts", "./@types/jsb", + "./@types/jsb.auto", "./@types/editor-extends", "./@types/webGL.extras", "./@types/webGL2.extras", @@ -42,6 +43,7 @@ "include": [ "exports/**/*.ts", "index.ts", - "pal/**/*.ts" + "pal/**/*.ts", + "./cocos/**/*.jsb.ts", ] }