repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
effects-runtime | github_2023 | galacean | typescript | PMaterialPBR.getOcclusionTexture | getOcclusionTexture (): Texture {
return this.occlusionTexture as Texture;
} | /**
* 获取遮挡纹理
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/material.ts#L775-L777 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMaterialPBR.setOcclusionTexture | setOcclusionTexture (val: Texture) {
this.occlusionTexture = val;
} | /**
* 设置遮挡纹理
* @param val - 纹理
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/material.ts#L783-L785 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMaterialPBR.hasEmissiveTexture | hasEmissiveTexture (): boolean {
return this.emissiveTexture !== undefined;
} | /**
* 是否有自发光纹理
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/material.ts#L791-L793 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMaterialPBR.getEmissiveTexture | getEmissiveTexture (): Texture {
return this.emissiveTexture as Texture;
} | /**
* 获取自发光纹理
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/material.ts#L799-L801 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMaterialPBR.setEmissiveTexture | setEmissiveTexture (val: Texture) {
this.emissiveTexture = val;
} | /**
* 设置自发光纹理
* @param val - 纹理
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/material.ts#L807-L809 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMaterialPBR.hasEmissiveValue | hasEmissiveValue (): boolean {
return this.emissiveFactor.luminance() * this.emissiveIntensity > 0;
} | /**
* 是否有自发光值,包含强度
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/material.ts#L815-L817 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMaterialPBR.getEmissiveFactor | getEmissiveFactor (): Color {
return this.emissiveFactor;
} | /**
* 获取自发光颜色
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/material.ts#L823-L825 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMaterialPBR.setEmissiveFactor | setEmissiveFactor (val: Color | Vector3 | spec.vec3) {
if (val instanceof Color) {
// Color
this.emissiveFactor.set(val.r, val.g, val.b, val.a);
} else if (val instanceof Vector3) {
// Vector3
this.emissiveFactor.set(val.x, val.y, val.z, 0);
} else {
// vec3
this.emissiveFactor.set(val[0], val[1], val[2], 0);
}
} | /**
* 设置自发光颜色
* @param val - 颜色
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/material.ts#L831-L842 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMaterialPBR.getEmissiveIntensity | getEmissiveIntensity (): number {
return this.emissiveIntensity;
} | /**
* 获取自发光强度
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/material.ts#L848-L850 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMaterialPBR.setEmissiveIntensity | setEmissiveIntensity (val: number) {
this.emissiveIntensity = val;
} | /**
* 设置自发光强度
* @param val - 强度
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/material.ts#L856-L858 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMesh.constructor | constructor (
private engine: Engine,
name: string,
meshData: ModelMeshComponentData,
owner: ModelMeshComponent,
parentId?: string,
parent?: VFXItem,
) {
super();
const proxy = new EffectsMeshProxy(meshData, owner, parent);
this.name = name;
this.type = PObjectType.mesh;
this.visible = false;
this.owner = owner;
//
this.parentIndex = proxy.getParentIndex();
this.parentItem = proxy.parentItem;
this.parentItemId = parentId;
this.rootBoneItem = meshData.rootBone as unknown as VFXItem;
this.skin = proxy.getSkinObj(engine);
this.morph = proxy.getMorphObj();
this.hide = proxy.isHide();
this.priority = owner?.item?.renderOrder || 0;
//
this.subMeshes = [];
const geometry = proxy.getGeometry() as unknown as Geometry;
const materials = owner?.materials ?? [];
materials.forEach(material => {
const subMesh = new PSubMesh(this.engine);
subMesh.create(geometry, material, this);
this.subMeshes.push(subMesh);
});
if (this.subMeshes.length <= 0) {
console.warn(`No primitive inside mesh item ${name}.`);
}
this.boundingBox = this.getItemBoundingBox(meshData.interaction);
} | /**
* 构造函数,创建 Mesh 对象,并与所属组件和父元素相关联
* @param engine - 引擎
* @param name - 名称
* @param meshData - Mesh 参数
* @param owner - 所属的 Mesh 组件
* @param parentId - 父元素索引
* @param parent - 父元素
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L90-L131 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMesh.build | build (scene: PSceneManager) {
if (this.isBuilt) {
return;
}
this.isBuilt = true;
this.subMeshes.forEach(prim => {
prim.build(scene.maxLightCount, scene.skybox);
});
if (PGlobalState.getInstance().visBoundingBox) {
this.boundingBoxMesh = new BoxMesh(this.engine, this.priority);
}
} | /**
* 创建 GE 的 Mesh、Geometry 和 Material 对象
* @param scene - 场景管理器
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L138-L151 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMesh.update | override update () {
if (this.owner !== undefined) {
this.transform.fromEffectsTransform(this.owner.transform);
if (this.morph && this.morph.hasMorph() && this.owner.morphWeights.length > 0) {
this.morph.updateWeights(this.owner.morphWeights);
}
}
} | /**
* 更新变换数据和蒙皮数据
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L156-L164 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMesh.lateUpdate | lateUpdate () {
this.skin?.updateSkinMatrices();
} | /**
* 更新骨骼动画
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L169-L171 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMesh.render | override render (scene: PSceneManager, renderer: Renderer) {
this.updateMaterial(scene);
this.subMeshes.forEach((subMesh, index) => {
renderer.drawGeometry(
subMesh.getEffectsGeometry(),
subMesh.getEffectsMaterial(),
index
);
});
if (this.visBoundingBox && this.boundingBoxMesh !== undefined) {
const mesh = this.boundingBoxMesh.mesh;
renderer.drawGeometry(mesh.geometry, mesh.material);
}
} | /**
* 渲染 Mesh 对象,需要将内部相关数据传给渲染器
* @param scene - 场景
* @param renderer - 渲染器
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L178-L194 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMesh.dispose | override dispose () {
if (this.isDisposed) {
return;
}
super.dispose();
this.owner = undefined;
this.isDisposed = true;
// @ts-expect-error
this.engine = null;
this.parentItem = undefined;
this.skin?.dispose();
this.skin = undefined;
this.morph?.dispose();
this.morph = undefined;
this.subMeshes.forEach(prim => {
prim.dispose();
});
this.subMeshes = [];
this.boundingBoxMesh?.dispose();
this.boundingBoxMesh = undefined;
} | /**
* 销毁,需要主动释放蒙皮、morph 和 Mesh 等相关的对象
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L200-L222 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMesh.updateMorphWeights | updateMorphWeights (weightsArray: Float32Array) {
if (this.morph === undefined || !this.morph.hasMorph()) {
return;
}
const updatedArray = this.morph.morphWeightsArray;
if (updatedArray === undefined) {
return;
}
if (updatedArray.length != weightsArray.length) {
throw new Error('Weight array length mismatch.');
}
for (let i = 0; i < updatedArray.length; i++) {
updatedArray[i] = weightsArray[i];
}
} | /**
* 更新 Morph 动画权重
* 每帧都会更新 Morph 动画权重,需要小心检查 Morph 动画参数
* 对于数组长度对不上的情况,直接报错
*
* @param weightsArray - Morph 动画的权重数组
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L231-L249 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMesh.updateParentInfo | updateParentInfo (parentId: string, parentItem: VFXItem) {
this.parentItemId = parentId;
this.parentItem = parentItem;
if (this.skin !== undefined) {
this.skin.updateParentItem(parentItem);
}
} | /**
* 更新父 VFX 元素
* @param parentId - 父元素索引
* @param parentItem - 父 VFX 元素
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L256-L262 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMesh.updateMaterial | updateMaterial (scene: PSceneManager) {
const worldMatrix = this.matrix;
const normalMatrix = worldMatrix.clone().invert().transpose();
const sceneStates = scene.sceneStates;
this.subMeshes.forEach(prim => {
prim.updateMaterial(worldMatrix, normalMatrix, sceneStates);
});
if (this.boundingBoxMesh !== undefined) {
this.computeBoundingBox(worldMatrix);
const lineColor = new Vector3(1, 1, 1);
const minPos = this.boundingBox.min;
const maxPos = this.boundingBox.max;
const positions = new Float32Array([
minPos.x, minPos.y, minPos.z,
maxPos.x, minPos.y, minPos.z,
maxPos.x, maxPos.y, minPos.z,
minPos.x, maxPos.y, minPos.z,
minPos.x, minPos.y, maxPos.z,
maxPos.x, minPos.y, maxPos.z,
maxPos.x, maxPos.y, maxPos.z,
minPos.x, maxPos.y, maxPos.z,
]);
this.boundingBoxMesh.update(worldMatrix, sceneStates.viewProjectionMatrix, positions, lineColor);
}
} | /**
* 根据当前场景状态更新内部材质数据
* @param scene - 场景管理器
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L268-L296 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMesh.hitTesting | hitTesting (rayOrigin: Vector3, rayDirection: Vector3): Vector3[] {
const worldMatrix = this.matrix;
const invWorldMatrix = worldMatrix.clone().invert();
const newOrigin = invWorldMatrix.transformPoint(rayOrigin, new Vector3());
const newDirection = invWorldMatrix.transformNormal(rayDirection, new Vector3());
const bounding = this.boundingBox;
const boxt = RayBoxTesting(newOrigin, newDirection, bounding.min, bounding.max);
if (boxt === undefined) {
return [];
}
let mint: number | undefined;
if (PGlobalState.getInstance().isEditorEnv) {
this.subMeshes.forEach(prim => {
const primt = prim.hitTesting(newOrigin, newDirection, worldMatrix, invWorldMatrix);
if (primt !== undefined) {
if (mint === undefined || mint > primt) {
mint = primt;
}
}
});
} else {
mint = boxt;
}
if (mint === undefined) {
return [];
}
newDirection.multiply(mint);
newOrigin.add(newDirection);
worldMatrix.transformPoint(newOrigin);
return [newOrigin];
} | /**
* 点击测试,对于编辑器模式会进行精准的点击测试,否则就和内部的包围盒进行测试
* @param rayOrigin - 射线原点
* @param rayDirection - 射线方向
* @returns 交点列表
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L304-L342 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMesh.computeBoundingBox | computeBoundingBox (worldMatrix: Matrix4): Box3 {
const box = this.boundingBox.makeEmpty();
const inverseWorldMatrix = worldMatrix.clone().invert();
this.subMeshes.forEach(prim => {
const subbox = prim.computeBoundingBox(inverseWorldMatrix);
box.union(subbox);
});
return box;
} | /**
* 计算包围盒,根据传入的世界矩阵
* @param worldMatrix - 世界矩阵
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L349-L360 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMesh.getParentId | getParentId (): string | undefined {
return this.parentItemId;
} | /**
* 获取父节点 id
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L391-L393 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMesh.hasSkin | get hasSkin (): boolean {
return this.skin !== undefined;
} | /**
* 是否有蒙皮
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L398-L400 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSubMesh.create | create (geometry: Geometry, material: Material, parent: PMesh) {
this.parent = parent;
this.skin = parent.skin;
this.morph = parent.morph;
this.setGeometry(geometry);
this.setMaterial(material);
this.name = parent.name;
this.effectsPriority = parent.priority;
this.geometry.setHide(parent.hide);
if (this.skin !== undefined) {
const jointCount = this.skin.maxJointCount;
this.jointMatrixList = new Float32Array(jointCount * 16);
this.jointNormalMatList = new Float32Array(jointCount * 16);
if (this.skin.isTextureDataMode()) {
const isHalfFloat = this.skin.textureDataMode === TextureDataMode.half_float;
this.jointMatrixTexture = new PAnimTexture(this.engine);
this.jointNormalMatTexture = new PAnimTexture(this.engine);
this.jointMatrixTexture.create(jointCount, isHalfFloat, 'jointMatrixTexture');
this.jointNormalMatTexture.create(jointCount, isHalfFloat, 'jointNormalMatTexture');
}
} else {
if (this.geometry.hasWeights() || this.geometry.hasJoints()) {
// 最近出现发布后模型动画没播出来问题,
// 是因为导出后 skin 属性丢失导致,所以增加这个检查
console.warn('Geometry has weight and/or joint array, but the skin is missing.');
}
}
this.isCompressed = this.geometry.isCompressed();
//if (PGlobalState.getInstance().isTiny3dMode) {
// if (this._material.isAdditive || this._material.isTranslucent()) { this.mriPriority += 10000; }
//}
} | /**
* 创建 Primitive 对象
* @param data - Primitive 参数
* @param parent - 所属 Mesh 对象
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L450-L486 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSubMesh.build | build (lightCount: number, skybox?: PSkybox) {
const globalState = PGlobalState.getInstance();
const primitiveMacroList = this.getMacroList(lightCount, true, skybox);
const materialMacroList = this.material.getMacroList(primitiveMacroList);
let material: Material;
const isWebGL2 = PGlobalState.getInstance().isWebGL2;
if (this.material.effectMaterial) {
material = this.material.effectMaterial;
materialMacroList.forEach(macro => {
const { name, value } = macro;
material.enableMacro(name, value);
});
this.material.setMaterialStates(material);
} else {
material = Material.create(
this.engine,
{
shader: {
vertex: this.material.vertexShaderCode,
fragment: this.material.fragmentShaderCode,
shared: globalState.shaderShared,
glslVersion: isWebGL2 ? GLSLVersion.GLSL3 : GLSLVersion.GLSL1,
},
}
);
this.material.setMaterialStates(material);
}
} | /**
* 创建 GE Mesh、Geometry 和 Material 对象,用于后面的渲染
* @param lightCount - 灯光数目
* @param skybox - 天空盒
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L493-L525 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSubMesh.getFeatureList | private getFeatureList (lightCount: number, pbrPass: boolean, skybox?: PSkybox): string[] {
const featureList: string[] = [];
if (this.geometry.hasNormals()) {
featureList.push('HAS_NORMALS 1');
}
if (this.geometry.hasTangents()) {
featureList.push('HAS_TANGENTS 1');
}
if (this.geometry.hasUVCoords(1)) {
featureList.push('HAS_UV_SET1 1');
}
if (this.geometry.hasUVCoords(2)) {
featureList.push('HAS_UV_SET2 1');
}
if (this.morph !== undefined && this.morph.hasMorph()) {
// 存在 Morph 动画,需要配置 Morph 动画相关的 Shader 宏定义
// USE_MORPHING 是总开关,WEIGHT_COUNT 是 weights 数组长度(Shader)
featureList.push('USE_MORPHING');
featureList.push(`WEIGHT_COUNT ${this.morph.morphWeightsLength}`);
for (let i = 0; i < this.morph.morphWeightsLength; i++) {
if (this.morph.hasPositionMorph) {
featureList.push(`HAS_TARGET_POSITION${i}`);
}
if (this.morph.hasNormalMorph) {
featureList.push(`HAS_TARGET_NORMAL${i}`);
}
if (this.morph.hasTangentMorph) {
featureList.push(`HAS_TARGET_TANGENT${i}`);
}
}
}
if (this.skin !== undefined) {
featureList.push('USE_SKINNING 1');
featureList.push(`JOINT_COUNT ${this.skin.getJointCount()}`);
featureList.push('HAS_JOINT_SET1 1');
featureList.push('HAS_WEIGHT_SET1 1');
if (this.skin.textureDataMode) { featureList.push('USE_SKINNING_TEXTURE 1'); }
}
if (this.material.materialType !== PMaterialType.unlit) {
// let hasLight = false;
if (lightCount > 0 && this.geometry.hasNormals()) {
// hasLight = true;
featureList.push('USE_PUNCTUAL 1');
featureList.push(`LIGHT_COUNT ${lightCount}`);
}
if (skybox !== undefined && skybox.available) {
// hasLight = true;
featureList.push('USE_IBL 1');
featureList.push('USE_TEX_LOD 1');
if (skybox.hasDiffuseImage) {
// do nothing
} else {
featureList.push('IRRADIANCE_COEFFICIENTS 1');
}
}
// if(!hasLight){
// featureList.push('MATERIAL_UNLIT 1');
// }
}
// 渲染中间结果输出,用于渲染效果调试,支持 pbr 和 unlit
const renderMode = PGlobalState.getInstance().renderMode3D;
const outputDefine = this.getRenderMode3DDefine(renderMode);
if (outputDefine !== undefined) {
featureList.push('DEBUG_OUTPUT 1');
featureList.push(`${outputDefine} 1`);
}
return featureList;
} | // TODO: 待移除? | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L528-L605 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSubMesh.dispose | dispose () {
// @ts-expect-error
this.engine = null;
this.parent = undefined;
this.skin = undefined;
this.morph = undefined;
this.geometry.dispose();
this.material.dispose();
//
this.jointMatrixList = undefined;
this.jointNormalMatList = undefined;
this.jointMatrixTexture?.dispose();
this.jointMatrixTexture = undefined;
this.jointNormalMatTexture?.dispose();
this.jointNormalMatTexture = undefined;
} | /**
* 销毁,需要释放创建的 GE 对象
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L687-L702 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSubMesh.updateMaterial | updateMaterial (worldMatrix: Matrix4, nomralMatrix: Matrix4, sceneStates: PSceneStates) {
this.updateUniformsByAnimation(worldMatrix, nomralMatrix);
this.updateUniformsByScene(sceneStates);
this.material.updateUniforms(this.getEffectsMaterial());
} | /**
* 更新内部 GE 材质着色器 Uniform 数据,根据场景状态
* @param worldMatrix - 世界矩阵
* @param nomralMatrix - 法线矩阵
* @param sceneStates - 场景状态
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L710-L714 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSubMesh.hitTesting | hitTesting (newOrigin: Vector3, newDirection: Vector3, worldMatrix: Matrix4, invWorldMatrix: Matrix4) {
const bounding = this.boundingBox;
const boxt = RayBoxTesting(newOrigin, newDirection, bounding.min, bounding.max);
const bindMatrices: Matrix4[] = [];
if (boxt === undefined) {
return;
}
if (this.skin !== undefined) {
const animMatrices = this.skin.animationMatrices;
animMatrices.forEach(mat => {
bindMatrices.push(new Matrix4().multiplyMatrices(invWorldMatrix, mat));
});
}
const proxy = new HitTestingProxy();
const doubleSided = this.material.isBothSide();
proxy.create(this.geometry.geometry, doubleSided, bindMatrices);
return proxy.getHitPoint(newOrigin, newDirection);
} | /**
* 点击测试,先进行简单的包围合测试,然后再计算精准的点击测试,这个测试非常耗时不要在移动端上使用
* @param newOrigin - 射线原点
* @param newDirection - 射线方向
* @param worldMatrix - 世界矩阵
* @param invWorldMatrix - 逆世界矩阵
* @returns 射线的 t 参数
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L724-L747 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSubMesh.computeBoundingBox | computeBoundingBox (inverseWorldMatrix: Matrix4): Box3 {
if (this.skin === undefined && !this.boundingBox.isEmpty()) {
// 包围盒缓存了,直接返回计算的结果
return this.boundingBox;
}
// 重新计算包围盒
const bindMatrices: Matrix4[] = [];
if (this.skin !== undefined) {
const animMatrices = this.skin.animationMatrices;
animMatrices.forEach(mat => {
bindMatrices.push(new Matrix4().multiplyMatrices(inverseWorldMatrix, mat));
});
}
const proxy = new GeometryBoxProxy();
proxy.create(this.geometry.geometry, bindMatrices);
return proxy.getBoundingBox(this.boundingBox);
} | /**
* 计算包围盒
* @param inverseWorldMatrix - 逆世界矩阵
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L754-L776 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSubMesh.getRenderMode3DDefine | getRenderMode3DDefine (mode: spec.RenderMode3D): string | undefined {
switch (mode) {
case spec.RenderMode3D.uv:
return 'DEBUG_UV';
case spec.RenderMode3D.normal:
return 'DEBUG_NORMAL';
case spec.RenderMode3D.basecolor:
return 'DEBUG_BASECOLOR';
case spec.RenderMode3D.alpha:
return 'DEBUG_ALPHA';
case spec.RenderMode3D.metallic:
return 'DEBUG_METALLIC';
case spec.RenderMode3D.roughness:
return 'DEBUG_ROUGHNESS';
case spec.RenderMode3D.ao:
return 'DEBUG_OCCLUSION';
case spec.RenderMode3D.emissive:
return 'DEBUG_EMISSIVE';
case spec.RenderMode3D.diffuse:
return 'DEBUG_DIFFUSE';
}
} | /**
* 渲染输出模式转成着色器中的宏定义
* @param mode - 渲染输出模式
* @returns 返回相应的宏定义
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L783-L804 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSubMesh.hasSkin | hasSkin (): boolean {
return this.skin !== undefined;
} | /**
* 是否有蒙皮
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L917-L919 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSubMesh.getEffectsGeometry | getEffectsGeometry (): Geometry {
return this.geometry.geometry;
} | /**
* 获取 GE 几何体
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L925-L927 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSubMesh.setGeometry | setGeometry (val: PGeometry | Geometry) {
if (val instanceof PGeometry) {
this.geometry = val;
} else {
this.geometry = new PGeometry(val);
}
} | /**
* 设置几何体
* @param val - 插件或 GE 几何体
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L933-L939 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSubMesh.setMaterial | setMaterial (val: PMaterial | Material) {
if (val instanceof PMaterialUnlit) {
this.material = val;
} else if (val instanceof PMaterialPBR) {
this.material = val;
} else {
this.material = createPluginMaterial(val);
}
} | /**
* 设置材质
* @param val - 插件材质对象或材质参数
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L945-L953 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSubMesh.getEffectsMaterial | getEffectsMaterial (): Material {
return this.material.effectMaterial;
} | /**
* 获取 GE 材质
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L959-L961 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSubMesh.isUnlitMaterial | isUnlitMaterial (): boolean {
return this.material.materialType === PMaterialType.unlit;
} | /**
* 是否无光照材质
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L967-L969 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSubMesh.hasMorph | hasMorph (): boolean {
if (this.morph === undefined) {
return false;
}
return this.morph.hasMorph();
} | /**
* 是否有 Morph 动画:
* 需要注意 Morph 对象存在,但还是没有 Morph 动画的情况
* @returns 返回是否有 Morph 动画
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L976-L982 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSubMesh.getWorldBoundingBox | getWorldBoundingBox (): Box3 {
if (this.parent === undefined) {
if (this.boundingBox.isEmpty()) {
this.computeBoundingBox(Matrix4.fromIdentity());
}
return this.boundingBox;
} else {
const matrix = this.parent.matrix;
if (this.boundingBox.isEmpty()) {
this.computeBoundingBox(matrix.clone().invert());
}
return this.boundingBox.clone().applyMatrix4(matrix);
}
} | /**
* 获取世界坐标下的包围盒
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L988-L1004 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PGeometry.constructor | constructor (public geometry: Geometry) {
this.attributeNames = geometry.getAttributeNames();
} | /**
* 创建 3D 几何体,根据 GE 几何体
* @param geometry - GE 几何体
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L1020-L1022 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PGeometry.dispose | dispose () {
// @ts-expect-error
this.geometry = undefined;
this.attributeNames = [];
} | /**
* 销毁
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L1027-L1031 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PGeometry.hasAttribute | hasAttribute (name: string): boolean {
const index = this.attributeNames.findIndex(item => {
return item === name;
});
return index !== -1;
} | /**
* 是否有某个属性
* @param name - 属性名
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L1038-L1044 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PGeometry.setHide | setHide (hide: boolean) {
const geomExt = this.geometry as GeometryExt;
if (geomExt.getDrawCount() === 0) {
const indexArray = geomExt.getIndexData();
if (indexArray !== undefined) {
geomExt.setDrawCount(indexArray.length);
}
}
if (hide) {
if (geomExt.getDrawCount() >= 0) {
geomExt.setDrawCount(-geomExt.getDrawCount());
}
} else {
if (geomExt.getDrawCount() < 0) {
geomExt.setDrawCount(-geomExt.getDrawCount());
}
}
} | /**
* 设置隐藏,通过修改几何体中的渲染数目
* @param hide - 隐藏值
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L1050-L1069 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PGeometry.isCompressed | isCompressed (): boolean {
const positionAttrib = this.geometry.getAttributeData('aPos');
if (positionAttrib === undefined) {
return false;
}
// FIXME: get attributes from geometry
//return positionAttrib.normalize === true;
return false;
} | /**
* 是否压缩格式
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L1075-L1085 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PGeometry.hasPositions | hasPositions (): boolean {
return this.hasAttribute('aPos');
} | /**
* 是否有位置属性
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L1091-L1093 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PGeometry.hasNormals | hasNormals (): boolean {
return this.hasAttribute('aNormal');
} | /**
* 是否有法线属性
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L1099-L1101 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PGeometry.hasTangents | hasTangents (): boolean {
return this.hasAttribute('aTangent');
} | /**
* 是否有切线属性
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L1107-L1109 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PGeometry.hasUVCoords | hasUVCoords (index: number): boolean {
if (index === 1) {
return this.hasAttribute('aUV');
} else {
return this.hasAttribute(`aUV${index}`);
}
} | /**
* 是否有纹理坐标属性
* @param index - 纹理坐标索引
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L1116-L1122 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PGeometry.hasColors | hasColors (): boolean {
return this.hasAttribute('aColor');
} | /**
* 是否有颜色属性
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L1128-L1130 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PGeometry.hasJoints | hasJoints (): boolean {
return this.hasAttribute('aJoints');
} | /**
* 是否有关节点属性
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L1136-L1138 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PGeometry.hasWeights | hasWeights (): boolean {
return this.hasAttribute('aWeights');
} | /**
* 是否有权重属性
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L1144-L1146 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | EffectsMeshProxy.getMorphObj | getMorphObj (): PMorph | undefined {
if (!this.hasMorphTarget()) {
return;
}
return this.morphObj;
} | /**
* 返回 Morph 对象
* 需要先判断是否有 Morph 动画,如果没有就直接返回 undefined
*
* @returns 缓存的 Morph 对象,或者 undefined
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/mesh.ts#L1186-L1192 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSceneManager.initial | initial (opts: PSceneOptions) {
this.clean();
this.compName = opts.componentName;
this.renderer = opts.renderer;
this.engine = opts.renderer.engine;
this.sceneCache = opts.sceneCache;
this.enableDynamicSort = opts.enableDynamicSort === true;
this.renderSkybox = opts.renderSkybox;
this.maxLightCount = opts.lightItemCount;
this.maxJointCount = opts.maxJointCount;
this.cameraManager.initial(this.renderer.getWidth(), this.renderer.getHeight());
this.brdfLUT = this.sceneCache.getBrdfLutTexture();
this.initGlobalState(opts);
if (this.maxLightCount > 8) {
console.warn(`Too many light items: ${this.maxLightCount} light(s).`);
}
} | /**
* 初始化场景管理器,设置全局状态
* @param opts - 场景参数
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/scene.ts#L235-L252 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSceneManager.dispose | dispose () {
this.itemList.forEach(item => item.dispose());
this.itemList = [];
this.meshList.forEach(mesh => mesh.dispose());
this.meshList = [];
this.lightManager.dispose();
this.cameraManager.dispose();
this.brdfLUT = undefined;
this.skybox?.dispose();
this.skybox = undefined;
this.renderedMeshSet.clear();
//
this.renderer = undefined;
this.sceneCache = undefined;
// @ts-expect-error
this.engine = undefined;
this.parentId2Mesh.clear();
} | /**
* 销毁,需要销毁各种管理器和创建的 WebGL 资源
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/scene.ts#L291-L308 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSceneManager.addItem | addItem (item: PMesh | PCamera | PLight | PSkybox) {
if (item instanceof PMesh) {
const mesh = item;
if (mesh.parentItemId !== undefined) {
this.parentId2Mesh.set(mesh.parentItemId, mesh);
}
addItem(this.meshList, mesh);
} else if (item instanceof PSkybox) {
const skybox = item;
skybox.setup(this.brdfLUT);
if (!this.renderSkybox) {
// renderable会控制天空盒是否作为背景渲染,来自用户(编辑器)的输入
// this.renderSkybox是播放时候的控制参数。
// -- 如果是false,会强制天空不渲染。
// -- 如果是true,会按照用户设置来渲染天空盒。
skybox.renderable = false;
}
this.skybox = skybox;
} else if (item instanceof PLight) {
this.lightManager.insertLight(item);
} else {
this.cameraManager.insertCamera(item);
}
addItem(this.itemList, item);
} | /**
* 添加插件元素到场景中
* @param item - 插件元素
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/scene.ts#L314-L342 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSceneManager.removeItem | removeItem (item: PMesh | PCamera | PLight | PSkybox) {
if (item instanceof PMesh) {
const mesh = item;
if (mesh.parentItemId !== undefined) {
this.parentId2Mesh.delete(mesh.parentItemId);
}
removeItem(this.meshList, mesh);
} else if (item instanceof PSkybox) {
this.skybox = undefined;
} else if (item instanceof PLight) {
this.lightManager.remove(item);
} else {
this.cameraManager.remove(item);
}
removeItem(this.itemList, item);
} | /**
* 从场景中删除插件元素
* @param item - 插件元素
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/scene.ts#L348-L366 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSceneManager.updateDefaultCamera | updateDefaultCamera (camera: CameraOptionsEx, viewportMatrix: Matrix4) {
const effectsTransfrom = new Transform({
...camera,
valid: true,
});
const newTransform = new PTransform().fromEffectsTransform(effectsTransfrom);
this.cameraManager.updateDefaultCamera(
camera.fov,
viewportMatrix,
camera.aspect,
camera.near,
camera.far,
newTransform.getPosition(),
newTransform.getRotation(),
camera.clipMode,
);
} | /**
* 更新默认相机状态,根据传入的相机参数
* @param camera - 相机参数
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/scene.ts#L372-L390 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSceneManager.tick | tick (deltaTime: number) {
const deltaSeconds = deltaTime;
const camera = this.activeCamera;
const viewMatrix = camera.viewMatrix;
const projectionMatrix = camera.projectionMatrix;
const viewProjectionMatrix = projectionMatrix.clone().multiply(viewMatrix);
this.sceneStates = {
deltaSeconds: deltaSeconds,
//
camera: camera,
cameraPosition: camera.getEye(),
viewMatrix: viewMatrix,
inverseViewMatrix: viewMatrix.clone().invert(),
projectionMatrix: projectionMatrix,
viewProjectionMatrix: viewProjectionMatrix,
winSize: camera.getSize(),
sceneRadius: 1.0,
//
lightList: this.lightManager.lightList,
maxLightCount: this.maxLightCount,
maxJointCount: this.maxJointCount,
skybox: this.skybox,
};
if (this.enableDynamicSort) {
this.dynamicSortMeshes(this.sceneStates);
}
this.tickCount += 1;
this.lastTickSecond += deltaSeconds;
} | /**
* 更新插件场景,需要更新内部的相关的插件对象,特别是 Mesh 对象的骨骼动画
* 并将需要渲染的对象添加到渲染对象集合中
* @param deltaTime - 更新间隔
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/scene.ts#L397-L428 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSceneManager.dynamicSortMeshes | dynamicSortMeshes (states: PSceneStates) {
const meshComponents: ModelMeshComponent[] = [];
const priorityList: number[] = [];
this.meshList.forEach(mesh => {
if (mesh.owner && mesh.owner.enabled) {
const component = mesh.owner;
meshComponents.push(component);
priorityList.push(component.priority);
}
});
priorityList.sort((a, b) => a - b);
// 按照 Tiny 排序算法,对 Mesh 对象进行排序
// 将透明和不透明物体拆开,从而渲染正确
const viewMatrix = states.viewMatrix;
meshComponents.sort((a: ModelMeshComponent, b: ModelMeshComponent) => {
const atransparent = WebGLHelper.isTransparentMesh(a);
const btransparent = WebGLHelper.isTransparentMesh(b);
if (atransparent && btransparent) {
const aposition = a.transform.getWorldPosition();
const bposition = b.transform.getWorldPosition();
const anewPos = viewMatrix.transformPoint(aposition);
const bnewPos = viewMatrix.transformPoint(bposition);
if (anewPos.z === bnewPos.z) { return a.priority - b.priority; } else { return anewPos.z - bnewPos.z; }
} else if (atransparent) {
return 1;
} else if (btransparent) {
return -1;
} else {
return a.priority - b.priority;
}
});
let prePriority = -99999;
// 重新赋值渲染优先级
for (let i = 0; i < meshComponents.length; i++) {
const mesh = meshComponents[i];
const priority = priorityList[i];
if (prePriority < priority) {
prePriority = priority;
mesh.priority = priority;
} else {
prePriority += 0.1;
mesh.priority = prePriority;
}
}
} | /**
* 动态调整 Mesh 渲染优先级
* 主要是为了和 Tiny 渲染对齐,正常渲染不进行调整
* @param states - 场景中的状态数据
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/scene.ts#L435-L489 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSceneManager.queryMesh | queryMesh (parentId: string): PMesh | undefined {
const mesh = this.parentId2Mesh.get(parentId);
if (mesh === undefined || !mesh.visible) {
return;
}
return mesh;
} | /**
* 查询场景中的 Mesh
* 通过 parentId 查询 Mesh 对象,可能找不到 Mesh 对象
* @param parentId - Item 中定义的 parentId
* @returns 查询到的 PMesh,或者是没找到。如果 Mesh 不可见,也是没找到。
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/scene.ts#L497-L505 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSceneManager.getSceneAABB | getSceneAABB (box?: Box3): Box3 {
const sceneBox = box ?? new Box3();
this.itemList.forEach(item => {
if (item.type === PObjectType.mesh) {
const mesh = item as PMesh;
if (mesh.owner) {
const transform = mesh.owner.item.getWorldTransform();
const worldMatrix = transform.getWorldMatrix();
const meshBox = mesh.computeBoundingBox(worldMatrix);
meshBox.applyMatrix4(worldMatrix);
sceneBox.union(meshBox);
} else {
sceneBox.union(mesh.computeBoundingBox(Matrix4.fromIdentity()));
}
}
});
return sceneBox;
} | /**
* 获取场景的包围盒
* @param box - 包围盒
* @returns 场景的包围盒
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/scene.ts#L512-L533 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSceneManager.getRenderer | getRenderer (): Renderer {
return this.renderer as Renderer;
} | /**
* 获取渲染器
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/scene.ts#L556-L558 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSceneManager.getSceneCache | getSceneCache (): CompositionCache {
return this.sceneCache as CompositionCache;
} | /**
* 获取场景中缓存
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/scene.ts#L564-L566 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSceneManager.activeCamera | get activeCamera (): PCamera {
return this.cameraManager.getActiveCamera();
} | /**
* 获取激活的相机
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/scene.ts#L571-L573 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSceneManager.lightCount | get lightCount (): number {
return this.lightManager.lightCount;
} | /**
* 获取灯光数目
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/scene.ts#L578-L580 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSceneManager.shaderLightCount | get shaderLightCount (): number {
return Math.min(10, this.lightManager.lightCount);
} | /**
* 获取着色器灯光数目,最小是 10
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/scene.ts#L585-L587 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PShaderManager.getInstance | static getInstance (): PShaderManager {
// Do you need arguments? Make it a regular static method instead.
return this._instance || (this._instance = new this());
} | /**
* 获取着色器单例对象
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/shader.ts#L50-L53 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PShaderManager.genShaderCode | genShaderCode (context: PShaderContext): PShaderResults {
const materialType = context.material.materialType;
const func = this.funcMap.get(materialType);
if (func !== undefined) {
return func(context);
} else {
throw new Error(`Invalid material type ${materialType}, shader content ${context}.`);
}
} | /**
* 生成着色器代码
* @param context - 着色器上下文
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/shader.ts#L71-L80 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkybox.constructor | constructor (name: string, data: ModelSkyboxComponentData, owner?: ModelSkyboxComponent) {
super();
this.name = name;
this.type = PObjectType.skybox;
this.visible = false;
this.owner = owner;
const { irradianceCoeffs } = data;
this.renderable = data.renderable;
this.intensity = data.intensity;
this.reflectionsIntensity = data.reflectionsIntensity;
if (irradianceCoeffs) {
this.irradianceCoeffs = [];
for (let i = 0; i < irradianceCoeffs.length; i += 3) {
this.irradianceCoeffs.push([
irradianceCoeffs[i],
irradianceCoeffs[i + 1],
irradianceCoeffs[i + 2],
]);
}
} else {
this.irradianceCoeffs = [];
}
this.diffuseImage = data.diffuseImage as unknown as Texture;
this.specularImage = data.specularImage as unknown as Texture;
this.specularImageSize = data.specularImageSize;
this.specularMipCount = data.specularMipCount;
this.priority = owner?.item?.renderOrder || 0;
} | /**
* 构造函数
* @param name - 名称
* @param data - 天空盒参数
* @param owner - 所属天空盒组件元素
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L79-L110 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkybox.setup | setup (brdfLUT?: Texture) {
this.brdfLUT = brdfLUT;
} | /**
* 设置 BRDF 查询纹理
* @param brdfLUT - 纹理
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L116-L118 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkybox.build | build (scene: PSceneManager) {
if (this.isBuilt) {
return;
}
this.isBuilt = true;
this.skyboxMaterial = new PMaterialSkyboxFilter();
this.skyboxMaterial.create(this);
this.skyboxMaterial.build();
//
const sceneCache = scene.getSceneCache();
this.skyboxMesh = sceneCache.getFilterMesh('SkyboxFilterPlane', this.skyboxMaterial);
this.skyboxMesh.priority = this.priority;
this.skyboxMaterial.updateUniforms(this.skyboxMesh.material);
} | /**
* 构建天空盒,创建天空盒材质,从场景缓存中创建天空盒 Mesh
* @param sceneCache - 场景缓存
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L125-L140 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkybox.render | override render (scene: PSceneManager, renderer: Renderer) {
this.updateMaterial(scene);
if (this.visible && this.renderable && this.skyboxMesh !== undefined) {
const mesh = this.skyboxMesh;
renderer.drawGeometry(mesh.geometry, mesh.material);
}
} | /**
* 渲染天空盒
* @param scene - 场景
* @param renderer - 渲染器
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L147-L155 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkybox.dispose | override dispose () {
super.dispose();
this.owner = undefined;
this.diffuseImage = undefined;
//@ts-expect-error
this.specularImage = undefined;
this.brdfLUT = undefined;
this.skyboxMesh = undefined;
this.skyboxMaterial?.dispose();
this.skyboxMaterial = undefined;
} | /**
* 销毁
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L160-L170 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkybox.available | get available (): boolean {
if (!this.isValid()) { return false; }
if (this.intensity <= 0 && this.reflectionsIntensity <= 0) { return false; }
if (this.irradianceCoeffs === undefined && this.diffuseImage === undefined) { return false; }
return this.specularImage !== undefined && this.specularMipCount >= 0;
} | /**
* 是否可用,根据内部的强度、辐射照度系数、漫反射贴图和高光贴图状态
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L190-L198 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkybox.currentIntensity | get currentIntensity (): number {
return this.visible ? this.intensity : 0;
} | /**
* 当前强度,如果不可见返回 0
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L203-L205 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkybox.currentReflectionsIntensity | get currentReflectionsIntensity (): number {
return this.visible ? this.reflectionsIntensity : 0;
} | /**
* 当前反射强度,如果不可见返回 0
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L210-L212 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkybox.hasDiffuseImage | get hasDiffuseImage (): boolean {
return this.diffuseImage !== undefined;
} | /**
* 是否有漫反射贴图
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L217-L219 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkybox.hasIrradianceCoeffs | get hasIrradianceCoeffs (): boolean {
return this.irradianceCoeffs !== undefined;
} | /**
* 是否有辐射照度系数
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L224-L226 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMaterialSkyboxFilter.create | create (skybox: PSkybox) {
this.type = PObjectType.material;
this.materialType = PMaterialType.skyboxFilter;
this.ZTest = false;
//
this.name = skybox.name;
this.intensity = skybox.intensity;
this.reflectionsIntensity = skybox.reflectionsIntensity;
this.brdfLUT = skybox.brdfLUT;
this.irradianceCoeffs = skybox.irradianceCoeffs;
this.diffuseImage = skybox.diffuseImage;
this.specularImage = skybox.specularImage;
this.specularMipCount = skybox.specularMipCount;
} | /**
* 创建天空盒材质,从天空盒对象
* @param skybox - 天空盒对象
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L267-L280 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMaterialSkyboxFilter.dispose | override dispose () {
super.dispose();
this.brdfLUT = undefined;
this.irradianceCoeffs = undefined;
this.diffuseImage = undefined;
// @ts-expect-error
this.specularImage = undefined;
} | /**
* 销毁,需要解除资源引用
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L285-L292 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMaterialSkyboxFilter.getShaderFeatures | override getShaderFeatures (): string[] {
const featureList: string[] = [];
featureList.push('USE_IBL 1');
featureList.push('USE_TEX_LOD 1');
if (this.diffuseImage === undefined) { featureList.push('IRRADIANCE_COEFFICIENTS 1'); }
return featureList;
} | /**
* 获取着色器特性列表
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L298-L306 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMaterialSkyboxFilter.updateUniforms | override updateUniforms (material: Material) {
if (this.brdfLUT === undefined) {
throw new Error('Setup brdfLUT for skybox at first.');
}
material.setVector2('_IblIntensity', new Vector2(2.0, 2.0));
material.setTexture('_brdfLUT', this.brdfLUT);
if (this.diffuseImage !== undefined) {
material.setTexture('_DiffuseEnvSampler', this.diffuseImage);
} else {
const coeffs = this.irradianceCoeffs;
if (coeffs === undefined || coeffs.length != 9) { throw new Error(`Invalid skybox irradiance coeffs ${coeffs}.`); }
const aliasName = ['l00', 'l1m1', 'l10', 'l11', 'l2m2', 'l2m1', 'l20', 'l21', 'l22'];
aliasName.forEach((n, i) => {
material.setVector3(`_shCoefficients.${n}`, Vector3.fromArray(coeffs[i] as spec.vec3));
});
}
material.setInt('_MipCount', this.specularMipCount - 1);
material.setTexture('_SpecularEnvSampler', this.specularImage);
} | /**
* 更新着色器 Uniform 数据
* @param material - 对应的 Core 层材质
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L312-L334 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PMaterialSkyboxFilter.setMaterialStates | override setMaterialStates (material: Material) {
material.depthTest = true;
material.depthMask = false;
this.setFaceSideStates(material);
} | /**
* 设置对应的材质状态
* @param material - 对应的 Core 层材质
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L340-L344 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkyboxCreator.getBrdfLutTextureOptions | static async getBrdfLutTextureOptions (): Promise<TextureSourceOptions> {
const brdfURL = 'https://gw.alipayobjects.com/zos/gltf-asset/61420044606400/lut-ggx.png';
//const brdfURL = 'https://gw.alipayobjects.com/zos/gltf-asset/58540818729423/a4191420-a8cd-432c-8e36-9bd02a67ec85.png';
const brdfLutImage = await loadImage(brdfURL);
const brdfLutOpts: TextureSourceOptions = {
name: 'brdfLut',
wrapS: glContext.CLAMP_TO_EDGE,
wrapT: glContext.CLAMP_TO_EDGE,
magFilter: glContext.LINEAR,
minFilter: glContext.LINEAR,
anisotropic: 1,
sourceType: TextureSourceType.image,
image: brdfLutImage,
generateMipmap: false,
flipY: false,
premultiplyAlpha: false,
};
return brdfLutOpts;
} | /**
* 获取 BRDF 查询纹理选项
* @returns 纹理源选项
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L454-L474 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkyboxCreator.createBrdfLutTexture | static async createBrdfLutTexture (engine: Engine): Promise<Texture> {
const brdfLutOpts = await this.getBrdfLutTextureOptions();
const brdfLutTexture = Texture.create(engine, brdfLutOpts);
return brdfLutTexture;
} | /**
* 创建 BRDF 查询纹理
* @param engine - 引擎
* @returns 纹理
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L481-L486 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkyboxCreator.createSkyboxOptions | static async createSkyboxOptions (engine: Engine, params: PSkyboxParams): Promise<ModelSkyboxOptions> {
const specularImage = await this.createSpecularCubeMap(engine, params);
const diffuseImage = await this.createDiffuseCubeMap(engine, params);
const { renderable, intensity, reflectionsIntensity, irradianceCoeffs, specularImageSize, specularMipCount } = params;
const skyboxOptions: ModelSkyboxOptions = {
renderable,
intensity,
reflectionsIntensity,
// @ts-expect-error
irradianceCoeffs,
diffuseImage,
specularImage,
specularImageSize,
specularMipCount,
};
return skyboxOptions;
} | /**
* 创建天空盒选项
* @param engine - 引擎
* @param params - 天空盒参数
* @returns 天空盒选项
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L494-L511 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkyboxCreator.createSkyboxComponentData | static createSkyboxComponentData (params: PSkyboxParams) {
const specularCubeData = PSkyboxCreator.getSpecularCubeMapData(params);
const diffuseCubeData = PSkyboxCreator.getDiffuseCubeMapData(params);
const { renderable, intensity, reflectionsIntensity, irradianceCoeffs, specularImageSize, specularMipCount } = params;
let diffuseImage: spec.DataPath;
const imageList: spec.Image[] = [];
const textureOptionsList: TextureSourceOptions[] = [];
if (diffuseCubeData) {
imageList.push(...diffuseCubeData.images);
textureOptionsList.push(diffuseCubeData.textureOptions);
diffuseImage = {
id: diffuseCubeData.textureOptions.id!,
};
}
imageList.push(...specularCubeData.images);
textureOptionsList.push(specularCubeData.textureOptions);
const specularImage = { id: specularCubeData.textureOptions.id };
const componentData: ModelSkyboxComponentData = {
id: generateGUID(),
dataType: spec.DataType.SkyboxComponent,
item: {
id: generateGUID(),
},
renderable,
intensity,
reflectionsIntensity,
irradianceCoeffs,
// @ts-expect-error
diffuseImage,
// @ts-expect-error
specularImage,
specularImageSize,
specularMipCount,
};
return {
imageList,
textureOptionsList,
component: componentData,
};
} | /**
* 创建天空盒选项
* @param engine - 引擎
* @param params - 天空盒参数
* @returns 天空盒选项
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L519-L562 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkyboxCreator.createSpecularCubeMap | static async createSpecularCubeMap (engine: Engine, params: PSkyboxParams): Promise<Texture> {
// const configOptions: TextureConfigOptions = {
// wrapS: glContext.CLAMP_TO_EDGE,
// wrapT: glContext.CLAMP_TO_EDGE,
// magFilter: glContext.LINEAR,
// minFilter: glContext.LINEAR_MIPMAP_LINEAR,
// };
if (params.type === 'url') {
return WebGLHelper.createTextureCubeMipmapFromURL(engine, params.specularImage);
} else {
return WebGLHelper.createTextureCubeMipmapFromBuffer(engine, params.specularImage, params.specularImageSize);
}
} | /**
* 创建高光 Cube Map 纹理
* @param engine - 引擎
* @param params - 天空盒参数
* @returns 纹理
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L570-L583 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkyboxCreator.createDiffuseCubeMap | static async createDiffuseCubeMap (engine: Engine, params: PSkyboxParams): Promise<Texture | null> {
if (params.diffuseImage === undefined) { return null; }
if (params.type === 'url') {
return WebGLHelper.createTextureCubeFromURL(engine, params.diffuseImage);
} else {
return WebGLHelper.createTextureCubeFromBuffer(engine, params.diffuseImage);
}
} | /**
* 创建漫反射纹理
* @param engine - 引擎
* @param params - 天空盒参数
* @returns 纹理或未定义
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L626-L634 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkyboxCreator.getSkyboxParams | static getSkyboxParams (skyboxType = PSkyboxType.NFT): PSkyboxURLParams {
const specularImage = this.getSpecularImageList(skyboxType);
const params: PSkyboxURLParams = {
type: 'url',
renderable: true,
intensity: 1.8,
reflectionsIntensity: 1.8,
irradianceCoeffs: this.getIrradianceCoeffs(skyboxType),
diffuseImage: this.getDiffuseImageList(skyboxType, specularImage),
specularImage: specularImage,
specularImageSize: Math.pow(2, specularImage.length - 1),
specularMipCount: specularImage.length,
};
return params;
} | /**
* 创建天空盒参数
* @param skyboxType - 天空盒类型
* @returns 天空盒参数
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L676-L691 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | PSkyboxCreator.checkCubeMapImage | private async checkCubeMapImage (imageList: string[]) {
let lastImage!: HTMLImageElement;
const specularImageLists: HTMLImageElement[][] = [];
for (let i = 0; i < imageList.length; i++) {
const image = await loadImage(imageList[i]);
if (i > 0) {
if (i % 6 === 0) {
if (image.width * 2 !== lastImage.width || image.height * 2 !== lastImage.height) {
throw new Error(`Invalid cube map list1: index ${i}, image0 ${lastImage}, image1 ${image}.`);
}
} else {
if (image.width !== lastImage.width || image.height !== lastImage.height) {
throw new Error(`Invalid cube map list2: index ${i}, image0 ${lastImage}, image1 ${image}.`);
}
}
}
if (i % 6 === 0) { specularImageLists.push([]); }
const lastList = specularImageLists[specularImageLists.length - 1];
lastList.push(image);
lastImage = image;
}
} | // TODO: 待移除? | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/skybox.ts#L694-L718 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | StandardShader.getVertexShaderCode | static getVertexShaderCode (context: PShaderContext): string {
const features = context.featureList;
const materialType = context.material.materialType;
switch (materialType) {
case PMaterialType.unlit:
case PMaterialType.pbr:
case PMaterialType.shadowBase:
return StandardShaderSource.build(primitiveVert, features);
case PMaterialType.skyboxFilter:
return StandardShaderSource.build(skyboxVert, features);
default:
throw new Error(`Invalid material type ${materialType} for getVertexShaderString!`);
}
} | /**
* 获取顶点着色器代码
* @param context - 着色器上下文
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/shader-libs/standard-shader.ts#L24-L38 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | StandardShader.getFragmentShaderCode | static getFragmentShaderCode (context: PShaderContext): string {
const features = context.featureList;
const materialType = context.material.materialType;
switch (materialType) {
case PMaterialType.unlit:
case PMaterialType.pbr:
return StandardShaderSource.build(metallicRoughnessFrag, features);
case PMaterialType.shadowBase:
return StandardShaderSource.build(shadowPassFrag, features);
case PMaterialType.skyboxFilter:
return StandardShaderSource.build(skyboxFrag, features);
default:
throw new Error(`Invalid material type ${materialType} for getFragmentShaderString!`);
}
} | /**
* 获取片段着色器代码
* @param context - 着色器上下文
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/shader-libs/standard-shader.ts#L45-L60 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | StandardShader.genFragmentShaderCode | static genFragmentShaderCode (materialType: PMaterialType): string {
switch (materialType) {
case PMaterialType.unlit:
case PMaterialType.pbr:
return metallicRoughnessFrag;
case PMaterialType.shadowBase:
return shadowPassFrag;
case PMaterialType.skyboxFilter:
return skyboxFrag;
default:
throw new Error(`Invalid material type ${materialType} for genFragmentShaderCode!`);
}
} | /**
* 获取片段着色器代码
* @param materialType - 材质类型
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/runtime/shader-libs/standard-shader.ts#L80-L92 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RayIntersectsBoxWithRotation | function RayIntersectsBoxWithRotation (ray: Ray, matrixData: Matrix4, bounding: ModelItemBounding): Vector3[] | undefined {
const local2World = matrixData;
const world2Local = local2World.clone().invert();
const newRay = ray.clone().applyMatrix(world2Local);
const boxCenter = Vector3.fromArray(bounding.center!);
const boxHalfSize = Vector3.fromArray((bounding as ModelItemBoundingBox).size!).multiply(0.5);
const boxMin = boxCenter.clone().subtract(boxHalfSize);
const boxMax = boxCenter.clone().add(boxHalfSize);
const intersetPoint = newRay.intersectBox({ min: boxMin, max: boxMax }, new Vector3());
if (intersetPoint !== undefined) {
const insersetPointInWorld = local2World.transformPoint(intersetPoint);
return [insersetPointInWorld];
} else {
return;
}
} | // 射线与带旋转的包围盒求交 | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/utility/hit-test-helper.ts#L31-L49 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RayBoxTesting | function RayBoxTesting (ro: Vector3, rd: Vector3, bmin: Vector3, bmax: Vector3): number | undefined {
let tmin = 0, tmax = 0;
let tymin = 0, tymax = 0;
let tzmin = 0, tzmax = 0;
const invdirx = 1 / rd.x;
const invdiry = 1 / rd.y;
const invdirz = 1 / rd.z;
if (invdirx >= 0) {
tmin = (bmin.x - ro.x) * invdirx;
tmax = (bmax.x - ro.x) * invdirx;
} else {
tmin = (bmax.x - ro.x) * invdirx;
tmax = (bmin.x - ro.x) * invdirx;
}
if (invdiry >= 0) {
tymin = (bmin.y - ro.y) * invdiry;
tymax = (bmax.y - ro.y) * invdiry;
} else {
tymin = (bmax.y - ro.y) * invdiry;
tymax = (bmin.y - ro.y) * invdiry;
}
// These lines also handle the case where tmin or tmax is NaN
// (result of 0 * Infinity). x !== x returns true if x is NaN
if (tmin > tymax || tymin > tmax) {
return;
}
if (tymin > tmin || tmin !== tmin) {
tmin = tymin;
}
if (tymax < tmax || tmax !== tmax) {
tmax = tymax;
}
if (invdirz >= 0) {
tzmin = (bmin.z - ro.z) * invdirz;
tzmax = (bmax.z - ro.z) * invdirz;
} else {
tzmin = (bmax.z - ro.z) * invdirz;
tzmax = (bmin.z - ro.z) * invdirz;
}
if (tmin > tzmax || tzmin > tmax) {
return;
}
if (tzmin > tmin || tmin !== tmin) {
tmin = tzmin;
}
if (tzmax < tmax || tmax !== tmax) {
//return point closest to the ray (positive side)
tmax = tzmax;
}
if (tmax < 0) {
return;
}
return tmin >= 0 ? tmin : tmax;
} | /**
* 射线与包围盒求交
* @param ro - 射线原点
* @param rd - 射线方向
* @param bmin - 包围盒左下点
* @param bmax - 包围盒右上点
* @returns 交点参数或者 undefined
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/utility/hit-test-helper.ts#L59-L120 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RayTriangleTesting | function RayTriangleTesting (ro: Vector3, rd: Vector3, a: Vector3, b: Vector3, c: Vector3, backfaceCulling: boolean): number | undefined {
// Compute the offset origin, edges, and normal.
// from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
edge1.subtractVectors(b, a);
edge2.subtractVectors(c, a);
normal.crossVectors(edge1, edge2);
// Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
// E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
// |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
// |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
// |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
let DdN = rd.dot(normal);
let sign = 0;
if (DdN > 0) {
if (backfaceCulling) { return; }
sign = 1;
} else if (DdN < 0) {
sign = -1;
DdN = -DdN;
} else {
return;
}
diff.subtractVectors(ro, a);
edge2.crossVectors(diff, edge2);
const DdQxE2 = sign * rd.dot(edge2); // b1 < 0, no intersection
if (DdQxE2 < 0) {
return;
}
edge1.crossVectors(edge1, diff);
const DdE1xQ = sign * rd.dot(edge1); // b2 < 0, no intersection
if (DdE1xQ < 0) {
return;
} // b1+b2 > 1, no intersection
if (DdQxE2 + DdE1xQ > DdN) {
return;
} // Line intersects triangle, check if ray does.
const QdN = -sign * diff.dot(normal); // t < 0, no intersection
if (QdN < 0) {
return;
} // Ray intersects triangle.
return QdN / DdN;
} | /**
* 射线与三角形求交
* @param ro - 射线原点
* @param rd - 射线方向
* @param a - 三角形点
* @param b - 三角形点
* @param c - 三角形点
* @param backfaceCulling - 是否剔除背面
* @returns 交点参数或者 undefined
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/utility/hit-test-helper.ts#L137-L189 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | CompositionHitTest | function CompositionHitTest (composition: Composition, x: number, y: number): Region[] {
const regions = composition.hitTest(x, y, true);
const ray = composition.getHitTestRay(x, y);
if (regions.length <= 0) {
return [];
}
const o = ray.origin;
const d = ray.direction;
const nums = regions.map((region, index) => {
const p = region.position;
//const p = (region.hitPositions as vec3[]) [index];
const t: spec.vec3 = [0, 0, 0];
for (let i = 0; i < 3; i++) {
t[i] = (p.getElement(i) - o.getElement(i)) / d.getElement(i);
}
return [index, Math.max(...t)];
});
nums.sort(function (a, b) {
const a1 = a[1] >= 0 ? a[1] : (a[1] + 1000000000);
const b1 = b[1] >= 0 ? b[1] : (b[1] + 1000000000);
return a1 - b1;
});
return nums.map(val => {
return regions[val[0]];
});
} | /**
* 合成点击测试,支持获取多个交点,并按照远近排序
* @param composition - 合成
* @param x - 点击 x 坐标
* @param y - 点击 y 坐标
* @returns 点击信息列表
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/utility/hit-test-helper.ts#L198-L230 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ToggleItemBounding | function ToggleItemBounding (composition: Composition, itemId: string) {
composition.items?.forEach(item => {
if (item.type === VFX_ITEM_TYPE_3D) {
const meshComponent = item.getComponent(ModelMeshComponent);
if (meshComponent) {
const mesh = meshComponent.content;
if (item.id === itemId) {
mesh.visBoundingBox = true;
} else {
mesh.visBoundingBox = false;
}
}
}
});
} | /**
* 切换 3D Mesh 元素的包围盒显示标志
* @param composition - 合成
* @param itemId - 元素 id
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/utility/hit-test-helper.ts#L237-L253 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | WebGLHelper.createTexture2D | static async createTexture2D (engine: Engine, image: GLTFImage, texture: GLTFTexture, isBaseColor?: boolean, tiny3dMode?: boolean): Promise<Texture> {
if (image.imageData === undefined) {
console.error(`createTexture2D: Invalid image data from ${image}.`);
// 这里不应该发生的,做个兜底
return Texture.create(engine, {
name: 'createTexture2D',
sourceType: TextureSourceType.data,
data: {
data: new Uint8Array([255, 255, 255, 255]),
width: 1,
height: 1,
},
});
}
const blob = new Blob([image.imageData], { type: image.mimeType });
const urlCreator = window.URL || window.webkitURL;
const imageUrl = urlCreator.createObjectURL(blob);
const imageObj = new Image();
imageObj.src = imageUrl;
return new Promise(function (resolve, reject) {
imageObj.onload = () => {
let minFilter: number = texture.minFilter ?? glContext.LINEAR_MIPMAP_LINEAR;
let premultiplyAlpha = false;
if (tiny3dMode) {
//if (minFilter === glContext.NEAREST_MIPMAP_LINEAR
// || minFilter === glContext.LINEAR_MIPMAP_NEAREST) {
minFilter = glContext.LINEAR_MIPMAP_LINEAR;
//}
if (!WebGLHelper.isPow2(imageObj.width) || !WebGLHelper.isPow2(imageObj.height)) {
minFilter = glContext.LINEAR;
}
//
premultiplyAlpha = isBaseColor ? false : true;
}
let generateMipmap = false;
if (minFilter == glContext.NEAREST_MIPMAP_NEAREST ||
minFilter == glContext.LINEAR_MIPMAP_NEAREST ||
minFilter == glContext.NEAREST_MIPMAP_LINEAR ||
minFilter == glContext.LINEAR_MIPMAP_LINEAR) {
generateMipmap = true;
}
const res = Texture.create(engine, {
name: 'createTexture2D',
wrapS: texture.wrapS ?? glContext.REPEAT,
wrapT: texture.wrapT ?? glContext.REPEAT,
magFilter: texture.magFilter ?? glContext.LINEAR,
minFilter,
anisotropic: 1,
//flipY: tex.flipY,
premultiplyAlpha,
sourceType: TextureSourceType.image,
image: imageObj,
generateMipmap,
});
resolve(res);
urlCreator.revokeObjectURL(imageUrl);
};
imageObj.onerror = reject;
});
} | /**
* 创建二维纹理对象
* @param engine - 引擎
* @param image - glTF 图像参数
* @param texture - glTF 纹理参数
* @param isBaseColor - 是否基础颜色
* @param tiny3dMode - 是否 Tiny3d 模式
* @returns 二维纹理对象
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/plugin-packages/model/src/utility/plugin-helper.ts#L96-L163 | 20512f4406e62c400b2b4255576cfa628db74a22 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.