12345678910 |
- /**
- * @copyright © 未来飞马 © 未来全栈 www.fmode.cn
- * 版权所有 © 未来飞马 © 江西脑控科技有限公司 Copyright © Fmode Technology Co., Ltd.
- * 保留所有权利 All Rights Reserved.
- * /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/aigc/avatar/comp-avatar-particle/comp-avatar-particle.component.mjs
- */
- import{CommonModule}from"@angular/common";import{Component,ElementRef}from"@angular/core";import{ViewChild}from"@angular/core";import{FormsModule}from"@angular/forms";import*as BABYLON from"@babylonjs/core";import"@babylonjs/loaders";import{RolePointsCloud}from"./role-points.class";import*as i0 from"@angular/core";export class CompAvatarParticleComponent{constructor(e){this.elementRef=e,this.isWebVR=!1,this.animMap={}}ngAfterViewInit(){if(this.canvas=this.renderCanvas.nativeElement,console.log(this.canvas),this.canvas){let e={};this.engine=new BABYLON.Engine(this.canvas,!0,e),console.log(this.engine),this.createScene(),this.engine.runRenderLoop((()=>{this.scene?.render(),this.engine?.resize()})),window.addEventListener("resize",(()=>{this.engine?.resize()}))}}async createScene(){this.scene=new BABYLON.Scene(this.engine),this.scene.clearColor=new BABYLON.Color4(0,0,0,1),this.mainCamera=this.createCamera(),console.log(this.mainCamera),this.currentRole=new RolePointsCloud(this.scene,this.engine,this.mainCamera),await this.currentRole.init(),this.currentRole.playAnim("idle"),this.currentRole.Mesh.visibility=0,await this.createCloudPoints();new BABYLON.HemisphericLight("light1",new BABYLON.Vector3(0,1,0),this.scene);this.engine?.resize()}createCamera(){let e=new(this.isWebVR?BABYLON.VRDeviceOrientationArcRotateCamera:BABYLON.ArcRotateCamera)("Camera",0,0,30,new BABYLON.Vector3(0,.5,0),this.scene);return e.setPosition(new BABYLON.Vector3(0,0,5)),e.beta=Math.PI/3,e.alpha=Math.PI/1.2,e.radius=15,e}async createCloudPoints(){this.pointsMesh=this.currentRole.Mesh,this.pointsCloud=new BABYLON.PointsCloudSystem("pcs",1,this.scene);let e=new BABYLON.Color3(.7,.8,1),t=new BABYLON.Color4(.7,.8,1),n=(new BABYLON.Color4(.2,.5,1),new BABYLON.Color4(0,0,.2,0),new BABYLON.Texture("/assets/avatar/particle/textures/flare.png",this.scene)),i=new BABYLON.PBRMaterial("material",this.scene);i.emissiveTexture=n,i.emissiveColor=e,this.pointsCloud.addVolumePoints(this.currentRole.Mesh,5e3,BABYLON.PointColor.Color,t),this.pointsCloud.buildMeshAsync().then((()=>{this.playAnimation("waiting")})),this.scene.registerAfterRender((()=>{this.pointsCloud.setParticles()})),this.engine.runRenderLoop((()=>{this.scene.render()}))}playAnimation(e){switch(e){case"waiting":this.cloudAnim();break;case"listening":this.cloudAnim({rotateSpeed:.01,breathing:!1});break;case"thinking":this.cloudAnim({rotateSpeed:.2,breathing:!1});break;case"talking":this.animMap.idle&&this.scene.beginDirectAnimation(this.pointsMesh,[this.animMap.talking],0,20,!0)}}cloudAnim(e={breathing:!0,rotateSpeed:.002}){this.animMap.idle&&this.scene.beginDirectAnimation(this.pointsMesh,[this.animMap.idle],0,120,!0);let t=new BABYLON.Color4(1,1,1,1),n=(new BABYLON.Texture("/assets/avatar/particle/textures/flare.png",this.scene),0);this.pointsCloud.updateParticle=i=>{let a=this.currentRole.Mesh.getBoundingInfo()?.boundingSphere?.radiusWorld,o=this.currentRole.Mesh.getBoundingInfo()?.boundingSphere?.centerWorld;i.idx;if(i.color=t,i.rotation.y+=e.rotateSpeed,i&&n<3&&(console.log(this.currentRole.Mesh.getBoundingInfo()),console.log(i),n++),i.initpos||(i.initpos=i.position),e.breathing){let e=i.initpos.subtract(o);i.position=new BABYLON.Vector3(e.x*a,e.y*a,e.z*a).add(this.currentRole.offsetPosition)}return i}}createSphere(){let e=BABYLON.MeshBuilder.CreateSphere("sphere",{diameter:2},this.scene);e.visibility=1,e.material=new BABYLON.StandardMaterial("mat",this.scene),e.material.wireframe=!0,e.scaling=new BABYLON.Vector3(1,1,1),this.pointsMesh=e;let t=new BABYLON.Animation("breathingAnimation","scaling",30,BABYLON.Animation.ANIMATIONTYPE_VECTOR3,BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE),n=[];n.push({frame:0,value:new BABYLON.Vector3(.3,.3,.3)}),n.push({frame:60,value:new BABYLON.Vector3(.5,.5,.5)}),n.push({frame:120,value:new BABYLON.Vector3(.3,.3,.3)}),t.setKeys(n),this.animMap.idle=t;let i=[{frame:0,value:BABYLON.Vector3.One()},{frame:10,value:new BABYLON.Vector3(1.2,.8,1.2)},{frame:20,value:BABYLON.Vector3.One()}],a=new BABYLON.Animation("talkAnimation","scaling",30,BABYLON.Animation.ANIMATIONTYPE_VECTOR3,BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);return a.setKeys(i),this.animMap.talk=a,this.scene.beginDirectAnimation(e,[this.animMap.idle],0,120,!0),e}async createParticle(){let e=this.createSphere(),t=new BABYLON.ParticleSystem("particles",2e3,this.scene);t.particleTexture=new BABYLON.Texture("/assets/avatar/particle/textures/flare.png",this.scene),t.emitter=e,t.minEmitBox=new BABYLON.Vector3(0,0,0),t.maxEmitBox=new BABYLON.Vector3(0,0,0),t.color1=new BABYLON.Color4(.7,.8,1,1),t.color2=new BABYLON.Color4(.2,.5,1,1),t.colorDead=new BABYLON.Color4(0,0,.2,0),t.minSize=.5,t.maxSize=.5,t.minLifeTime=.1,t.maxLifeTime=.1,t.minAngularSpeed=0,t.maxAngularSpeed=Math.PI,t.minInitialRotation=0,t.maxInitialRotation=Math.PI,t.minEmitPower=0,t.maxEmitPower=0,t.emitRate=1500,t.updateSpeed=.01,t.blendMode=BABYLON.ParticleSystem.BLENDMODE_ONEONE,t.direction1=new BABYLON.Vector3(0,0,0),t.direction2=new BABYLON.Vector3(0,0,0),t.start();let n=t.createSphereEmitter();n.radius=2,n.radiusRange=0,n.directionRandomizer=0,t.gravity=new BABYLON.Vector3(0,0,0),t.disposeOnStop=!0,t.updateFunction=n=>{for(let i=0;i<n.length;i++){let a=n[i],o=e.getBoundingInfo()?.boundingSphere?.radiusWorld;a.position=a.position.normalize().scale(o),a.age+=this.scene.getEngine().getDeltaTime()/1e3,a.age>=a.lifeTime&&(t.recycleParticle(a),i--)}},this.engine.runRenderLoop((()=>{this.scene.render(),t.worldOffset=e.position}))}setCameraToMeshCenter(e,t){t.computeWorldMatrix(!0);let n=t.getBoundingInfo(),i=n.minimum,a=n.maximum,o=a.x-i.x,r=a.y-i.y,s=a.z-i.z,l=n.boundingBox.center;console.log("宽度:"+o),console.log("高度:"+r),console.log("深度:"+s),console.log("中心点:"+l)}static{this.ɵfac=i0.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:CompAvatarParticleComponent,deps:[{token:i0.ElementRef}],target:i0.ɵɵFactoryTarget.Component})}static{this.ɵcmp=i0.ɵɵngDeclareComponent({minVersion:"14.0.0",version:"17.3.12",type:CompAvatarParticleComponent,isStandalone:!0,selector:"fm-avatar-role-particle",viewQueries:[{propertyName:"renderCanvas",first:!0,predicate:["renderCanvas"],descendants:!0}],ngImport:i0,template:'<canvas #renderCanvas class="render-canvas"></canvas>',styles:[".render-canvas{display:block;width:100%;height:100%;touch-action:none}\n"],dependencies:[{kind:"ngmodule",type:CommonModule},{kind:"ngmodule",type:FormsModule}]})}}i0.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:CompAvatarParticleComponent,decorators:[{type:Component,args:[{selector:"fm-avatar-role-particle",standalone:!0,imports:[CommonModule,FormsModule],template:'<canvas #renderCanvas class="render-canvas"></canvas>',styles:[".render-canvas{display:block;width:100%;height:100%;touch-action:none}\n"]}]}],ctorParameters:()=>[{type:i0.ElementRef}],propDecorators:{renderCanvas:[{type:ViewChild,args:["renderCanvas"]}]}});
- var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9haWdjL2F2YXRhci9jb21wLWF2YXRhci1wYXJ0aWNsZS9jb21wLWF2YXRhci1wYXJ0aWNsZS5jb21wb25lbnQubWpz`
-
|