123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- import * as THREE from "../../libs/three.js/build/three.module.js";
- THREE.WebGLRenderer.prototype.paramThreeToGL = function(e) {
- var t, i = this.extensions, r = this.getContext();//context;
- if (e === THREE.RepeatWrapping)
- return r.REPEAT;
- if (e === THREE.ClampToEdgeWrapping)
- return r.CLAMP_TO_EDGE;
- if (e === THREE.MirroredRepeatWrapping)
- return r.MIRRORED_REPEAT;
- if (e === THREE.NearestFilter)
- return r.NEAREST;
- if (e === THREE.NearestMipMapNearestFilter)
- return r.NEAREST_MIPMAP_NEAREST;
- if (e === THREE.NearestMipMapLinearFilter)
- return r.NEAREST_MIPMAP_LINEAR;
- if (e === THREE.LinearFilter)
- return r.LINEAR;
- if (e === THREE.LinearMipMapNearestFilter)
- return r.LINEAR_MIPMAP_NEAREST;
- if (e === THREE.LinearMipMapLinearFilter)
- return r.LINEAR_MIPMAP_LINEAR;
- if (e === THREE.UnsignedByteType)
- return r.UNSIGNED_BYTE;
- if (e === THREE.UnsignedShort4444Type)
- return r.UNSIGNED_SHORT_4_4_4_4;
- if (e === THREE.UnsignedShort5551Type)
- return r.UNSIGNED_SHORT_5_5_5_1;
- if (e === THREE.UnsignedShort565Type)
- return r.UNSIGNED_SHORT_5_6_5;
- if (e === THREE.ByteType)
- return r.BYTE;
- if (e === THREE.ShortType)
- return r.SHORT;
- if (e === THREE.UnsignedShortType)
- return r.UNSIGNED_SHORT;
- if (e === THREE.IntType)
- return r.INT;
- if (e === THREE.UnsignedIntType)
- return r.UNSIGNED_INT;
- if (e === THREE.FloatType)
- return r.FLOAT;
- if (t = i.get("OES_texture_half_float"),
- null !== t && e === THREE.HalfFloatType)
- return t.HALF_FLOAT_OES;
- if (e === THREE.AlphaFormat)
- return r.ALPHA;
- if (e === THREE.RGBFormat)
- return r.RGB;
- if (e === THREE.RGBAFormat)
- return r.RGBA;
- if (e === THREE.LuminanceFormat)
- return r.LUMINANCE;
- if (e === THREE.LuminanceAlphaFormat)
- return r.LUMINANCE_ALPHA;
- if (e === THREE.AddEquation)
- return r.FUNC_ADD;
- if (e === THREE.SubtractEquation)
- return r.FUNC_SUBTRACT;
- if (e === THREE.ReverseSubtractEquation)
- return r.FUNC_REVERSE_SUBTRACT;
- if (e === THREE.ZeroFactor)
- return r.ZERO;
- if (e === THREE.OneFactor)
- return r.ONE;
- if (e === THREE.SrcColorFactor)
- return r.SRC_COLOR;
- if (e === THREE.OneMinusSrcColorFactor)
- return r.ONE_MINUS_SRC_COLOR;
- if (e === THREE.SrcAlphaFactor)
- return r.SRC_ALPHA;
- if (e === THREE.OneMinusSrcAlphaFactor)
- return r.ONE_MINUS_SRC_ALPHA;
- if (e === THREE.DstAlphaFactor)
- return r.DST_ALPHA;
- if (e === THREE.OneMinusDstAlphaFactor)
- return r.ONE_MINUS_DST_ALPHA;
- if (e === THREE.DstColorFactor)
- return r.DST_COLOR;
- if (e === THREE.OneMinusDstColorFactor)
- return r.ONE_MINUS_DST_COLOR;
- if (e === THREE.SrcAlphaSaturateFactor)
- return r.SRC_ALPHA_SATURATE;
- if (t = i.get("WEBGL_compressed_texture_s3tc"),
- null !== t) {
- if (e === THREE.RGB_S3TC_DXT1_Format)
- return t.COMPRESSED_RGB_S3TC_DXT1_EXT;
- if (e === THREE.RGBA_S3TC_DXT1_Format)
- return t.COMPRESSED_RGBA_S3TC_DXT1_EXT;
- if (e === THREE.RGBA_S3TC_DXT3_Format)
- return t.COMPRESSED_RGBA_S3TC_DXT3_EXT;
- if (e === THREE.RGBA_S3TC_DXT5_Format)
- return t.COMPRESSED_RGBA_S3TC_DXT5_EXT
- }
- if (t = i.get("WEBGL_compressed_texture_pvrtc"),
- null !== t) {
- if (e === THREE.RGB_PVRTC_4BPPV1_Format)
- return t.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
- if (e === THREE.RGB_PVRTC_2BPPV1_Format)
- return t.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
- if (e === THREE.RGBA_PVRTC_4BPPV1_Format)
- return t.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
- if (e === THREE.RGBA_PVRTC_2BPPV1_Format)
- return t.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
- }
- if (t = i.get("WEBGL_compressed_texture_etc1"),
- null !== t && e === THREE.RGB_ETC1_Format)
- return t.COMPRESSED_RGB_ETC1_WEBGL;
- if (t = i.get("EXT_blend_minmax"),
- null !== t) {
- if (e === THREE.MinEquation)
- return t.MIN_EXT;
- if (e === THREE.MaxEquation)
- return t.MAX_EXT
- }
- return 0
- }
- THREE.EventDispatcher.prototype.addEventListener = function(type, listener, {importance=0, once}={}){ //add importance
- if ( this._listeners === undefined ) this._listeners = {};
- const listeners = this._listeners;
- if ( listeners[ type ] === undefined ) {
- listeners[ type ] = [];
- }
- /* if(type == 'flyingDone'){
- console.log('addEventListener flyingDone')
- } */
- if ( !listeners[ type ].some(e=>e.listener == listener ) ) {
- listeners[type].push({ listener, importance, once});
- listeners[type] = listeners[type].sort((e,a)=> a.importance - e.importance)//add
- }
- }
- THREE.EventDispatcher.prototype.hasEventListener = function(type, listener){
- if ( this._listeners === undefined ) return false;
- const listeners = this._listeners;
- return listeners[ type ] !== undefined && listeners[ type ].some(e=>e.listener == listener )
- }
- THREE.EventDispatcher.prototype.removeEventListener = function(type, listener){
- if ( this._listeners === undefined ) return;
- const listeners = this._listeners;
- const listenerArray = listeners[ type ];
- if ( listenerArray !== undefined ) {
- /* const index = listenerArray.indexOf( listener );
- if ( index !== - 1 ) {
- listenerArray.splice( index, 1 );
- } */
- let item = listenerArray.find(e=>e.listener == listener)
- item && listenerArray.splice(listenerArray.indexOf(item), 1);
- }
- }
- THREE.EventDispatcher.prototype.removeEventListeners = function(type){ //add
- if(this._listeners && this._listeners[type] !== undefined){
- delete this._listeners[type];
- }
- }
- THREE.EventDispatcher.prototype.removeAllListeners = function(){ //add
- this._listeners = {};
- }
- THREE.EventDispatcher.prototype.dispatchEvent = function(event){
- if(typeof event == 'string'){//add
- event = {type:event}
- }
- if ( this._listeners === undefined ) return;
- const listeners = this._listeners;
- const listenerArray = listeners[ event.type ];
- if ( listenerArray !== undefined ) {
- event.target = this;
- // Make a copy, in case listeners are removed while iterating.
- for(let {listener, once} of listenerArray.slice(0)){
- if(once){
- this.removeEventListener(event.type,listener)
- }
- let result = listener.call(this, event); //add stopContinue
-
- if(result && result.stopContinue){
- break
- }
- }
- }
- }
- THREE.EventDispatcher.prototype.traverse = function(callback){
- let result = callback( this );
- if(result && result.stopContinue){//xzw add
- return
- }
-
- const children = this.children;
- if(children){
- for ( let i = 0, l = children.length; i < l; i ++ ) {
- children[ i ].traverse( callback );
- }
- }
- }
- THREE.Object3D.prototype.traverse = function ( callback ) {
- let result = callback( this );
- if(result && result.stopContinue){//xzw add
- return
- }
-
- const children = this.children;
- for ( let i = 0, l = children.length; i < l; i ++ ) {
- children[ i ] && children[ i ].traverse( callback );
- }
- }
- THREE.Material.prototype.setValues = function ( values ) {
- if ( values === undefined ) return;
- for ( const key in values ) {
- const newValue = values[ key ];
- if ( newValue === undefined ) {
- console.warn( 'THREE.Material: \'' + key + '\' parameter is undefined.' );
- continue;
- }
- // for backward compatability if shading is set in the constructor
- if ( key === 'shading' ) {
- console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
- this.flatShading = ( newValue === FlatShading ) ? true : false;
- continue;
- }
- const currentValue = this[ key ];
- /* if ( currentValue === undefined ) { //-----主要删了这段,否则很难和 set 一起使用
- //console.warn( 'THREE.' + this.type + ': \'' + key + '\' is not a property of this material.' );
- continue;
- } */
- if ( currentValue && currentValue.isColor ) {
- currentValue.set( newValue );
- } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
- currentValue.copy( newValue );
- } else {
- this[ key ] = newValue;
- }
- }
- }
- function ascSort( a, b ) {
- return a.distance - b.distance;
- }
- function intersectObject( object, raycaster, intersects, recursive, ignoreUnvisible ) {
-
- if(ignoreUnvisible && !object.visible)return //add
-
- if ( object.layers.test( raycaster.layers ) ) {
- object.raycast( raycaster, intersects );
- }
- if ( recursive === true ) {
- const children = object.children;
- for ( let i = 0, l = children.length; i < l; i ++ ) {
- intersectObject( children[ i ], raycaster, intersects, true, ignoreUnvisible);
- }
- }
- }
- THREE.Raycaster.prototype.intersectObject = function ( object, recursive, optionalTarget, ignoreUnvisible ) {
- const intersects = optionalTarget || [];
-
- intersectObject( object, this, intersects, recursive, ignoreUnvisible );
- intersects.sort( ascSort );
- return intersects;
- }
- THREE.Raycaster.prototype.intersectObjects = function ( objects, recursive, optionalTarget, ignoreUnvisible ) {//add ignoreUnvisible 跳过不可见
- const intersects = optionalTarget || [];
- if ( Array.isArray( objects ) === false ) {
- console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
- return intersects;
- }
- for ( let i = 0, l = objects.length; i < l; i ++ ) {
- intersectObject( objects[ i ], this, intersects, recursive, ignoreUnvisible );
- }
- intersects.sort( ascSort );
- return intersects;
- }
- THREE.Object3D.prototype.realVisible = function(){
- let v = true
- let parent = this
- let lastParent
- while(parent){
- if(parent.visible === false){
- v = false
- break;
- }
- lastParent = parent
- parent = parent.parent
- }
-
- if(v && !(lastParent instanceof THREE.Scene)){//已被删除
- v = false
- }
- return v
- }
|