Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Junior2Ran committed Oct 11, 2023
1 parent 785c51d commit a449da6
Show file tree
Hide file tree
Showing 6 changed files with 348 additions and 60 deletions.
17 changes: 13 additions & 4 deletions README2.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
执行编译 `npm run build`
# bmap-three
`bmap-three``mapv-three`的依赖包,由于`three`库本身有一些变量、功能or钩子不对外暴露,而在开发`mapv-three`引擎时对底层渲染又有强需求,所以不得不魔改`three`的代码。

执行拷贝脚本 `sh bmap-three-all.sh`
本质上`bmap-three``three`是一模一样的,只不过会多抛出一些钩子而已,不用太在意。

`cd bmap-three`
两个库的版本号一致,如果在一些功能上单独使用`bmap-three`有问题,那大概率是`three`本身的问题,需要检查`three`是否更新并修复了,如果是那么可以执行下面的代码同步操作来更新

执行 `npm publish`
## 同步three更新
1. 访问 https://github.com/huiyan-fe/three.js
2. 点击`Sync Fork`,然后`Update Branch`,正常情况下应该不会有什么冲突,如果有,找`@李高锋`解决一下冲突
3. 执行`git pull`,本地代码更新为最新的`threejs`代码,然后就可以准备发布了

## 发布
1. 执行编译`npm run build`
2. 执行拷贝脚本`sh bmap-three-all.sh`,把库名从`three`替换成`bmap-three`
3. 进入发布目录`cd bmap-three`,执行`npm publish`发布包
129 changes: 111 additions & 18 deletions build/three.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4154,21 +4154,20 @@ class Vector3 {

applyQuaternion( q ) {

const x = this.x, y = this.y, z = this.z;
const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
// Derived from https://raw.org/proof/vector-rotation-using-quaternions/

// calculate quat * vector

const ix = qw * x + qy * z - qz * y;
const iy = qw * y + qz * x - qx * z;
const iz = qw * z + qx * y - qy * x;
const iw = - qx * x - qy * y - qz * z;
const vx = this.x, vy = this.y, vz = this.z;
const qx = q.x, qy = q.y, qz = q.z, qw = q.w;

// calculate result * inverse quat
// t = 2q x v
const tx = 2 * ( qy * vz - qz * vy );
const ty = 2 * ( qz * vx - qx * vz );
const tz = 2 * ( qx * vy - qy * vx );

this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
// v + w t + q x t
this.x = vx + qw * tx + qy * tz - qz * ty;
this.y = vy + qw * ty + qz * tx - qx * tz;
this.z = vz + qw * tz + qx * ty - qy * tx;

return this;

Expand Down Expand Up @@ -16208,14 +16207,24 @@ class PMREMGenerator {
* and far planes ensure the scene is rendered in its entirety (the cubeCamera
* is placed at the origin).
*/
fromScene( scene, sigma = 0, near = 0.1, far = 100 ) {
fromScene( scene, sigma = 0, near = 0.1, far = 100, cubeUVRenderTarget = null, pingPongRenderTarget = null ) {

_oldTarget = this._renderer.getRenderTarget();

this._setSize( 256 );

const cubeUVRenderTarget = this._allocateTargets();
cubeUVRenderTarget.depthBuffer = true;
if ( ! cubeUVRenderTarget ) {

cubeUVRenderTarget = this._allocateTargets();

}

if ( pingPongRenderTarget ) {

this._pingPongRenderTarget = pingPongRenderTarget;

}

this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget );

Expand All @@ -16232,6 +16241,48 @@ class PMREMGenerator {

}

prepareForRenderTarget( cubeUVRenderTarget, pingPongRenderTarget = null, cubeSize = 256 ) {

this._setSize( cubeSize );
const { _lodMax } = this;
( { sizeLods: this._sizeLods, lodPlanes: this._lodPlanes, sigmas: this._sigmas } = _createPlanes( _lodMax ) );
const width = 3 * Math.max( this._cubeSize, 16 * 7 );
const height = 4 * this._cubeSize;
this._blurMaterial = _getBlurShader( _lodMax, width, height );
cubeUVRenderTarget.setSize( width, height );

if ( pingPongRenderTarget ) {

pingPongRenderTarget.setSize( width, height);

}

}

fromSceneToRenderTarget( scene, cubeUVRenderTarget, pingPongRenderTarget, sigma = 0, near = 0.1, far = 100 ) {

_oldTarget = this._renderer.getRenderTarget();

this._pingPongRenderTarget = pingPongRenderTarget;


this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget );
if ( sigma > 0 ) {

this._blur( cubeUVRenderTarget, 0, 0, sigma );

}

this._applyPMREM( cubeUVRenderTarget );

this._renderer.setRenderTarget( _oldTarget );
cubeUVRenderTarget.scissorTest = false;
_setViewport( cubeUVRenderTarget, 0, 0, cubeUVRenderTarget.width, cubeUVRenderTarget.height );

return cubeUVRenderTarget;

}

/**
* Generates a PMREM from an equirectangular texture, which can be either LDR
* or HDR. The ideal input image size is 1k (1024 x 512),
Expand Down Expand Up @@ -16955,6 +17006,16 @@ function _getCommonVertexShader() {

varying vec3 vOutputDirection;

mat3 getRotationMatrix(vec3 axis, float angle) {
axis = normalize(axis);
float s = sin(angle);
float c = cos(angle);
float oc = 1.0 - c;

return mat3(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s,
oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s,
oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c);
}
// RH coordinate system; PMREM face-indexing convention
vec3 getDirection( vec2 uv, float face ) {

Expand Down Expand Up @@ -16991,6 +17052,8 @@ function _getCommonVertexShader() {

}

mat3 rotationMatrix = getRotationMatrix(vec3(1.0, 0.0, 0.0), 1.57);
direction = rotationMatrix * direction;
return direction;

}
Expand Down Expand Up @@ -19921,6 +19984,14 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {

}

if ( renderer.onShaderBeforeResolve ) {

const ret = renderer.onShaderBeforeResolve( vertexShader, fragmentShader, parameters );
vertexShader = ret.vertexShader;
fragmentShader = ret.fragmentShader;

}

vertexShader = resolveIncludes( vertexShader );
vertexShader = replaceLightNums( vertexShader, parameters );
vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
Expand Down Expand Up @@ -19964,9 +20035,16 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {

}

const vertexGlsl = versionString + prefixVertex + vertexShader;
const fragmentGlsl = versionString + prefixFragment + fragmentShader;
let vertexGlsl = versionString + prefixVertex + vertexShader;
let fragmentGlsl = versionString + prefixFragment + fragmentShader;

if ( renderer.onShaderBeforeCompile ) {

const ret = renderer.onShaderBeforeCompile( vertexGlsl, fragmentGlsl, parameters );
vertexGlsl = ret.vertexShader;
fragmentGlsl = ret.fragmentShader;

}
// console.log( '*VERTEX*', vertexGlsl );
// console.log( '*FRAGMENT*', fragmentGlsl );

Expand Down Expand Up @@ -20607,7 +20685,9 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
rendererExtensionDrawBuffers: IS_WEBGL2 || extensions.has( 'WEBGL_draw_buffers' ),
rendererExtensionShaderTextureLod: IS_WEBGL2 || extensions.has( 'EXT_shader_texture_lod' ),

customProgramCacheKey: material.customProgramCacheKey()
customProgramCacheKey: material.customProgramCacheKey(),

extraProgramCacheKey: renderer.extraProgramCacheKey

};

Expand Down Expand Up @@ -20651,6 +20731,12 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities

array.push( parameters.customProgramCacheKey );

if ( renderer.extraProgramCacheKey ) {

array.push( renderer.extraProgramCacheKey );

}

return array.join();

}
Expand Down Expand Up @@ -25558,7 +25644,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( ignoreDepthValues === false ) {

if ( renderTarget.depthBuffer ) mask |= _gl.DEPTH_BUFFER_BIT;
if ( renderTarget.stencilBuffer ) mask |= _gl.STENCIL_BUFFER_BIT;
// if ( renderTarget.stencilBuffer ) mask |= _gl.STENCIL_BUFFER_BIT;

}

Expand Down Expand Up @@ -29699,6 +29785,7 @@ class WebGLRenderer {
materialProperties.vertexAlphas = parameters.vertexAlphas;
materialProperties.vertexTangents = parameters.vertexTangents;
materialProperties.toneMapping = parameters.toneMapping;
materialProperties.extraProgramCacheKey = parameters.extraProgramCacheKey;

}

Expand Down Expand Up @@ -29736,6 +29823,8 @@ class WebGLRenderer {
const materialProperties = properties.get( material );
const lights = currentRenderState.state.lights;

const extraProgramCacheKey = _this.extraProgramCacheKey;

if ( _clippingEnabled === true ) {

if ( _localClippingEnabled === true || camera !== _currentCamera ) {
Expand Down Expand Up @@ -29833,6 +29922,10 @@ class WebGLRenderer {

needsProgramChange = true;

} else if ( extraProgramCacheKey !== materialProperties.extraProgramCacheKey ) {

needsProgramChange = true;

}

} else {
Expand Down
Loading

0 comments on commit a449da6

Please sign in to comment.