|
@@ -79,19 +79,14 @@ export default class XMaterialComponent {
|
|
|
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))
|
|
|
- }
|
|
|
- );
|
|
|
+ });
|
|
|
|
|
|
- E(this, "updateRawYUVData", (stream,width,height,fov=-1)=>{
|
|
|
- var o, a;
|
|
|
+ E(this, "updateRawYUVData", (stream, width, height, fov=-1)=>{
|
|
|
fov == -1 && (fov = this.yuvInfo.fov);
|
|
|
+
|
|
|
if (this._isUpdateYUV == !0) {
|
|
|
console.log('执行:updateRawYUVData')
|
|
|
- const s = {
|
|
|
- width: width,
|
|
|
- height: height,
|
|
|
- fov: fov
|
|
|
- }
|
|
|
+ const yuvInfo = { width, height, fov }
|
|
|
const videosResOriArrayIndex = this._videoRawYUVTexArray.findId(width, height)
|
|
|
const currentVideoId = this._videoRawYUVTexArray.getCurrentVideoTexId();
|
|
|
|
|
@@ -100,48 +95,51 @@ export default class XMaterialComponent {
|
|
|
this.yuvInfo.width = width;
|
|
|
this.yuvInfo.height = height;
|
|
|
this.yuvInfo.fov = fov;
|
|
|
+
|
|
|
this._videoRawYUVTexArray.setCurrentVideoTexId(videosResOriArrayIndex);
|
|
|
- this._changeVideoRes(videosResOriArrayIndex);
|
|
|
- this._changePureVideoLowModelShaderCanvasSize(s);
|
|
|
- this._scenemanager.cameraComponent.cameraFovChange(s);
|
|
|
- this._scenemanager.yuvInfo = s;
|
|
|
+ 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)
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
+ //var o, a
|
|
|
//(o = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || o.update(stream),
|
|
|
//(a = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || a.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
|
|
|
}
|
|
|
- }
|
|
|
- );
|
|
|
+ });
|
|
|
+
|
|
|
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)
|
|
|
+ E(this, "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`))
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
- ).catch(n=>logger.error(`[Engine] ${n}`)));
|
|
|
+ )(s);
|
|
|
+ resolve(!0)
|
|
|
+ } else
|
|
|
+ reject(new XMaterialError(`[Engine] DynamicRoomSize (${dynamicRange}) is too small`))
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }).catch(n=>logger.error(`[Engine] ${n}`))
|
|
|
+ });
|
|
|
|
|
|
E(this, "_initDefaultShader", ()=>{
|
|
|
this._defaultShader == null && (this._defaultShader = new BABYLON.GridMaterial("GridShader",this.scene),
|
|
@@ -150,8 +148,8 @@ export default class XMaterialComponent {
|
|
|
this._defaultShader.majorUnitFrequency = 1,
|
|
|
this._defaultShader.mainColor = new BABYLON.Color3(.6,.6,.6),
|
|
|
this._defaultShader.backFaceCulling = !1)
|
|
|
- }
|
|
|
- );
|
|
|
+ });
|
|
|
+
|
|
|
E(this, "_initPureVideoShader", ()=>{
|
|
|
if (this._lowModelShader == null) {
|
|
|
const e = new BABYLON.ShaderMaterial("PureVideoShader",this.scene,{
|
|
@@ -173,46 +171,49 @@ export default class XMaterialComponent {
|
|
|
e.backFaceCulling = !1,
|
|
|
this._lowModelShader = e
|
|
|
}
|
|
|
- }
|
|
|
- );
|
|
|
+ });
|
|
|
+
|
|
|
E(this, "setDynamicSize", e=>new Promise((t,r)=>{
|
|
|
e >= 1 && e <= 100 ? (this._dynamic_size = e,
|
|
|
t(!0)) : (this._dynamic_size = 1,
|
|
|
t(!1))
|
|
|
- }
|
|
|
- ));
|
|
|
+ }));
|
|
|
+
|
|
|
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"]
|
|
|
- });
|
|
|
- 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)
|
|
|
- }
|
|
|
+ });
|
|
|
+
|
|
|
+ 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"]
|
|
|
+ });
|
|
|
+ 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)
|
|
|
+ }
|
|
|
)));
|
|
|
+
|
|
|
this._scenemanager = e,
|
|
|
this.scene = e.Scene,
|
|
|
this.engine = this.scene.getEngine(),
|
|
@@ -410,24 +411,34 @@ export default class XMaterialComponent {
|
|
|
pointLight.intensity = 0
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
_updatePanoShaderInput(e) {
|
|
|
- var t, r, n, o, a, s, l, u, c, h;
|
|
|
- if (this._isInDynamicRange(e))
|
|
|
- if (this.scene.getLightByName("AvatarLight") ? ((t = this._dynamic_shaders[e]) == null || t.setFloat("haveShadowLight", 1),
|
|
|
- (o = this._dynamic_shaders[e]) == null || o.setTexture("shadowSampler", (n = (r = this.scene.getLightByName("AvatarLight")) == null ? void 0 : r.getShadowGenerator()) == null ? void 0 : n.getShadowMapForRendering()),
|
|
|
- (l = this._dynamic_shaders[e]) == null || l.setMatrix("lightSpaceMatrix", (s = (a = this.scene.getLightByName("AvatarLight")) == null ? void 0 : a.getShadowGenerator()) == null ? void 0 : s.getTransformMatrix())) : ((u = this._dynamic_shaders[e]) == null || u.setTexture("shadowSampler", null),
|
|
|
- (c = this._dynamic_shaders[e]) == null || c.setMatrix("lightSpaceMatrix", new Matrix),
|
|
|
- (h = this._dynamic_shaders[e]) == null || h.setFloat("haveShadowLight", 0)),
|
|
|
- this.scene.getLightByName("fireworkLight"))
|
|
|
+ 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(()=>{
|
|
|
- var f;
|
|
|
- this._dynamic_shaders[e].setFloat("fireworkLight", this.scene.getLightByName("fireworkLight").getScaledIntensity()),
|
|
|
- this._dynamic_shaders[e].setVector3("fireworkLightPosition", (f = this.scene.getLightByName("fireworkLight")) == null ? void 0 : f.position)
|
|
|
- }
|
|
|
- );
|
|
|
- else {
|
|
|
- const f = new BABYLON.PointLight("fireworkLight",new BABYLON.Vector3(0,0,0),this.scene);
|
|
|
+ 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
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
}
|