Browse Source

revert to static

Andrew V Butt Sr 5 năm trước cách đây
mục cha
commit
38a37920bc

+ 0 - 5
Tools/Config/config.json

@@ -231,11 +231,6 @@
                 "output": "babylon.waterMaterial.min.js",
                 "entry": "./legacy/legacy-water.ts",
                 "preventLoadLibrary": true
-            },
-            {
-                "output": "babylon.boneWeightsMaterial.min.js",
-                "entry": "./legacy/legacy-boneWeights.ts",
-                "preventLoadLibrary": true
             }
         ],
         "build": {

+ 1 - 2
materialsLibrary/src/index.ts

@@ -12,5 +12,4 @@ export * from "./simple";
 export * from "./sky";
 export * from "./terrain";
 export * from "./triPlanar";
-export * from "./water";
-export * from "./skeletonDebug";
+export * from "./water";

+ 0 - 26
materialsLibrary/src/skeletonDebug/IBoneWeightsMaterial.ts

@@ -1,26 +0,0 @@
-import { Color3, Skeleton } from 'babylonjs';
-/**
- * Defines the constructor options for the BoneWeight Shader.
- */
-export interface IBoneWeightsMaterialOptions{
-    /** Skeleton to Map */
-    skeleton: Skeleton;
- 
-    /** Colors for Uninfluenced bones */
-    colorBase? : Color3;
- 
-    /** Colors for 0.0-0.25 Weight bones */
-    colorZero? : Color3;
- 
-    /** Color for 0.25-0.5 Weight Influence */
-    colorQuarter? : Color3;
- 
-    /** Color for 0.5-0.75 Weight Influence */
-    colorHalf? : Color3;
- 
-    /** Color for 0.75-1 Weight Influence */
-    colorFull? : Color3;
- 
-    /** Color for Zero Weight Influence */
-    targetBoneIndex? : number;
- }

+ 0 - 7
materialsLibrary/src/skeletonDebug/boneWeights.fragment.fx

@@ -1,7 +0,0 @@
-precision highp float;
-varying vec3 vColor;
-
-void main() {
-	vec4 color = vec4(vColor, 1.0);
-	gl_FragColor = color;
-}

+ 0 - 53
materialsLibrary/src/skeletonDebug/boneWeights.vertex.fx

@@ -1,53 +0,0 @@
-precision highp float;
-
-attribute vec3 position;
-attribute vec2 uv;
-
-uniform mat4 view;
-uniform mat4 projection;
-uniform mat4 worldViewProjection;
-
-#include<bonesDeclaration>
-#include<instancesDeclaration>
-
-varying vec3 vColor;
-
-uniform vec3 colorBase;
-uniform vec3 colorZero;
-uniform vec3 colorQuarter;
-uniform vec3 colorHalf;
-uniform vec3 colorFull;
-
-uniform float targetBoneIndex;
-
-void main() {
-	vec3 positionUpdated = position;
-
-	#include<instancesVertex>
-	#include<bonesVertex>
-
-	vec4 worldPos = finalWorld * vec4(positionUpdated, 1.0);
-
-	vec3 color = colorBase;
-	float totalWeight = 0.;
-	if(matricesIndices[0] == targetBoneIndex && matricesWeights[0] > 0.){
-		totalWeight += matricesWeights[0];
-	}
-	if(matricesIndices[1] == targetBoneIndex && matricesWeights[1] > 0.){
-		totalWeight += matricesWeights[1];
-	}
-	if(matricesIndices[2] == targetBoneIndex && matricesWeights[2] > 0.){
-		totalWeight += matricesWeights[2];
-	}
-	if(matricesIndices[3] == targetBoneIndex && matricesWeights[3] > 0.){
-		totalWeight += matricesWeights[3];
-	}
-
-	color = mix(color, colorZero, smoothstep(0., 0.25, totalWeight));
-	color = mix(color, colorQuarter, smoothstep(0.25, 0.5, totalWeight));
-	color = mix(color, colorHalf, smoothstep(0.5, 0.75, totalWeight));
-	color = mix(color, colorFull, smoothstep(0.75, 1.0, totalWeight));
-
-
-	gl_Position = projection * view * worldPos;
-}

+ 0 - 286
materialsLibrary/src/skeletonDebug/boneWeightsMaterial.ts

@@ -1,286 +0,0 @@
-import { Nullable } from "babylonjs/types";
-import { serialize,  serializeAsColor3, SerializationHelper } from "babylonjs/Misc/decorators";
-import { Matrix } from "babylonjs/Maths/math.vector";
-import { Color3 } from "babylonjs/Maths/math.color";
-import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
-import { IEffectCreationOptions } from "babylonjs/Materials/effect";
-import { MaterialDefines } from "babylonjs/Materials/materialDefines";
-import { MaterialHelper } from "babylonjs/Materials/materialHelper";
-import { PushMaterial } from "babylonjs/Materials/pushMaterial";
-
-import { VertexBuffer } from "babylonjs/Meshes/buffer";
-import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
-import { SubMesh } from "babylonjs/Meshes/subMesh";
-import { Mesh } from "babylonjs/Meshes/mesh";
-import { Scene } from "babylonjs/scene";
-import { _TypeStore } from 'babylonjs/Misc/typeStore';
-import { IAnimatable } from 'babylonjs/Animations/animatable.interface';
-import { EffectFallbacks } from 'babylonjs/Materials/effectFallbacks';
-
-import "./boneWeights.fragment";
-import "./boneWeights.vertex";
-
-import { IBoneWeightsMaterialOptions } from "./IBoneWeightsMaterial";
-import { Skeleton } from 'babylonjs';
-
-class BoneWeightsMaterialDefines extends MaterialDefines {
-    public DIFFUSE = false;
-    public HEIGHTMAP = false;
-    public CLIPPLANE = false;
-    public CLIPPLANE2 = false;
-    public CLIPPLANE3 = false;
-    public CLIPPLANE4 = false;
-    public CLIPPLANE5 = false;
-    public CLIPPLANE6 = false;
-    public ALPHATEST = false;
-    public DEPTHPREPASS = false;
-    public POINTSIZE = false;
-    public FOG = false;
-    public NORMAL = false;
-    public UV1 = false;
-    public UV2 = false;
-    public VERTEXCOLOR = false;
-    public VERTEXALPHA = false;
-    public NUM_BONE_INFLUENCERS = 0;
-    public BonesPerMesh = 0;
-    public INSTANCES = false;
-    public HIGHLEVEL = false;
-    constructor() {
-        super();
-        this.rebuild();
-    }
-}
-
-
-export class BoneWeightsMaterial extends PushMaterial{
-    @serialize('skeleton')
-    public skeleton: Skeleton;
-    @serializeAsColor3('colorBase')
-    public colorBase: Color3;
-    @serializeAsColor3('colorZero')
-    public colorZero: Color3;
-    @serializeAsColor3('colorQuarter')
-    public colorQuarter: Color3;
-    @serializeAsColor3('colorHalf')
-    public colorHalf: Color3;
-    @serializeAsColor3('colorFull')
-    public colorFull: Color3;
-    @serialize('targetBoneIndex')
-    public targetBoneIndex: number; 
-   
-    constructor(name: string, options:IBoneWeightsMaterialOptions, scene: Scene) {
-        super(name, scene);
-        this.skeleton = options.skeleton;
-        this.colorBase = options.colorBase ?? Color3.Black();
-        this.colorZero = options.colorZero ?? Color3.Blue();
-        this.colorQuarter = options.colorQuarter ?? Color3.Green();
-        this.colorHalf = options.colorHalf ?? Color3.Yellow();
-        this.colorFull = options.colorFull ?? Color3.Red();
-        this.targetBoneIndex = options.targetBoneIndex ?? 0;
-    }
-
-    public needAlphaBlending(): boolean {
-        return false;
-    }
-
-    public needAlphaTesting(): boolean {
-        return false;
-    }
-
-    public getAlphaTestTexture(): Nullable<BaseTexture> {
-        return null;
-    }
-
-  // Methods
-  public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {
-    if (this.isFrozen) {
-        if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {
-            return true;
-        }
-    }
-
-    if (!subMesh._materialDefines) {
-        subMesh._materialDefines = new BoneWeightsMaterialDefines();
-    }
-
-    var defines = <BoneWeightsMaterialDefines>subMesh._materialDefines;
-    var scene = this.getScene();
-
-    if (this._isReadyForSubMesh(subMesh)) {
-        return true;
-    }
-
-    var engine = scene.getEngine();
-
-    // Misc.
-    MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
-
-    // Lights
-    //defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 0, true);
-
-    // Values that need to be evaluated on every frame
-    MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
-
-    // Attribs
-    MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
-    //console.log(defines)
-
-    // Get correct effect
-    if (defines.isDirty) {
-        defines.markAsProcessed();
-        scene.resetCachedMaterial();
-
-        // Fallbacks
-        var fallbacks = new EffectFallbacks(); 
-        if (defines.FOG) {
-            fallbacks.addFallback(1, "FOG");
-        }  
-
-        MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, 0);
-
-        if (defines.NUM_BONE_INFLUENCERS > 0) {
-            fallbacks.addCPUSkinningFallback(0, mesh);
-        }
-
-        //Attributes
-        var attribs = [VertexBuffer.PositionKind];
-
-        if (defines.NORMAL) {
-            attribs.push(VertexBuffer.NormalKind);
-        } 
-
-        MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
-        //console.log(attribs)
-        MaterialHelper.PrepareAttributesForInstances(attribs, defines);
-
-        var shaderName = "boneWeights";
-        var join = defines.toString();
-        var uniforms = ["world", "view", "viewProjection", 'projection', 'viewProjection',
-            'colorBase', 'colorZero', 'colorQuarter', 'colorHalf', 'colorFull', 'targetBoneIndex'           
-        ];
-        var samplers:string[] = [];
-        var uniformBuffers = new Array<string>();
-
-        MaterialHelper.PrepareUniformsAndSamplersList(<IEffectCreationOptions>{
-            uniformsNames: uniforms,
-            uniformBuffersNames: uniformBuffers,
-            samplers: samplers,
-            defines: defines,
-            maxSimultaneousLights: 0
-        });
-        console.log(uniforms)
-        let effect = scene.getEngine().createEffect(shaderName,
-            <IEffectCreationOptions>{
-                attributes: attribs,
-                uniformsNames: uniforms,
-                uniformBuffersNames: uniformBuffers,
-                samplers: samplers,
-                defines: join,
-                fallbacks: fallbacks,
-                onCompiled: this.onCompiled,
-                onError: this.onError,
-                indexParameters: { maxSimultaneousLights: 0 }
-            }, engine);
-        
-        effect.onBindObservable.add(()=>{
-            effect.setColor3('colorBase', this.colorBase);
-            effect.setColor3('colorZero', this.colorZero);
-            effect.setColor3('colorQuarter', this.colorQuarter);
-            effect.setColor3('colorHalf', this.colorHalf);
-            effect.setColor3('colorFull', this.colorFull);
-            effect.setFloat('targetBoneIndex', this.targetBoneIndex);
-            //subMesh.transparencyMode = Material.MATERIAL_OPAQUE;
-        })
-        subMesh.setEffect(effect, defines);
-
-    }
-    if (!subMesh.effect || !subMesh.effect.isReady()) {
-        return false;
-    }
-
-    defines._renderId = scene.getRenderId();
-    subMesh.effect._wasPreviouslyReady = true;
-
-    return true;
-}
-
-public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void {
-    var scene = this.getScene();
-
-    var defines = <BoneWeightsMaterialDefines>subMesh._materialDefines;
-    if (!defines) {
-        return;
-    }
-
-    var effect = subMesh.effect;
-    if (!effect) {
-        return;
-    }
-    this._activeEffect = effect;
-
-    // Matrices
-    this.bindOnlyWorldMatrix(world);
-    this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
-
-    // Bones
-    MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
-
-    if (this._mustRebind(scene, effect)) {
-        MaterialHelper.BindEyePosition(effect, scene);
-    }
-  
-    this._afterBind(mesh, this._activeEffect);
-}
-
-public getAnimatables(): IAnimatable[] {
-    return []
-}
-
-public getActiveTextures(): BaseTexture[] {
-    return []
-}
-
-public hasTexture(texture: BaseTexture): boolean {
-    return false;    
-}
-
-public dispose(forceDisposeEffect?: boolean): void {
-    super.dispose(forceDisposeEffect);
-}
-
-public getClassName(): string {
-    return "BoneWeightsMaterial";
-}
-
-public clone(name: string): BoneWeightsMaterial {
-    return SerializationHelper.Clone<BoneWeightsMaterial>(() => new BoneWeightsMaterial(name, {
-        skeleton:this.skeleton,
-        colorBase:this.colorBase,
-        colorZero:this.colorZero,
-        colorQuarter:this.colorQuarter,
-        colorHalf:this.colorHalf,
-        colorFull:this.colorFull
-    }, this.getScene()), this);
-}
-
-public serialize(): any {
-    var serializationObject = SerializationHelper.Serialize(this);
-    serializationObject.customType = "BABYLON.BoneWeightsMaterial";
-    return serializationObject;
-}
-
-// Statics
-public static Parse(source: any, scene: Scene, rootUrl: string): BoneWeightsMaterial {
-    return SerializationHelper.Parse(() => new BoneWeightsMaterial(source.name, {
-        skeleton:source.skeleton,
-        colorBase:source.colorBase,
-        colorZero:source.colorZero,
-        colorQuarter:source.colorQuarter,
-        colorHalf:source.colorHalf,
-        colorFull:source.colorFull
-    }, scene), source, scene, rootUrl);
-}
-
-}
-
-_TypeStore.RegisteredTypes["BABYLON.BoneWeightsMaterial"] = BoneWeightsMaterial;

+ 0 - 1
materialsLibrary/src/skeletonDebug/index.ts

@@ -1 +0,0 @@
-export * from "./boneWeightsMaterial";

+ 29 - 0
src/Debug/ISkeletonViewer.ts

@@ -19,6 +19,9 @@ export interface ISkeletonViewerOptions{
 
    /** Flag to toggle if the Viewer should use the CPU for animations or not? */
    computeBonesUsingShaders : boolean;
+
+   /** Flag ignore non weighted bones */
+   useAllBones: boolean;
 }
 
 /**
@@ -42,6 +45,32 @@ export interface ISkeletonViewerDisplayOptions{
 }
 
 /**
+ * Defines the constructor options for the BoneWeight Shader.
+ */
+export interface IBoneWeightShaderOptions{
+   /** Skeleton to Map */
+   skeleton: Skeleton;
+
+   /** Colors for Uninfluenced bones */
+   colorBase? : Color3;
+
+   /** Colors for 0.0-0.25 Weight bones */
+   colorZero? : Color3;
+
+   /** Color for 0.25-0.5 Weight Influence */
+   colorQuarter? : Color3;
+
+   /** Color for 0.5-0.75 Weight Influence */
+   colorHalf? : Color3;
+
+   /** Color for 0.75-1 Weight Influence */
+   colorFull? : Color3;
+
+   /** Color for Zero Weight Influence */
+   targetBoneIndex? : number;
+}
+
+/**
  * Simple structure of the gradient steps for the Color Map.
  */
 export interface ISkeletonMapShaderColorMapKnot{

+ 3 - 6
src/Debug/skeletonViewer.ts

@@ -15,7 +15,7 @@ import { ShaderMaterial } from '../Materials/shaderMaterial';
 import { DynamicTexture } from '../Materials/Textures/dynamicTexture';
 import { VertexBuffer } from '../Meshes/buffer';
 
-import { ISkeletonViewerOptions, ISkeletonMapShaderOptions, ISkeletonMapShaderColorMapKnot } from './ISkeletonViewer';
+import { ISkeletonViewerOptions, IBoneWeightShaderOptions, ISkeletonMapShaderOptions, ISkeletonMapShaderColorMapKnot } from './ISkeletonViewer';
 import { Observer } from '../Misc/observable';
 
 import { SphereBuilder } from '../Meshes/Builders/sphereBuilder';
@@ -38,7 +38,7 @@ export class SkeletonViewer {
      * @param scene The scene that the shader is scoped to
      * @returns The created ShaderMaterial
      */
-    /*static CreateBoneWeightShader(options: IBoneWeightShaderOptions, scene: Scene): ShaderMaterial {
+    static CreateBoneWeightShader(options: IBoneWeightShaderOptions, scene: Scene): ShaderMaterial {
 
         let skeleton: Skeleton = options.skeleton;
         let colorBase: Color3 = options.colorBase ?? Color3.Black();
@@ -134,7 +134,7 @@ export class SkeletonViewer {
         shader.transparencyMode = Material.MATERIAL_OPAQUE;
 
         return shader;
-    }*/
+    }
 
     /** public static method to create a BoneWeight Shader
      * @param options The constructor options
@@ -349,7 +349,6 @@ export class SkeletonViewer {
         }
         this.options.displayMode = value;
     }
-
     /**
      * Creates a new SkeletonViewer
      * @param skeleton defines the skeleton to render
@@ -391,13 +390,11 @@ export class SkeletonViewer {
 
         const boneIndices = mesh.getVerticesData(VertexBuffer.MatricesIndicesKind);
         const boneWeights = mesh.getVerticesData(VertexBuffer.MatricesWeightsKind);
-
         this._boneIndices = new Set();
 
         if (boneIndices && boneWeights) {
             for (let i = 0; i < boneIndices.length; ++i) {
                 const index = boneIndices[i], weight = boneWeights[i];
-
                 if (weight !== 0) {
                     this._boneIndices.add(index);
                 }