Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/layabox/LayaAir
Browse files Browse the repository at this point in the history
  • Loading branch information
LayaCharley committed Nov 24, 2020
2 parents e12cb97 + 6e5e6d6 commit ebebb66
Show file tree
Hide file tree
Showing 21 changed files with 213 additions and 196 deletions.
1 change: 1 addition & 0 deletions bin/indexTSC.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
</script>
<script src='astar.js'></script>
<script src='laya.physics3D.js'></script>
<!-- <script src='laya.physics3D.wasm.js'></script> -->
<script src='cannon.js'></script>
<script src='tsc/samples/index.js' type='module-shim' ></script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion src/layaAir/jsLibs/box2d.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/layaAir/laya/d3/core/Camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ export class Camera extends BaseCamera {
var gl: WebGLRenderingContext = LayaGL.instance;
var context: RenderContext3D = RenderContext3D._instance;
var scene: Scene3D = context.scene = <Scene3D>this._scene;
context.pipelineMode = "Forward";
context.pipelineMode = context.configPipeLineMode;

if (needInternalRT) {
this._internalRenderTexture = RenderTexture.createFromPool(viewport.width, viewport.height, this._getRenderTextureFormat(), RenderTextureDepthFormat.DEPTH_16);
Expand Down
2 changes: 2 additions & 0 deletions src/layaAir/laya/d3/core/render/RenderContext3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export class RenderContext3D {
invertY: boolean = false;
/** @internal */
pipelineMode: string;
/** @internal */
configPipeLineMode:string = "Forward";

/**
* 创建一个 <code>RenderContext3D</code> 实例。
Expand Down
92 changes: 45 additions & 47 deletions src/layaAir/laya/d3/core/scene/Scene3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource {
default:
throw "Scene3D:unknown shader quality.";
}
if(config.isUseCannonPhysicsEngine){
Scene3D.cannonPhysicsSettings = new CannonPhysicsSettings();
}else{
if (config.isUseCannonPhysicsEngine) {
Scene3D.cannonPhysicsSettings = new CannonPhysicsSettings();
} else {
Scene3D.physicsSettings = new PhysicsSettings();
}
}
Expand Down Expand Up @@ -284,13 +284,13 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource {
/** @internal */
_mainDirectionLight: DirectionLight;
/** @internal */
_mainSpotLight:SpotLight;
_mainSpotLight: SpotLight;
/** @internal */
_mainPointLight:PointLight;//TODO
_mainPointLight: PointLight;//TODO
/** @internal */
_physicsSimulation: PhysicsSimulation;
/** @internal */
_cannonPhysicsSimulation:CannonPhysicsSimulation;
_cannonPhysicsSimulation: CannonPhysicsSimulation;
/** @internal */
_octree: BoundsOctree;
/** @internal 只读,不允许修改。*/
Expand All @@ -317,7 +317,7 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource {
/** @internal */
_reflectionCubeHDRParams: Vector4 = new Vector4();
/** @internal */
_reflectionProbeManager:ReflectionProbeManager = new ReflectionProbeManager();
_reflectionProbeManager: ReflectionProbeManager = new ReflectionProbeManager();



Expand Down Expand Up @@ -470,10 +470,11 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource {
}

set reflection(value: TextureCube) {
value = value ? value : TextureCube.blackTexture;
if (this._reflection != value) {
value._addReference();
this._reflectionProbeManager.sceneReflectionProbe = value;
this._reflection = value || TextureCube.blackTexture;
this._reflection = value
this._reflectionProbeManager._needUpdateAllRender = true;

}
Expand Down Expand Up @@ -526,7 +527,7 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource {
return this._physicsSimulation;
}

get cannonPhysicsSimulation():CannonPhysicsSimulation{
get cannonPhysicsSimulation(): CannonPhysicsSimulation {
return this._cannonPhysicsSimulation;
}
/**
Expand Down Expand Up @@ -583,13 +584,13 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource {
*/
constructor() {
super();
if(!Config3D._config.isUseCannonPhysicsEngine&&Physics3D._bullet)
if (!Config3D._config.isUseCannonPhysicsEngine && Physics3D._bullet)
this._physicsSimulation = new PhysicsSimulation(Scene3D.physicsSettings);
else if(Physics3D._cannon){
else if (Physics3D._cannon) {
this._cannonPhysicsSimulation = new CannonPhysicsSimulation(Scene3D.cannonPhysicsSettings);
}


this._shaderValues = new ShaderData(null);

this.enableFog = false;
Expand Down Expand Up @@ -662,7 +663,7 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource {
this._shaderValues.setNumber(Scene3D.TIME, this._time);

var simulation: PhysicsSimulation = this._physicsSimulation;
if (Physics3D._enablePhysics && !PhysicsSimulation.disableSimulation&&!Config3D._config.isUseCannonPhysicsEngine) {
if (Physics3D._enablePhysics && !PhysicsSimulation.disableSimulation && !Config3D._config.isUseCannonPhysicsEngine) {
simulation._updatePhysicsTransformFromRender();
PhysicsComponent._addUpdateList = false;//物理模拟器会触发_updateTransformComponent函数,不加入更新队列
//simulate physics
Expand All @@ -677,8 +678,8 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource {
//send contact events
simulation._eventScripts();
}
if(Physics3D._cannon&&Config3D._config.isUseCannonPhysicsEngine){
var cannonSimulation:CannonPhysicsSimulation = this._cannonPhysicsSimulation;
if (Physics3D._cannon && Config3D._config.isUseCannonPhysicsEngine) {
var cannonSimulation: CannonPhysicsSimulation = this._cannonPhysicsSimulation;
cannonSimulation._updatePhysicsTransformFromRender();
CannonPhysicsComponent._addUpdateList = false;
cannonSimulation._simulate(delta);
Expand All @@ -692,7 +693,7 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource {
this._updateScript();
Animator._update(this);
VideoTexture._update();
if(this._reflectionProbeManager._needUpdateAllRender)
if (this._reflectionProbeManager._needUpdateAllRender)
this._reflectionProbeManager.updateAllRenderObjects(this._renders);
else
this._reflectionProbeManager.update();
Expand Down Expand Up @@ -864,7 +865,7 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource {
var sunLightIndex: number = this._directionLights.getBrightestLight();//get the brightest light as sun
this._mainDirectionLight = dirElements[sunLightIndex];
this._directionLights.normalLightOrdering(sunLightIndex);
for (var i: number = 0; i < dirCount; i++ , curCount++) {
for (var i: number = 0; i < dirCount; i++, curCount++) {
var dirLight: DirectionLight = dirElements[i];
var dir: Vector3 = dirLight._direction;
var intCor: Vector3 = dirLight._intensityColor;
Expand Down Expand Up @@ -892,10 +893,10 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource {
var poiCount: number = this._pointLights._length;
if (poiCount > 0) {
var poiElements: PointLight[] = this._pointLights._elements;
var mainPointLightIndex:number = this._pointLights.getBrightestLight();
var mainPointLightIndex: number = this._pointLights.getBrightestLight();
this._mainPointLight = poiElements[mainPointLightIndex];
this._pointLights.normalLightOrdering(mainPointLightIndex);
for (var i: number = 0; i < poiCount; i++ , curCount++) {
for (var i: number = 0; i < poiCount; i++, curCount++) {
var poiLight: PointLight = poiElements[i];
var pos: Vector3 = poiLight.transform.position;
var intCor: Vector3 = poiLight._intensityColor;
Expand All @@ -918,10 +919,10 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource {
var spoCount: number = this._spotLights._length;
if (spoCount > 0) {
var spoElements: SpotLight[] = this._spotLights._elements;
var mainSpotLightIndex:number = this._spotLights.getBrightestLight();
var mainSpotLightIndex: number = this._spotLights.getBrightestLight();
this._mainSpotLight = spoElements[mainSpotLightIndex];
this._spotLights.normalLightOrdering(mainSpotLightIndex)
for (var i: number = 0; i < spoCount; i++ , curCount++) {
for (var i: number = 0; i < spoCount; i++, curCount++) {
var spoLight: SpotLight = spoElements[i];
var dir: Vector3 = spoLight._direction;
var pos: Vector3 = spoLight.transform.position;
Expand Down Expand Up @@ -1160,10 +1161,9 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource {
/**
* @internal 渲染Scene的各个管线
*/
_renderScene(context: RenderContext3D,renderFlag:number): void {
_renderScene(context: RenderContext3D, renderFlag: number): void {
var camera: Camera = <Camera>context.camera;
switch(renderFlag)
{
switch (renderFlag) {
case Scene3D.SCENERENDERFLAG_RENDERQPAQUE:
this._opaqueQueue._render(context);//非透明队列
break;
Expand Down Expand Up @@ -1308,8 +1308,7 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource {
/**
* @internal
*/
_clearRenderQueue():void
{
_clearRenderQueue(): void {
this._opaqueQueue.clear();
this._transparentQueue.clear();
var staticBatchManagers: StaticBatchManager[] = StaticBatchManager._managers;
Expand Down Expand Up @@ -1346,8 +1345,8 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource {
if (maps) {
for (var i: number = 0, n: number = maps.length; i < n; i++) {
var map: Lightmap = maps[i];
map.lightmapColor&&map.lightmapColor._removeReference();
map.lightmapDirection&&map.lightmapDirection._removeReference();
map.lightmapColor && map.lightmapColor._removeReference();
map.lightmapDirection && map.lightmapDirection._removeReference();
}
}
this._lightmaps = null;
Expand Down Expand Up @@ -1402,49 +1401,48 @@ export class Scene3D extends Sprite implements ISubmit, ICreateResource {
reUse(context: Context, pos: number): number {
return 0;
}

/**
* 设置全局渲染数据
* @param name 数据对应着色器名字
* @param shaderDataType 渲染数据类型
* @param value 渲染数据值
*/
setGlobalShaderValue(name:string,shaderDataType:ShaderDataType,value:any){
var shaderOffset = Shader3D.propertyNameToID(name);
switch(shaderDataType)
{
setGlobalShaderValue(name: string, shaderDataType: ShaderDataType, value: any) {
var shaderOffset = Shader3D.propertyNameToID(name);
switch (shaderDataType) {
case ShaderDataType.Int:
this._shaderValues.setInt(shaderOffset,value);
this._shaderValues.setInt(shaderOffset, value);
break;
case ShaderDataType.Number:
this._shaderValues.setNumber(shaderOffset,value);
this._shaderValues.setNumber(shaderOffset, value);
break;
case ShaderDataType.Bool:
this._shaderValues.setBool(shaderOffset,value);
this._shaderValues.setBool(shaderOffset, value);
break;
case ShaderDataType.Matrix4x4:
this._shaderValues.setMatrix4x4(shaderOffset,value);
this._shaderValues.setMatrix4x4(shaderOffset, value);
break;
case ShaderDataType.Quaternion:
this._shaderValues.setQuaternion(shaderOffset,value);
this._shaderValues.setQuaternion(shaderOffset, value);
break;
case ShaderDataType.Texture:
this._shaderValues.setTexture(shaderOffset,value);
this._shaderValues.setTexture(shaderOffset, value);
break;
case ShaderDataType.Vector:
this._shaderValues.setVector(shaderOffset,value);
this._shaderValues.setVector(shaderOffset, value);
break;
case ShaderDataType.Vector2:
this._shaderValues.setVector2(shaderOffset,value);
this._shaderValues.setVector2(shaderOffset, value);
break;
case ShaderDataType.Vector3:
this._shaderValues.setVector3(shaderOffset,value);
this._shaderValues.setVector3(shaderOffset, value);
break;
case ShaderDataType.Buffer:
this._shaderValues.setBuffer(shaderOffset,value);
break;
}
this._shaderValues.setBuffer(shaderOffset, value);
break;
}

}


Expand Down
4 changes: 2 additions & 2 deletions src/layaAir/laya/d3/core/trail/TrailGeometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ export class TrailGeometry extends GeometryElement {
var oldSubBirthTime: Float32Array = new Float32Array(this._subBirthTime.buffer, this._activeIndex * 4, count);//修改出生时间数据

if (count === this._segementCount) {//当前count=_segementCount表示已满,需要扩充
this._vertexBuffer1.destroy();
this._vertexBuffer2.destroy();
var memorySize: number = this._vertexBuffer1._byteLength + this._vertexBuffer2._byteLength;
Resource._addMemory(-memorySize, -memorySize);
this._vertexBuffer1.destroy();
this._vertexBuffer2.destroy();
this._segementCount += this._increaseSegementCount;
this._resizeData(this._segementCount, this._bufferState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ export class ConfigurableConstraint extends ConstraintComponent{

_onDisable():void{
super._onDisable();
if(!this.connectedBody)
if(!this.connectedBody&&this._simulation)
this._removeFromSimulation();
if(this._btConstraint)
Physics3D._bullet.btTypedConstraint_setEnabled(this._btConstraint,false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class ConstraintComponent extends Component {
/**@internal */
set connectedBody(value:Rigidbody3D){
this._connectedBody = value;
value.constaintRigidbodyB = this;
value && (value.constaintRigidbodyB = this);
}

/**
Expand Down Expand Up @@ -332,7 +332,7 @@ export class ConstraintComponent extends Component {
*/
protected _onDestroy(): void {
var physics3D: any = Physics3D._bullet;
this._removeFromSimulation();
this._simulation&&this._removeFromSimulation();
if(this._btConstraint&&this._btJointFeedBackObj&&this._simulation){
physics3D.btTypedConstraint_destroy(this._btConstraint);
physics3D.btJointFeedback_destroy(this._btJointFeedBackObj);
Expand Down Expand Up @@ -387,7 +387,7 @@ export class ConstraintComponent extends Component {
*/
_breakConstrained():void{
this.ownBody.constaintRigidbodyA=null;
this.connectedBody.constaintRigidbodyB=null;
this.connectedBody && (this.connectedBody.constaintRigidbodyB=null);
this.destroy();
}

Expand Down
7 changes: 6 additions & 1 deletion src/layaAir/laya/d3/resource/TextureCube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { BaseTexture } from "../../resource/BaseTexture"
import { LayaGL } from "../../layagl/LayaGL";
import { ILaya } from "../../../ILaya";
import { TextureFormat } from "../../resource/TextureFormat";
import { LoaderManager } from "../../net/LoaderManager";
import { Utils } from "../../utils/Utils";


export enum TextureCubeFace {
Expand All @@ -28,6 +30,7 @@ export enum TextureCubeFace {
export class TextureCube extends BaseTexture {
/**TextureCube资源。*/
static TEXTURECUBE: string = "TEXTURECUBE";
static TEXTURECUBEBIN:string = "TEXTURECUBEBIN";

/**@private*/
private static _blackTexture: TextureCube;
Expand Down Expand Up @@ -89,7 +92,9 @@ export class TextureCube extends BaseTexture {
* @param complete 完成回调。
*/
static load(url: string, complete: Handler): void {
ILaya.loader.create(url, complete, null, TextureCube.TEXTURECUBE);
var extension = (LoaderManager.createMap[Utils.getFilecompatibleExtension(url)]) ? Utils.getFilecompatibleExtension(url) : Utils.getFileExtension(url);
var type = LoaderManager.createMap[extension] ? LoaderManager.createMap[extension][0] : null
ILaya.loader.create(url, complete, null, type);
}

/**
Expand Down
Loading

0 comments on commit ebebb66

Please sign in to comment.