|
@@ -1,8 +1,7 @@
|
|
|
-var EShaderMode = (i=>(i[i.default = 0] = "default",
|
|
|
-i[i.video = 1] = "video",
|
|
|
-i[i.videoAndPano = 2] = "videoAndPano",
|
|
|
-i))(EShaderMode || {});
|
|
|
-class XMaterialComponent {
|
|
|
+import {logger} from "./Logger.js"
|
|
|
+import XVideoRawYUV from "./XVideoRawYUV"
|
|
|
+
|
|
|
+export default class XMaterialComponent {
|
|
|
constructor(e, t) {
|
|
|
E(this, "scene");
|
|
|
E(this, "engine");
|
|
@@ -36,12 +35,12 @@ class XMaterialComponent {
|
|
|
E(this, "_initPureVideoContent", e=>{
|
|
|
this._inputYUV420 ? this._videoRawYUVTexArray.getVideoYUVTex(0) != null && (this._lowModelShader.setTexture("texture_video", this._videoRawYUVTexArray.getVideoYUVTex(0)),
|
|
|
this._lowModelShader.setFloat("isYUV", 1),
|
|
|
- Texture.WhenAllReady([this._videoRawYUVTexArray.getVideoYUVTex(0)], ()=>{
|
|
|
+ BABYLON.Texture.WhenAllReady([this._videoRawYUVTexArray.getVideoYUVTex(0)], ()=>{
|
|
|
this._changePureVideoLowModelShaderCanvasSize(e)
|
|
|
}
|
|
|
)) : (this._videoElement = e.videoElement,
|
|
|
this._videoTexture || (this._videoTexture = new VideoTexture("InterVideoTexture",this._videoElement,this.scene,!0,!1)),
|
|
|
- Texture.WhenAllReady([this._videoTexture], ()=>{
|
|
|
+ BABYLON.Texture.WhenAllReady([this._videoTexture], ()=>{
|
|
|
this._changePureVideoLowModelShaderCanvasSize({
|
|
|
width: this._videoElement.height,
|
|
|
height: this._videoElement.width,
|
|
@@ -59,7 +58,7 @@ class XMaterialComponent {
|
|
|
, r = e.width || 720
|
|
|
, n = e.height || 1280
|
|
|
, o = r / (2 * Math.tan(Math.PI * t / 360));
|
|
|
- (a = this._lowModelShader) == null || a.setVector3("focal_width_height", new Vector3(o,r,n))
|
|
|
+ (a = this._lowModelShader) == null || a.setVector3("focal_width_height", new BABYLON.Vector3(o,r,n))
|
|
|
}
|
|
|
);
|
|
|
E(this, "updateRawYUVData", (e,t,r,n=-1)=>{
|
|
@@ -82,7 +81,7 @@ class XMaterialComponent {
|
|
|
this._scenemanager.cameraComponent.cameraFovChange(s),
|
|
|
this._scenemanager.yuvInfo = s),
|
|
|
(o = this._videoRawYUVTexArray.getVideoYUVTex(l)) == null || o.update(e),
|
|
|
- (a = this._videoRawYUVTexArray.getVideoYUVTex(l)) == null || a.updateSamplingMode(Texture.BILINEAR_SAMPLINGMODE)
|
|
|
+ (a = this._videoRawYUVTexArray.getVideoYUVTex(l)) == null || a.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
|
|
|
}
|
|
|
}
|
|
|
);
|
|
@@ -108,19 +107,19 @@ class XMaterialComponent {
|
|
|
}
|
|
|
)
|
|
|
}
|
|
|
- ).catch(n=>log$v.error(`[Engine] ${n}`)));
|
|
|
+ ).catch(n=>logger.error(`[Engine] ${n}`)));
|
|
|
E(this, "_initDefaultShader", ()=>{
|
|
|
- this._defaultShader == null && (this._defaultShader = new GridMaterial("GridShader",this.scene),
|
|
|
+ this._defaultShader == null && (this._defaultShader = new BABYLON.GridMaterial("GridShader",this.scene),
|
|
|
this._defaultShader.gridRatio = 50,
|
|
|
- this._defaultShader.lineColor = new Color3(0,0,.5),
|
|
|
+ this._defaultShader.lineColor = new BABYLON.Color3(0,0,.5),
|
|
|
this._defaultShader.majorUnitFrequency = 1,
|
|
|
- this._defaultShader.mainColor = new Color3(.6,.6,.6),
|
|
|
+ this._defaultShader.mainColor = new BABYLON.Color3(.6,.6,.6),
|
|
|
this._defaultShader.backFaceCulling = !1)
|
|
|
}
|
|
|
);
|
|
|
E(this, "_initPureVideoShader", ()=>{
|
|
|
if (this._lowModelShader == null) {
|
|
|
- const e = new ShaderMaterial("PureVideoShader",this.scene,{
|
|
|
+ const e = new BABYLON.ShaderMaterial("PureVideoShader",this.scene,{
|
|
|
vertexSource: pureVideoVertex,
|
|
|
fragmentSource: pureVideoFragment
|
|
|
},{
|
|
@@ -134,8 +133,8 @@ class XMaterialComponent {
|
|
|
e.setTexture("texture_video", null),
|
|
|
e.setFloat("isYUV", this._inputYUV420 ? 1 : 0),
|
|
|
e.setFloat("fireworkLight", 0),
|
|
|
- e.setVector3("fireworkLightPosition", new Vector3(0,0,0)),
|
|
|
- e.setVector3("focal_width_height", new Vector3(772.022491,720,1280)),
|
|
|
+ e.setVector3("fireworkLightPosition", new BABYLON.Vector3(0,0,0)),
|
|
|
+ e.setVector3("focal_width_height", new BABYLON.Vector3(772.022491,720,1280)),
|
|
|
e.backFaceCulling = !1,
|
|
|
this._lowModelShader = e
|
|
|
}
|
|
@@ -151,14 +150,14 @@ class XMaterialComponent {
|
|
|
E(this, "initDynamicTexture", (e,t,r)=>{
|
|
|
this._isInDynamicRange(e) && (this._dynamic_textures[e] != null && (this._dynamic_textures[e].dispose(),
|
|
|
this._dynamic_textures[e] = null),
|
|
|
- this._dynamic_textures[e] = new RawTexture(null,t,r * 1.5,Engine.TEXTUREFORMAT_LUMINANCE,this.scene,!1,!0,Texture.NEAREST_SAMPLINGMODE,Engine.TEXTURETYPE_UNSIGNED_BYTE),
|
|
|
+ this._dynamic_textures[e] = new BABYLON.RawTexture(null,t,r * 1.5,BABYLON.Engine.TEXTUREFORMAT_LUMINANCE,this.scene,!1,!0,BABYLON.Texture.NEAREST_SAMPLINGMODE,BABYLON.Engine.TEXTURETYPE_UNSIGNED_BYTE),
|
|
|
this._dynamic_textures[e].name = "Pano_Dynamic_" + e + "_" + Date.now())
|
|
|
}
|
|
|
);
|
|
|
- E(this, "initDynamicShaders", e=>(log$v.info("[Engine] Material init dynamic shader."),
|
|
|
+ E(this, "initDynamicShaders", e=>(logger.info("[Engine] Material init dynamic shader."),
|
|
|
new Promise((t,r)=>{
|
|
|
this._dynamic_shaders[e] != null && this._dynamic_shaders[e].dispose();
|
|
|
- const n = new ShaderMaterial("Pano_Shader_" + e,this.scene,{
|
|
|
+ const n = new BABYLON.ShaderMaterial("Pano_Shader_" + e,this.scene,{
|
|
|
vertexSource: panoVertex,
|
|
|
fragmentSource: panoFragment
|
|
|
},{
|
|
@@ -167,13 +166,13 @@ class XMaterialComponent {
|
|
|
defines: ["#define SHADOWFULLFLOAT"]
|
|
|
});
|
|
|
n.setTexture("texture_pano", null),
|
|
|
- n.setVector3("centre_pose", new Vector3(0,0,0)),
|
|
|
+ n.setVector3("centre_pose", new BABYLON.Vector3(0,0,0)),
|
|
|
n.setFloat("isYUV", this._inputPanoYUV420 ? 1 : 0),
|
|
|
n.setTexture("shadowSampler", null),
|
|
|
n.setMatrix("lightSpaceMatrix", null),
|
|
|
n.setFloat("haveShadowLight", 0),
|
|
|
n.setFloat("fireworkLight", 0),
|
|
|
- n.setVector3("fireworkLightPosition", new Vector3(0,0,0)),
|
|
|
+ n.setVector3("fireworkLightPosition", new BABYLON.Vector3(0,0,0)),
|
|
|
n.backFaceCulling = !1,
|
|
|
this._dynamic_shaders[e] = n,
|
|
|
t(!0)
|
|
@@ -229,9 +228,9 @@ class XMaterialComponent {
|
|
|
}
|
|
|
}
|
|
|
changePanoImg(e, t) {
|
|
|
- if (log$v.info(`[Engine] changePanoImg, id=${e}, pose=${t.pose.position.x},${t.pose.position.y},${t.pose.position.z}`),
|
|
|
+ if (logger.info(`[Engine] changePanoImg, id=${e}, pose=${t.pose.position.x},${t.pose.position.y},${t.pose.position.z}`),
|
|
|
!this._isInDynamicRange(e))
|
|
|
- return log$v.error(`[Engine] ${e} is bigger than dynamic size set in PanoInfo`),
|
|
|
+ return logger.error(`[Engine] ${e} is bigger than dynamic size set in PanoInfo`),
|
|
|
Promise.reject(new XMaterialError(`[Engine] ${e} is bigger than dynamic size set in PanoInfo`));
|
|
|
const r = ue4Position2Xverse(t.pose.position);
|
|
|
return r && (this._dynamic_babylonpose[e] = {
|
|
@@ -241,12 +240,12 @@ class XMaterialComponent {
|
|
|
try {
|
|
|
typeof t.data == "string" ? (this.setPanoYUV420(!1),
|
|
|
this._dynamic_textures[e].updateURL(t.data, null, ()=>{
|
|
|
- this._dynamic_textures[e].updateSamplingMode(Texture.NEAREST_SAMPLINGMODE)
|
|
|
+ this._dynamic_textures[e].updateSamplingMode(BABYLON.Texture.NEAREST_SAMPLINGMODE)
|
|
|
}
|
|
|
)) : (this.isPanoYUV420() == !1 && this.initDynamicTexture(e, this._panoInfo.width, this._panoInfo.height),
|
|
|
this.setPanoYUV420(!0),
|
|
|
this._dynamic_textures[e].update(t.data),
|
|
|
- this._dynamic_textures[e].updateSamplingMode(Texture.NEAREST_SAMPLINGMODE)),
|
|
|
+ this._dynamic_textures[e].updateSamplingMode(BABYLON.Texture.NEAREST_SAMPLINGMODE)),
|
|
|
n(this)
|
|
|
} catch (a) {
|
|
|
o(new XMaterialError(`[Engine] ChangePanoImg Error! ${a}`))
|
|
@@ -288,7 +287,7 @@ class XMaterialComponent {
|
|
|
}
|
|
|
);
|
|
|
else {
|
|
|
- const h = new PointLight("fireworkLight",new Vector3(0,0,0),this.scene);
|
|
|
+ const h = new BABYLON.PointLight("fireworkLight",new BABYLON.Vector3(0,0,0),this.scene);
|
|
|
h.intensity = 0
|
|
|
}
|
|
|
}
|
|
@@ -308,7 +307,7 @@ class XMaterialComponent {
|
|
|
}
|
|
|
);
|
|
|
else {
|
|
|
- const f = new PointLight("fireworkLight",new Vector3(0,0,0),this.scene);
|
|
|
+ const f = new BABYLON.PointLight("fireworkLight",new BABYLON.Vector3(0,0,0),this.scene);
|
|
|
f.intensity = 0
|
|
|
}
|
|
|
}
|