|
@@ -3,301 +3,289 @@ import Logger from "./Logger.js";
|
|
|
|
|
|
const logger = new Logger("XMaterial");
|
|
|
export default class XMaterialComponent {
|
|
|
- constructor(e, t) {
|
|
|
- E(this, "scene");
|
|
|
- E(this, "engine");
|
|
|
- E(this, "yuvInfo");
|
|
|
- E(this, "shaderMode");
|
|
|
- E(this, "_panoInfo");
|
|
|
- E(this, "_dynamic_size");
|
|
|
- E(this, "_dynamic_babylonpose");
|
|
|
- E(this, "_dynamic_textures");
|
|
|
- E(this, "_dynamic_shaders");
|
|
|
- E(this, "_scenemanager");
|
|
|
- E(this, "_videoTexture");
|
|
|
- E(this, "_videoElement");
|
|
|
- E(this, "_lowModelShader");
|
|
|
- E(this, "_defaultShader");
|
|
|
- E(this, "_inputYUV420", !0);
|
|
|
- E(this, "_inputPanoYUV420", !0);
|
|
|
- E(this, "_videoRawYUVTexArray");
|
|
|
- E(this, "_isUpdateYUV", !0);
|
|
|
- E(
|
|
|
- this,
|
|
|
- "initMaterial",
|
|
|
- async () =>
|
|
|
- new Promise((resolve, t) => {
|
|
|
- this._initDefaultShader();
|
|
|
- if (this.shaderMode == 2) {
|
|
|
- this.initDynamicData(
|
|
|
- this._panoInfo.dynamicRange,
|
|
|
- this._panoInfo.width,
|
|
|
- this._panoInfo.height
|
|
|
- ).then(() => {
|
|
|
- this._initPureVideoShader();
|
|
|
- this._prepareRender(this.yuvInfo);
|
|
|
- });
|
|
|
- } else if (this.shaderMode == 1) {
|
|
|
- this._initPureVideoShader();
|
|
|
- this._prepareRender(this.yuvInfo);
|
|
|
- }
|
|
|
- // else if(this.shaderMode == 0){
|
|
|
- // resolve(!0)
|
|
|
- // }
|
|
|
- resolve(!0);
|
|
|
- // this.shaderMode == 2 ? this.initDynamicData(this._panoInfo.dynamicRange, this._panoInfo.width, this._panoInfo.height).then(()=>{
|
|
|
- // this._initPureVideoShader(),
|
|
|
- // this._prepareRender(this.yuvInfo)
|
|
|
- // }
|
|
|
- // ) : this.shaderMode == 1 ? (this._initPureVideoShader(),
|
|
|
- // this._prepareRender(this.yuvInfo)) : this.shaderMode == 0,
|
|
|
- // resolve(!0)
|
|
|
- })
|
|
|
- );
|
|
|
+ constructor(sceneManager, t) {
|
|
|
+ this.scene
|
|
|
+ this.engine
|
|
|
+ this.yuvInfo
|
|
|
+ this.shaderMode
|
|
|
+ this._panoInfo
|
|
|
+ this._dynamic_size
|
|
|
+ this._dynamic_babylonpose
|
|
|
+ this._dynamic_textures
|
|
|
+ this._dynamic_shaders
|
|
|
+ this._scenemanager
|
|
|
+ this._videoTexture
|
|
|
+ this._videoElement
|
|
|
+ this._lowModelShader
|
|
|
+ this._defaultShader
|
|
|
+ this._inputYUV420 = !0
|
|
|
+ this._inputPanoYUV420 = !0
|
|
|
+ this._videoRawYUVTexArray
|
|
|
+ this._isUpdateYUV = !0
|
|
|
|
|
|
- E(this, "_initPureVideoContent", (focal_width_height) => {
|
|
|
- if (this._inputYUV420) {
|
|
|
- if (this._videoRawYUVTexArray.getVideoYUVTex(0) != null) {
|
|
|
- this._lowModelShader.setTexture(
|
|
|
- "texture_video",
|
|
|
- this._videoRawYUVTexArray.getVideoYUVTex(0)
|
|
|
- );
|
|
|
- this._lowModelShader.setFloat("isYUV", 1);
|
|
|
- BABYLON.Texture.WhenAllReady(
|
|
|
- [this._videoRawYUVTexArray.getVideoYUVTex(0)],
|
|
|
- () => {
|
|
|
- this._changePureVideoLowModelShaderCanvasSize(focal_width_height);
|
|
|
- }
|
|
|
- );
|
|
|
- }
|
|
|
+ this._scenemanager = sceneManager
|
|
|
+ this.scene = sceneManager.Scene
|
|
|
+ this.engine = this.scene.getEngine()
|
|
|
+ this.shaderMode = 1
|
|
|
+ this._dynamic_textures = []
|
|
|
+ this._dynamic_shaders = []
|
|
|
+ this._dynamic_babylonpose = []
|
|
|
+ this._videoRawYUVTexArray = new XVideoRawYUV(
|
|
|
+ this.scene,
|
|
|
+ t.videoResOriArray
|
|
|
+ )
|
|
|
+ this.shaderMode = t.shaderMode
|
|
|
+ t.yuvInfo && (this.yuvInfo = t.yuvInfo),
|
|
|
+ t.panoInfo && this.setPanoInfo(t.panoInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ initMaterial = async () => {
|
|
|
+ return new Promise((resolve, t) => {
|
|
|
+ this._initDefaultShader();
|
|
|
+ if (this.shaderMode == 2) {
|
|
|
+ this.initDynamicData(
|
|
|
+ this._panoInfo.dynamicRange,
|
|
|
+ this._panoInfo.width,
|
|
|
+ this._panoInfo.height
|
|
|
+ ).then(() => {
|
|
|
+ this._initPureVideoShader();
|
|
|
+ this._prepareRender(this.yuvInfo);
|
|
|
+ });
|
|
|
+ } else if (this.shaderMode == 1) {
|
|
|
+ this._initPureVideoShader();
|
|
|
+ this._prepareRender(this.yuvInfo);
|
|
|
}
|
|
|
- // else{
|
|
|
- // this._videoElement = e.videoElement;
|
|
|
- // this._videoTexture || (this._videoTexture = new VideoTexture("InterVideoTexture",this._videoElement,this.scene,!0,!1));
|
|
|
- // BABYLON.Texture.WhenAllReady([this._videoTexture], ()=>{
|
|
|
- // this._changePureVideoLowModelShaderCanvasSize({
|
|
|
- // width: this._videoElement.height,
|
|
|
- // height: this._videoElement.width,
|
|
|
- // fov: e.fov
|
|
|
- // })
|
|
|
- // });
|
|
|
- // this._lowModelShader.setTexture("texture_video", this._videoTexture);
|
|
|
- // this._lowModelShader.setFloat("isYUV", 0);
|
|
|
+ // else if(this.shaderMode == 0){
|
|
|
+ // resolve(!0)
|
|
|
+ // }
|
|
|
+ resolve(!0);
|
|
|
+ // this.shaderMode == 2 ? this.initDynamicData(this._panoInfo.dynamicRange, this._panoInfo.width, this._panoInfo.height).then(()=>{
|
|
|
+ // this._initPureVideoShader(),
|
|
|
+ // this._prepareRender(this.yuvInfo)
|
|
|
// }
|
|
|
- });
|
|
|
-
|
|
|
- E(this, "_changePureVideoLowModelShaderCanvasSize", (e) => {
|
|
|
- var lowModelShader;
|
|
|
- const fov = e.fov || 50;
|
|
|
- const width = e.width || 720;
|
|
|
- const height = e.height || 1280;
|
|
|
- const focus = width / (2 * Math.tan((Math.PI * fov) / 360));
|
|
|
- (lowModelShader = this._lowModelShader) == null ||
|
|
|
- lowModelShader.setVector3(
|
|
|
- "focal_width_height",
|
|
|
- new BABYLON.Vector3(focus, width, height)
|
|
|
+ // ) : this.shaderMode == 1 ? (this._initPureVideoShader(),
|
|
|
+ // this._prepareRender(this.yuvInfo)) : this.shaderMode == 0,
|
|
|
+ // resolve(!0)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ _initPureVideoContent = (focal_width_height) => {
|
|
|
+ if (this._inputYUV420) {
|
|
|
+ if (this._videoRawYUVTexArray.getVideoYUVTex(0) != null) {
|
|
|
+ this._lowModelShader.setTexture(
|
|
|
+ "texture_video",
|
|
|
+ this._videoRawYUVTexArray.getVideoYUVTex(0)
|
|
|
);
|
|
|
- });
|
|
|
-
|
|
|
- E(this, "updateRawYUVData", (stream, width, height, fov=-1)=>{
|
|
|
- fov == -1 && (fov = this.yuvInfo.fov);
|
|
|
-
|
|
|
- if (this._isUpdateYUV == !0) {
|
|
|
- console.log('执行:updateRawYUVData')
|
|
|
- const yuvInfo = { width, height, fov }
|
|
|
- const videosResOriArrayIndex = this._videoRawYUVTexArray.findId(width, height)
|
|
|
- const currentVideoId = this._videoRawYUVTexArray.getCurrentVideoTexId();
|
|
|
-
|
|
|
- if(currentVideoId < 0 || videosResOriArrayIndex != currentVideoId || fov != this.yuvInfo.fov)
|
|
|
- {
|
|
|
- this.yuvInfo.width = width;
|
|
|
- this.yuvInfo.height = height;
|
|
|
- this.yuvInfo.fov = fov;
|
|
|
-
|
|
|
- this._videoRawYUVTexArray.setCurrentVideoTexId(videosResOriArrayIndex);
|
|
|
- this._changeVideoRes(videosResOriArrayIndex); // 设置texture_video
|
|
|
- this._changePureVideoLowModelShaderCanvasSize(yuvInfo); // 设置focal_width_height
|
|
|
- this._scenemanager.cameraComponent.cameraFovChange(yuvInfo);
|
|
|
- this._scenemanager.yuvInfo = yuvInfo;
|
|
|
- }
|
|
|
+ this._lowModelShader.setFloat("isYUV", 1);
|
|
|
+ BABYLON.Texture.WhenAllReady(
|
|
|
+ [this._videoRawYUVTexArray.getVideoYUVTex(0)],
|
|
|
+ () => {
|
|
|
+ this._changePureVideoLowModelShaderCanvasSize(focal_width_height);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // else{
|
|
|
+ // this._videoElement = e.videoElement;
|
|
|
+ // this._videoTexture || (this._videoTexture = new VideoTexture("InterVideoTexture",this._videoElement,this.scene,!0,!1));
|
|
|
+ // BABYLON.Texture.WhenAllReady([this._videoTexture], ()=>{
|
|
|
+ // this._changePureVideoLowModelShaderCanvasSize({
|
|
|
+ // width: this._videoElement.height,
|
|
|
+ // height: this._videoElement.width,
|
|
|
+ // fov: e.fov
|
|
|
+ // })
|
|
|
+ // });
|
|
|
+ // this._lowModelShader.setTexture("texture_video", this._videoTexture);
|
|
|
+ // this._lowModelShader.setFloat("isYUV", 0);
|
|
|
+ // }
|
|
|
+ }
|
|
|
|
|
|
- let VideoTexture = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)
|
|
|
- if(VideoTexture != null){
|
|
|
- // 更新视频流
|
|
|
- VideoTexture.update(stream)
|
|
|
- VideoTexture.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
|
|
|
- }
|
|
|
+ _changePureVideoLowModelShaderCanvasSize = (e) => {
|
|
|
+ var lowModelShader;
|
|
|
+ const fov = e.fov || 50;
|
|
|
+ const width = e.width || 720;
|
|
|
+ const height = e.height || 1280;
|
|
|
+ const focus = width / (2 * Math.tan((Math.PI * fov) / 360));
|
|
|
+ (lowModelShader = this._lowModelShader) == null ||
|
|
|
+ lowModelShader.setVector3(
|
|
|
+ "focal_width_height",
|
|
|
+ new BABYLON.Vector3(focus, width, height)
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
- //var o, a
|
|
|
- //(o = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || o.update(stream),
|
|
|
- //(a = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || a.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
|
|
|
- }
|
|
|
- });
|
|
|
+ updateRawYUVData = (stream, width, height, fov = -1) => {
|
|
|
+ fov == -1 && (fov = this.yuvInfo.fov);
|
|
|
|
|
|
- E(this, "_changeVideoRes", (e) => {
|
|
|
- this._lowModelShader.setTexture(
|
|
|
- "texture_video",
|
|
|
- this._videoRawYUVTexArray.getVideoYUVTex(e)
|
|
|
- );
|
|
|
- });
|
|
|
-
|
|
|
- E(this, "initDynamicData", (dynamicRange, width, height) =>
|
|
|
- new Promise((resolve, reject) => {
|
|
|
- this.setDynamicSize(dynamicRange).then((a) => {
|
|
|
- if (a) {
|
|
|
- for (let s = 0; s < dynamicRange; ++s)
|
|
|
- ((l) => {
|
|
|
- this.initDynamicTexture(l, width, height),
|
|
|
- this.initDynamicShaders(l).then(() => {
|
|
|
- this._updatePanoShaderInput(l);
|
|
|
- });
|
|
|
- })(s);
|
|
|
- resolve(!0);
|
|
|
- } else
|
|
|
- reject(
|
|
|
- new XMaterialError(
|
|
|
- `[Engine] DynamicRoomSize (${dynamicRange}) is too small`
|
|
|
- )
|
|
|
- );
|
|
|
- });
|
|
|
- }).catch((n) => logger.error(`[Engine] ${n}`))
|
|
|
- );
|
|
|
+ if (this._isUpdateYUV == !0) {
|
|
|
+ console.log('执行:updateRawYUVData')
|
|
|
+ const yuvInfo = { width, height, fov }
|
|
|
+ const videosResOriArrayIndex = this._videoRawYUVTexArray.findId(width, height)
|
|
|
+ const currentVideoId = this._videoRawYUVTexArray.getCurrentVideoTexId();
|
|
|
|
|
|
- E(this, "_initDefaultShader", () => {
|
|
|
- this._defaultShader == null &&
|
|
|
- ((this._defaultShader = new BABYLON.GridMaterial(
|
|
|
- "GridShader",
|
|
|
- this.scene
|
|
|
- )),
|
|
|
- (this._defaultShader.gridRatio = 50),
|
|
|
- (this._defaultShader.lineColor = new BABYLON.Color3(0, 0, 0.5)),
|
|
|
- (this._defaultShader.majorUnitFrequency = 1),
|
|
|
- (this._defaultShader.mainColor = new BABYLON.Color3(0.6, 0.6, 0.6)),
|
|
|
- (this._defaultShader.backFaceCulling = !1));
|
|
|
- });
|
|
|
- E(this, "_initPureVideoShader", () => {
|
|
|
- if (this._lowModelShader == null) {
|
|
|
- const e = new BABYLON.ShaderMaterial(
|
|
|
- "PureVideoShader",
|
|
|
- this.scene,
|
|
|
- {
|
|
|
- vertexSource: pureVideoVertex,
|
|
|
- fragmentSource: pureVideoFragment,
|
|
|
- },
|
|
|
- {
|
|
|
- attributes: [
|
|
|
- "uv",
|
|
|
- "position",
|
|
|
- "world0",
|
|
|
- "world1",
|
|
|
- "world2",
|
|
|
- "world3",
|
|
|
- ],
|
|
|
- uniforms: ["view", "projection", "worldViewProjection", "world"],
|
|
|
- defines: ["#define SHADOWFULLFLOAT"],
|
|
|
- }
|
|
|
- );
|
|
|
- e.setTexture("shadowSampler", null),
|
|
|
- e.setMatrix("lightSpaceMatrix", null),
|
|
|
- e.setFloat("haveShadowLight", 0),
|
|
|
- e.setTexture("texture_video", null),
|
|
|
- e.setFloat("isYUV", this._inputYUV420 ? 1 : 0),
|
|
|
- e.setFloat("fireworkLight", 0),
|
|
|
- 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);
|
|
|
+ if (currentVideoId < 0 || videosResOriArrayIndex != currentVideoId || fov != this.yuvInfo.fov) {
|
|
|
+ this.yuvInfo.width = width;
|
|
|
+ this.yuvInfo.height = height;
|
|
|
+ this.yuvInfo.fov = fov;
|
|
|
+
|
|
|
+ this._videoRawYUVTexArray.setCurrentVideoTexId(videosResOriArrayIndex);
|
|
|
+ this._changeVideoRes(videosResOriArrayIndex); // 设置texture_video
|
|
|
+ this._changePureVideoLowModelShaderCanvasSize(yuvInfo); // 设置focal_width_height
|
|
|
+ this._scenemanager.cameraComponent.cameraFovChange(yuvInfo);
|
|
|
+ this._scenemanager.yuvInfo = yuvInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ let VideoTexture = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)
|
|
|
+ if (VideoTexture != null) {
|
|
|
+ // 更新视频流
|
|
|
+ VideoTexture.update(stream)
|
|
|
+ VideoTexture.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
|
|
|
}
|
|
|
- });
|
|
|
- E(
|
|
|
- this,
|
|
|
- "setDynamicSize",
|
|
|
- (e) =>
|
|
|
- new Promise((t, r) => {
|
|
|
- e >= 1 && e <= 100
|
|
|
- ? ((this._dynamic_size = e), t(!0))
|
|
|
- : ((this._dynamic_size = 1), t(!1));
|
|
|
- })
|
|
|
+
|
|
|
+ //var o, a
|
|
|
+ //(o = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || o.update(stream),
|
|
|
+ //(a = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || a.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ _changeVideoRes = (e) => {
|
|
|
+ this._lowModelShader.setTexture(
|
|
|
+ "texture_video",
|
|
|
+ this._videoRawYUVTexArray.getVideoYUVTex(e)
|
|
|
);
|
|
|
- E(this, "_isInDynamicRange", (e) => e < this._dynamic_size && e >= 0);
|
|
|
- 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 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) => (
|
|
|
- logger.info("[Engine] Material init dynamic shader."),
|
|
|
- new Promise((t, r) => {
|
|
|
- this._dynamic_shaders[e] != null &&
|
|
|
- this._dynamic_shaders[e].dispose();
|
|
|
- const n = new BABYLON.ShaderMaterial(
|
|
|
- "Pano_Shader_" + e,
|
|
|
- this.scene,
|
|
|
- {
|
|
|
- vertexSource: panoVertex,
|
|
|
- fragmentSource: panoFragment,
|
|
|
- },
|
|
|
- {
|
|
|
- attributes: [
|
|
|
- "uv",
|
|
|
- "position",
|
|
|
- "world0",
|
|
|
- "world1",
|
|
|
- "world2",
|
|
|
- "world3",
|
|
|
- ],
|
|
|
- uniforms: ["view", "projection", "worldViewProjection", "world"],
|
|
|
- defines: ["#define SHADOWFULLFLOAT"],
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ initDynamicData = (dynamicRange, width, height) => {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ this.setDynamicSize(dynamicRange).then((a) => {
|
|
|
+ if (a) {
|
|
|
+ for (let s = 0; s < dynamicRange; ++s)
|
|
|
+ ((l) => {
|
|
|
+ this.initDynamicTexture(l, width, height),
|
|
|
+ this.initDynamicShaders(l).then(() => {
|
|
|
+ this._updatePanoShaderInput(l);
|
|
|
+ });
|
|
|
+ })(s);
|
|
|
+ resolve(!0);
|
|
|
+ } else
|
|
|
+ reject(
|
|
|
+ new XMaterialError(
|
|
|
+ `[Engine] DynamicRoomSize (${dynamicRange}) is too small`
|
|
|
+ )
|
|
|
);
|
|
|
- n.setTexture("texture_pano", null),
|
|
|
- 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 BABYLON.Vector3(0, 0, 0)),
|
|
|
- (n.backFaceCulling = !1),
|
|
|
- (this._dynamic_shaders[e] = n),
|
|
|
- t(!0);
|
|
|
- })
|
|
|
+ });
|
|
|
+ }).catch((n) => logger.error(`[Engine] ${n}`))
|
|
|
+ }
|
|
|
+
|
|
|
+ _initDefaultShader = () => {
|
|
|
+ if(this._defaultShader == null) {
|
|
|
+ this._defaultShader = new BABYLON.GridMaterial(
|
|
|
+ "GridShader",
|
|
|
+ this.scene
|
|
|
)
|
|
|
- );
|
|
|
- (this._scenemanager = e),
|
|
|
- (this.scene = e.Scene),
|
|
|
- (this.engine = this.scene.getEngine()),
|
|
|
- (this.shaderMode = 1),
|
|
|
- (this._dynamic_textures = []),
|
|
|
- (this._dynamic_shaders = []),
|
|
|
- (this._dynamic_babylonpose = []),
|
|
|
- (this._videoRawYUVTexArray = new XVideoRawYUV(
|
|
|
- this.scene,
|
|
|
- t.videoResOriArray
|
|
|
- )),
|
|
|
- (this.shaderMode = t.shaderMode),
|
|
|
- t.yuvInfo != null && (this.yuvInfo = t.yuvInfo),
|
|
|
- t.panoInfo != null && this.setPanoInfo(t.panoInfo);
|
|
|
+ this._defaultShader.gridRatio = 50
|
|
|
+ this._defaultShader.lineColor = new BABYLON.Color3(0, 0, 0.5)
|
|
|
+ this._defaultShader.majorUnitFrequency = 1
|
|
|
+ this._defaultShader.mainColor = new BABYLON.Color3(0.6, 0.6, 0.6)
|
|
|
+ this._defaultShader.backFaceCulling = !1
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ _initPureVideoShader = () => {
|
|
|
+ if (this._lowModelShader == null) {
|
|
|
+ const material = new BABYLON.ShaderMaterial(
|
|
|
+ "PureVideoShader",
|
|
|
+ this.scene, {
|
|
|
+ vertexSource: pureVideoVertex,
|
|
|
+ fragmentSource: pureVideoFragment,
|
|
|
+ }, {
|
|
|
+ attributes: ["uv", "position", "world0", "world1", "world2", "world3"],
|
|
|
+ uniforms: ["view", "projection", "worldViewProjection", "world"],
|
|
|
+ defines: ["#define SHADOWFULLFLOAT"],
|
|
|
+ }
|
|
|
+ );
|
|
|
+ material.setTexture("shadowSampler", null)
|
|
|
+ material.setMatrix("lightSpaceMatrix", null)
|
|
|
+ material.setFloat("haveShadowLight", 0)
|
|
|
+ material.setTexture("texture_video", null)
|
|
|
+ material.setFloat("isYUV", this._inputYUV420 ? 1 : 0)
|
|
|
+ material.setFloat("fireworkLight", 0)
|
|
|
+ material.setVector3("fireworkLightPosition", new BABYLON.Vector3(0, 0, 0))
|
|
|
+ material.setVector3(
|
|
|
+ "focal_width_height",
|
|
|
+ new BABYLON.Vector3(772.022491, 720, 1280)
|
|
|
+ )
|
|
|
+ material.backFaceCulling = !1
|
|
|
+
|
|
|
+ this._lowModelShader = material
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ setDynamicSize = (e) => {
|
|
|
+ return new Promise((t, r) => {
|
|
|
+ e >= 1 && e <= 100
|
|
|
+ ? ((this._dynamic_size = e), t(!0))
|
|
|
+ : ((this._dynamic_size = 1), t(!1));
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ _isInDynamicRange = (e) => {
|
|
|
+ return e < this._dynamic_size && e >= 0
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 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()
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ initDynamicShaders = (e) => {
|
|
|
+ logger.info("[Engine] Material init dynamic shader.")
|
|
|
+ return new Promise((resolve, r) => {
|
|
|
+ this._dynamic_shaders[e] != null && this._dynamic_shaders[e].dispose();
|
|
|
+
|
|
|
+ const material = new BABYLON.ShaderMaterial(
|
|
|
+ "Pano_Shader_" + e,
|
|
|
+ this.scene, {
|
|
|
+ vertexSource: panoVertex,
|
|
|
+ fragmentSource: panoFragment,
|
|
|
+ }, {
|
|
|
+ attributes: ["uv", "position", "world0", "world1", "world2", "world3"],
|
|
|
+ uniforms: ["view", "projection", "worldViewProjection", "world"],
|
|
|
+ defines: ["#define SHADOWFULLFLOAT"],
|
|
|
+ }
|
|
|
+ );
|
|
|
+ material.setTexture("texture_pano", null)
|
|
|
+ material.setVector3("centre_pose", new BABYLON.Vector3(0, 0, 0))
|
|
|
+ material.setFloat("isYUV", this._inputPanoYUV420 ? 1 : 0)
|
|
|
+ material.setTexture("shadowSampler", null)
|
|
|
+ material.setMatrix("lightSpaceMatrix", null)
|
|
|
+ material.setFloat("haveShadowLight", 0)
|
|
|
+ material.setFloat("fireworkLight", 0)
|
|
|
+ material.setVector3("fireworkLightPosition", new BABYLON.Vector3(0, 0, 0))
|
|
|
+ material.backFaceCulling = !1
|
|
|
+
|
|
|
+ this._dynamic_shaders[e] = material
|
|
|
+ resolve(!0);
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
stopYUVUpdate() {
|
|
@@ -365,7 +353,7 @@ export default class XMaterialComponent {
|
|
|
(logger.info(
|
|
|
`[Engine] changePanoImg, id=${e}, pose=${t.pose.position.x},${t.pose.position.y},${t.pose.position.z}`
|
|
|
),
|
|
|
- !this._isInDynamicRange(e))
|
|
|
+ !this._isInDynamicRange(e))
|
|
|
)
|
|
|
return (
|
|
|
logger.error(
|
|
@@ -380,9 +368,9 @@ export default class XMaterialComponent {
|
|
|
const r = ue4Position2Xverse(t.pose.position);
|
|
|
return (
|
|
|
r &&
|
|
|
- (this._dynamic_babylonpose[e] = {
|
|
|
- position: r,
|
|
|
- }),
|
|
|
+ (this._dynamic_babylonpose[e] = {
|
|
|
+ position: r,
|
|
|
+ }),
|
|
|
new Promise((n, o) => {
|
|
|
try {
|
|
|
typeof t.data == "string"
|
|
@@ -393,11 +381,11 @@ export default class XMaterialComponent {
|
|
|
);
|
|
|
}))
|
|
|
: (this.isPanoYUV420() == !1 &&
|
|
|
- this.initDynamicTexture(
|
|
|
- e,
|
|
|
- this._panoInfo.width,
|
|
|
- this._panoInfo.height
|
|
|
- ),
|
|
|
+ this.initDynamicTexture(
|
|
|
+ e,
|
|
|
+ this._panoInfo.width,
|
|
|
+ this._panoInfo.height
|
|
|
+ ),
|
|
|
this.setPanoYUV420(!0),
|
|
|
this._dynamic_textures[e].update(t.data),
|
|
|
this._dynamic_textures[e].updateSamplingMode(
|
|
@@ -410,9 +398,9 @@ export default class XMaterialComponent {
|
|
|
}).then(
|
|
|
(n) => (
|
|
|
t.fov != null &&
|
|
|
- this._scenemanager.cameraComponent.changeCameraFov(
|
|
|
- (t.fov * Math.PI) / 180
|
|
|
- ),
|
|
|
+ this._scenemanager.cameraComponent.changeCameraFov(
|
|
|
+ (t.fov * Math.PI) / 180
|
|
|
+ ),
|
|
|
this._dynamic_shaders[e].setFloat(
|
|
|
"isYUV",
|
|
|
this._inputPanoYUV420 ? 1 : 0
|
|
@@ -557,32 +545,31 @@ export default class XMaterialComponent {
|
|
|
}
|
|
|
|
|
|
_updatePanoShaderInput(e) {
|
|
|
- var n,s;
|
|
|
- if (this._isInDynamicRange(e))
|
|
|
- {
|
|
|
- let shader = this._dynamic_shaders[e]
|
|
|
- let avatarLight = this.scene.getLightByName("AvatarLight")
|
|
|
-
|
|
|
- shader == null || (avatarLight ? (
|
|
|
- shader.setFloat("haveShadowLight", 1),
|
|
|
- shader.setTexture("shadowSampler", (n = avatarLight == null ? void 0 : avatarLight.getShadowGenerator()) == null ? void 0 : n.getShadowMapForRendering()),
|
|
|
- shader.setMatrix("lightSpaceMatrix", (s = avatarLight == null ? void 0 : avatarLight.getShadowGenerator()) == null ? void 0 : s.getTransformMatrix())
|
|
|
- ) : (
|
|
|
- shader.setTexture("shadowSampler", null),
|
|
|
- shader.setMatrix("lightSpaceMatrix", new Matrix),
|
|
|
- shader.setFloat("haveShadowLight", 0)
|
|
|
- ))
|
|
|
-
|
|
|
- let fireworkLight = this.scene.getLightByName("fireworkLight")
|
|
|
- if (fireworkLight) {
|
|
|
- this.scene.registerBeforeRender(()=>{
|
|
|
- shader.setFloat("fireworkLight", fireworkLight.getScaledIntensity()),
|
|
|
- shader.setVector3("fireworkLightPosition", fireworkLight == null ? void 0 : fireworkLight.position)
|
|
|
- });
|
|
|
- } else {
|
|
|
- const f = new BABYLON.PointLight("fireworkLight", new BABYLON.Vector3(0,0,0), this.scene);
|
|
|
- f.intensity = 0
|
|
|
- }
|
|
|
+ var n, s;
|
|
|
+ if (this._isInDynamicRange(e)) {
|
|
|
+ let shader = this._dynamic_shaders[e]
|
|
|
+ let avatarLight = this.scene.getLightByName("AvatarLight")
|
|
|
+
|
|
|
+ shader == null || (avatarLight ? (
|
|
|
+ shader.setFloat("haveShadowLight", 1),
|
|
|
+ shader.setTexture("shadowSampler", (n = avatarLight == null ? void 0 : avatarLight.getShadowGenerator()) == null ? void 0 : n.getShadowMapForRendering()),
|
|
|
+ shader.setMatrix("lightSpaceMatrix", (s = avatarLight == null ? void 0 : avatarLight.getShadowGenerator()) == null ? void 0 : s.getTransformMatrix())
|
|
|
+ ) : (
|
|
|
+ shader.setTexture("shadowSampler", null),
|
|
|
+ shader.setMatrix("lightSpaceMatrix", new Matrix),
|
|
|
+ shader.setFloat("haveShadowLight", 0)
|
|
|
+ ))
|
|
|
+
|
|
|
+ let fireworkLight = this.scene.getLightByName("fireworkLight")
|
|
|
+ if (fireworkLight) {
|
|
|
+ this.scene.registerBeforeRender(() => {
|
|
|
+ shader.setFloat("fireworkLight", fireworkLight.getScaledIntensity()),
|
|
|
+ shader.setVector3("fireworkLightPosition", fireworkLight == null ? void 0 : fireworkLight.position)
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ const f = new BABYLON.PointLight("fireworkLight", new BABYLON.Vector3(0, 0, 0), this.scene);
|
|
|
+ f.intensity = 0
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
}
|