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 | TextComponentBase.setTextBaseline | setTextBaseline (value: spec.TextBaseline): void {
if (this.textLayout.textBaseline === value) {
return;
}
this.textLayout.textBaseline = value;
this.isDirty = true;
} | /**
* 设置文本垂直布局
* @param value - 布局选项
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/text/text-item.ts#L278-L284 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | TextComponentBase.setTextColor | setTextColor (value: spec.RGBAColorValue): void {
if (this.textStyle.textColor === value) {
return;
}
this.textStyle.textColor = value;
this.isDirty = true;
} | /**
* 设置文本颜色
* @param value - 颜色内容
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/text/text-item.ts#L291-L297 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | TextComponentBase.setFontFamily | setFontFamily (value: string): void {
if (this.textStyle.fontFamily === value && !isValidFontFamily(value)) {
console.warn('The font is either the current font or an risky font family.');
return;
}
this.textStyle.fontFamily = value;
this.isDirty = true;
} | /**
* 设置文本字体
* @param value - 文本字体
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/text/text-item.ts#L304-L312 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | TextComponentBase.setOutlineColor | setOutlineColor (value: spec.RGBAColorValue): void {
if (this.textStyle.outlineColor === value) {
return;
}
this.textStyle.outlineColor = value;
this.isDirty = true;
} | /**
* 设置外描边文本颜色
* @param value - 颜色内容
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/text/text-item.ts#L319-L325 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | TextComponentBase.setOutlineWidth | setOutlineWidth (value: number): void {
if (this.textStyle.outlineWidth === value) {
return;
}
this.textStyle.outlineWidth = value;
this.isDirty = true;
} | /**
* 设置外描边文本宽度
* @param value - 外描边宽度
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/text/text-item.ts#L332-L338 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | TextComponentBase.setShadowBlur | setShadowBlur (value: number): void {
if (this.textStyle.shadowBlur === value) {
return;
}
this.textStyle.shadowBlur = value;
this.isDirty = true;
} | /**
* 设置阴影模糊
* @param value - 阴影模糊强度
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/text/text-item.ts#L345-L351 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | TextComponentBase.setShadowColor | setShadowColor (value: spec.RGBAColorValue): void {
if (this.textStyle.shadowColor === value) {
return;
}
this.textStyle.shadowColor = value;
this.isDirty = true;
} | /**
* 设置阴影颜色
* @param value - 阴影颜色
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/text/text-item.ts#L358-L364 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | TextComponentBase.setShadowOffsetX | setShadowOffsetX (value: number): void {
if (this.textStyle.shadowOffsetX === value) {
return;
}
this.textStyle.shadowOffsetX = value;
this.isDirty = true;
} | /**
* 设置阴影水平偏移距离
* @param value - 水平偏移距离
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/text/text-item.ts#L371-L377 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | TextComponentBase.setShadowOffsetY | setShadowOffsetY (value: number): void {
if (this.textStyle.shadowOffsetY === value) {
return;
}
this.textStyle.shadowOffsetY = value;
this.isDirty = true;
} | /**
* 设置阴影水平偏移距离
* @param value - 水平偏移距离
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/text/text-item.ts#L384-L390 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | TextComponentBase.setFontScale | setFontScale (value: number): void {
if (this.textStyle.fontScale === value) {
return;
}
this.textStyle.fontScale = value;
this.isDirty = true;
} | /**
* 设置字体清晰度
* @param value - 字体清晰度
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/text/text-item.ts#L397-L404 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | TextComponentBase.setAutoWidth | setAutoWidth (value: boolean): void {
if (this.textLayout.autoWidth === value) {
return;
}
this.textLayout.autoWidth = value;
this.isDirty = true;
} | /**
* 设置自适应宽高开关
* @param value - 是否自适应宽高开关
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/text/text-item.ts#L411-L418 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | TextComponentBase.updateTexture | updateTexture (flipY = true) {
if (!this.isDirty || !this.context || !this.canvas) {
return;
}
const context = this.context;
const style = this.textStyle;
const layout = this.textLayout;
const fontScale = style.fontScale;
const width = (layout.width + style.fontOffset) * fontScale;
const finalHeight = layout.lineHeight * this.lineCount;
const fontSize = style.fontSize * fontScale;
const lineHeight = layout.lineHeight * fontScale;
this.char = (this.text || '').split('');
this.canvas.width = width;
if (layout.autoWidth) {
this.canvas.height = finalHeight * fontScale;
this.item.transform.size.set(1, finalHeight / layout.height);
} else {
this.canvas.height = layout.height * fontScale;
}
const height = this.canvas.height;
context.clearRect(0, 0, width, height);
// fix bug 1/255
context.fillStyle = 'rgba(255, 255, 255, 0.0039)';
if (!flipY) {
context.translate(0, height);
context.scale(1, -1);
}
context.fillRect(0, 0, width, height);
style.fontDesc = this.getFontDesc();
context.font = style.fontDesc;
if (style.hasShadow) {
this.setupShadow();
}
if (style.isOutlined) {
this.setupOutline();
}
// 文本颜色
context.fillStyle = `rgba(${style.textColor[0]}, ${style.textColor[1]}, ${style.textColor[2]}, ${style.textColor[3]})`;
const charsInfo: CharInfo[] = [];
let x = 0;
let y = layout.getOffsetY(style, this.lineCount, lineHeight, fontSize);
let charsArray = [];
let charOffsetX = [];
for (let i = 0; i < this.char.length; i++) {
const str = this.char[i];
const textMetrics = context.measureText(str);
// 和浏览器行为保持一致
x += layout.letterSpace * fontScale;
if (((x + textMetrics.width) > width && i > 0) || str === '\n') {
charsInfo.push({
y,
width: x,
chars: charsArray,
charOffsetX,
});
x = 0;
y += lineHeight;
charsArray = [];
charOffsetX = [];
}
if (str !== '\n') {
charsArray.push(str);
charOffsetX.push(x);
x += textMetrics.width;
}
}
charsInfo.push({
y,
width: x,
chars: charsArray,
charOffsetX,
});
charsInfo.forEach(charInfo => {
const x = layout.getOffsetX(style, charInfo.width);
charInfo.chars.forEach((str, i) => {
if (style.isOutlined) {
context.strokeText(str, x + charInfo.charOffsetX[i], charInfo.y);
}
context.fillText(str, x + charInfo.charOffsetX[i], charInfo.y);
});
});
if (style.hasShadow) {
context.shadowColor = 'transparent';
}
//与 toDataURL() 两种方式都需要像素读取操作
const imageData = context.getImageData(0, 0, this.canvas.width, this.canvas.height);
const texture = Texture.createWithData(
this.engine,
{
data: new Uint8Array(imageData.data),
width: imageData.width,
height: imageData.height,
},
{
flipY,
magFilter: glContext.LINEAR,
minFilter: glContext.LINEAR,
wrapS: glContext.CLAMP_TO_EDGE,
wrapT: glContext.CLAMP_TO_EDGE,
},
);
this.renderer.texture = texture;
this.material.setTexture('_MainTex', texture);
this.isDirty = false;
} | /**
* 更新文本
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/text/text-item.ts#L424-L554 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | TextLayout.getOffsetY | getOffsetY (style: TextStyle, lineCount: number, lineHeight: number, fontSize: number) {
const { outlineWidth, fontScale } = style;
// /3 计算Y轴偏移量,以匹配编辑器行为
const offsetY = (lineHeight - fontSize) / 3;
// 计算基础偏移量
const baseOffset = fontSize + outlineWidth * fontScale;
const commonCalculation = lineHeight * (lineCount - 1);
let offsetResult = 0;
switch (this.textBaseline) {
case spec.TextBaseline.top:
offsetResult = baseOffset + offsetY;
break;
case spec.TextBaseline.middle:
offsetResult = (this.height * fontScale - commonCalculation + baseOffset) / 2;
break;
case spec.TextBaseline.bottom:
offsetResult = (this.height * fontScale - commonCalculation) - offsetY;
break;
default:
break;
}
return offsetResult;
} | /**
* 获取初始的行高偏移值
* @param style - 字体基础数据
* @param lineCount - 渲染行数
* @param lineHeight - 渲染时的字体行高
* @param fontSize - 渲染时的字体大小
* @returns - 行高偏移值
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/text/text-layout.ts#L51-L78 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | TextLayout.setSize | setSize (width: number, height: number) {
this.width = width;
this.height = height;
} | /**
* 设置文本框的宽度和高度
* @param width 文本框宽度
* @param height 文本框高度
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/text/text-layout.ts#L110-L113 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | TrackAsset.updateAnimatedObject | updateAnimatedObject () {
if (this.parent) {
this.boundObject = this.parent.boundObject;
}
} | /**
* 重写该方法以获取自定义对象绑定
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/timeline/track.ts#L61-L65 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | TrackAsset.createTrackMixer | createTrackMixer (graph: PlayableGraph): TrackMixerPlayable {
return new TrackMixerPlayable(graph);
} | /**
* 重写该方法以创建自定义混合器
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/timeline/track.ts#L70-L72 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | TimelineAsset.invalidate | private invalidate () {
this.cacheFlattenedTracks = null;
} | /**
* Invalidates the asset, called when tracks data changed
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/plugins/timeline/playable-assets/timeline-asset.ts#L60-L62 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | Mesh.setVisible | setVisible (visible: boolean) {
this.visible = visible;
} | /**
* 设置当前 Mesh 的可见性。
* @param visible - true:可见,false:不可见
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/mesh.ts#L88-L90 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | Mesh.getVisible | getVisible (): boolean {
return this.visible;
} | /**
* 获取当前 Mesh 的可见性。
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/mesh.ts#L94-L96 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | Mesh.firstGeometry | firstGeometry (): Geometry {
return this.geometry;
} | /**
* 获取当前 Mesh 的第一个 geometry。
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/mesh.ts#L115-L117 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | Mesh.setMaterial | setMaterial (material: Material, destroy?: MaterialDestroyOptions | DestroyOptions.keep) {
if (destroy !== DestroyOptions.keep) {
this.material.dispose(destroy);
}
this.material = material;
} | /**
* 设置当前 Mesh 的材质
* @param material - 要设置的材质
* @param destroy - 可选的材质销毁选项
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/mesh.ts#L124-L129 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | Mesh.dispose | override dispose (options?: MeshDestroyOptions) {
if (this.destroyed) {
//console.error('call mesh.destroy multiple times', this);
return;
}
if (options?.geometries !== DestroyOptions.keep) {
this.geometry.dispose();
}
const materialDestroyOption = options?.material;
if (materialDestroyOption !== DestroyOptions.keep) {
this.material.dispose(materialDestroyOption);
}
this.destroyed = true;
if (this.engine !== undefined) {
this.engine.removeMesh(this);
// @ts-expect-error
this.engine = undefined;
}
} | /**
* 销毁当前资源
* @param options - 可选的销毁选项
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/mesh.ts#L138-L159 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderFrame.addMeshToDefaultRenderPass | addMeshToDefaultRenderPass (mesh: RendererComponent) {
this.drawObjectPass.addMesh(mesh);
} | /**
* 根据 Mesh 优先级添加到 RenderPass
* @param mesh - 要添加的 Mesh 对象
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-frame.ts#L403-L405 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderFrame.removeMeshFromDefaultRenderPass | removeMeshFromDefaultRenderPass (mesh: RendererComponent) {
this.drawObjectPass.removeMesh(mesh);
} | /**
* 把 Mesh 从 RenderPass 中移除,
* 如果 renderPass 中没有 mesh,此 renderPass 会被删除
* @param mesh - 要删除的 Mesh 对象
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-frame.ts#L412-L414 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderFrame.dispose | dispose (options?: RenderFrameDestroyOptions) {
if (options?.semantics !== DestroyOptions.keep) {
this.semantics.dispose();
}
const pass = options?.passes ? options.passes : undefined;
if (pass !== DestroyOptions.keep) {
this._renderPasses.forEach(renderPass => {
renderPass.dispose(pass);
});
}
this.passTextureCache.dispose();
this._renderPasses.length = 0;
this.emptyTexture.dispose();
this.transparentTexture.dispose();
if (this.resource) {
this.resource.color_a.dispose();
this.resource.color_b.dispose();
this.resource.depthStencil?.texture?.dispose();
this.resource.finalCopyRP.dispose();
this.resource.resRP.dispose();
// @ts-expect-error
this.resource = null;
}
this.destroyed = true;
} | /**
* 销毁 RenderFrame
* @param options - 可以有选择销毁一些对象
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-frame.ts#L420-L445 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderFrame.resetRenderPassDefaultAttachment | resetRenderPassDefaultAttachment (renderPasses: RenderPass[], startIndex: number) {
let pre: Texture;
const { color_a, color_b } = this.resource;
for (let i = startIndex; i < renderPasses.length; i++) {
const rp = renderPasses[i];
let tex = rp.attachments[0]?.texture;
// @ts-expect-error
if (tex && pre === tex) {
const next = tex === color_a ? color_b : color_a;
rp.resetColorAttachments([next]);
//this.renderer.extension.resetColorAttachments?.(rp as GLRenderPass, [next as GLTexture]);
}
tex = rp.attachments[0]?.texture;
if (tex) {
pre = tex;
}
}
} | /**
* 重置 RenderPass ColorAttachment,解决 Framebuffer 即读又写的问题
* @param renderPasses - RenderPass 对象数组
* @param startIndex - 开始重置的索引
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-frame.ts#L452-L472 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderFrame.findMeshRenderPassIndex | findMeshRenderPassIndex (mesh: Mesh): number {
let index = -1;
this.renderPasses.every((rp, idx) => {
if (rp.name.startsWith(RENDER_PASS_NAME_PREFIX) && rp.meshes.includes(mesh)) {
index = idx;
return false;
}
return true;
});
return index;
} | /**
* 查找 Mesh 所在的 RenderPass 索引,没找到是-1
* @param mesh - 需要查找的 Mesh
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-frame.ts#L478-L492 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderFrame.setRenderPasses | setRenderPasses (passes: RenderPass[]) {
if (this.renderer !== undefined) {
passes.forEach(pass => (pass as unknown as RenderPass).initialize(this.renderer));
}
this._renderPasses = passes.slice();
} | /**
* 设置 RenderPass 数组,直接修改内部的 RenderPass 数组
* @param passes - RenderPass 数组
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-frame.ts#L553-L558 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderFrame.addRenderPass | addRenderPass (pass: RenderPass): void {
if (this.renderer !== undefined) {
pass.initialize(this.renderer);
}
this._renderPasses.push(pass);
} | /**
* 添加 RenderPass
* @param pass - 需要添加的 RenderPass
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-frame.ts#L564-L569 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderFrame.createResource | createResource () {
const engine = this.renderer.engine;
if (!this.resource) {
const { detail, level } = engine.gpuCapability;
const width = this.renderer.getWidth();
const height = this.renderer.getHeight();
const filter = level === 2 ? glContext.LINEAR : glContext.NEAREST;
const texA = Texture.create(
engine,
{
sourceType: TextureSourceType.framebuffer,
format: glContext.RGBA,
name: 'frame_a',
minFilter: filter,
magFilter: filter,
}
);
const texB = Texture.create(
engine,
{
sourceType: TextureSourceType.framebuffer,
format: glContext.RGBA,
data: {
width,
height,
},
minFilter: filter,
magFilter: filter,
name: 'frame_b',
}
);
const depthStencilType = detail.readableDepthStencilTextures && detail.writableFragDepth ?
RenderPassAttachmentStorageType.depth_24_stencil_8_texture :
RenderPassAttachmentStorageType.depth_stencil_opaque;
const resRP = new RenderPass(this.renderer, {
depthStencilAttachment: { storageType: depthStencilType },
attachments: [{ texture: texA }],
}).initialize(this.renderer);
const finalCopyRP = new FinalCopyRP(this.renderer, {
name: 'effects-final-copy',
priority: RenderPassPriorityNormal + 600,
clearAction: {
depthAction: TextureLoadAction.clear,
stencilAction: TextureLoadAction.clear,
colorAction: TextureLoadAction.clear,
},
meshOrder: OrderType.ascending,
meshes: [this.createCopyMesh({ blend: true, depthTexture: resRP.getDepthAttachment()?.texture })],
});
this.resource = {
color_a: resRP.attachments[0].texture,
color_b: texB,
finalCopyRP,
depthStencil: resRP.depthAttachment,
resRP,
};
}
} | /**
* 创建 RenderPass 切分时需要的 GPU 资源
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-frame.ts#L574-L634 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderFrame.createCopyMesh | createCopyMesh (semantics?: { tex?: string, size?: string, blend?: boolean, depthTexture?: Texture }): Mesh {
const name = EFFECTS_COPY_MESH_NAME;
const engine = this.renderer.engine;
const geometry = Geometry.create(
engine,
{
name,
mode: glContext.TRIANGLE_STRIP,
attributes: {
aPos: {
type: glContext.FLOAT,
size: 2,
data: new Float32Array([-1, 1, -1, -1, 1, 1, 1, -1]),
},
},
drawCount: 4,
});
const shader = createCopyShader(engine.gpuCapability.level, !!semantics?.depthTexture);
// FIXME: 如果不把shader添加进shaderLibrary,这里可以移到core中,有性能上的考虑
this.renderer.getShaderLibrary()?.addShader(shader);
const material = Material.create(
engine,
{
uniformValues: {
// @ts-expect-error
uDepth: semantics?.depthTexture,
},
name,
shader,
});
material.blending = false;
material.depthTest = false;
material.culling = false;
if (semantics?.blend) {
material.blending = true;
material.blendFunction = [glContext.SRC_ALPHA, glContext.ONE_MINUS_SRC_ALPHA, glContext.SRC_ALPHA, glContext.ONE_MINUS_SRC_ALPHA];
}
return Mesh.create(
engine,
{
name, geometry, material,
priority: 0,
},
);
} | /**
* 创建拷贝 RenderPass 用到的 Mesh 对象
* @param semantics - RenderPass 渲染时 Framebuffer 的颜色和深度纹理、大小和是否混合
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-frame.ts#L641-L690 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderFrame.removeRenderPass | removeRenderPass (pass: RenderPass): void {
removeItem(this._renderPasses, pass);
} | /**
* 移除 RenderPass
* @param pass - 需要移除的 RenderPass
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-frame.ts#L696-L698 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderPass.getInitAttachments | getInitAttachments () {
if (this.attachments.length > 0) {
return this.attachments;
} else {
return this.options.attachments;
}
} | /**
* 获取当前 Attachment 数组,注意 RenderPass 可能没有创建完成
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-pass.ts#L413-L419 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderPass.configure | configure (renderer: Renderer) {
if (this.framebuffer) {
renderer.setFramebuffer(this.framebuffer);
} else {
const [x, y, width, height] = this.getViewport();
renderer.setViewport(x, y, width, height);
}
} | /**
* 配置当前pass的RT,在每帧渲染前调用
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-pass.ts#L425-L433 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderPass.execute | execute (renderer: Renderer) {
renderer.clear(this.clearAction);
renderer.renderMeshes(this.meshes);
renderer.clear(this.storeAction);
} | /**
* 执行当前pass,每帧调用一次
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-pass.ts#L438-L442 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderPass.frameCleanup | frameCleanup (renderer: Renderer) {
} | /**
* 每帧所有的pass渲染完后调用,通常用于清空临时的RT资源
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-pass.ts#L447-L449 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderPass.resetColorAttachments | resetColorAttachments (colors: Texture[]) {
if (!colors.length) {
this.resetAttachments({ attachments: [] });
}
if (!this.attachments.length) {
this.resetAttachments({ attachments: colors.map(t => ({ texture: t })) });
} else {
const attachments = colors.map(texture => {
texture.updateSource({ sourceType: TextureSourceType.framebuffer });
return new RenderTargetHandle(this.renderer.engine, { texture });
});
this.attachments.forEach(att => !att.externalTexture && att.dispose());
this.attachments = attachments;
if (this.framebuffer) {
this.framebuffer.bind();
this.framebuffer.resetColorTextures(colors.map(color => color));
}
}
} | /**
* 重置 ColorAttachment 数组,会直接替换掉
* @param colors - 纹理数组,作为新的 ColorAttachment
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-pass.ts#L455-L475 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderPass.resetAttachments | resetAttachments (options: RenderPassAttachmentOptions) {
this.options = options;
this.setViewportOptions(options);
if (this.renderer) {
this._resetAttachments();
}
} | /**
* 重置所有 Attachment,会替换掉所有 Attachment
* @param options - Attachment 和视口数据
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-pass.ts#L481-L487 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderPass.getViewport | getViewport (): vec4 {
const ret = this.framebuffer?.viewport || this.customViewport;
if (ret) {
return ret;
}
const renderer = this.renderer;
const vs = this.viewportScale;
return renderer ? [0, 0, renderer.getWidth() * vs, renderer.getHeight() * vs] : [0, 0, 0, 0];
} | /**
* 获取当前视口大小,格式:[x偏移,y偏移,宽度,高度]
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-pass.ts#L563-L573 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderPass.getDepthAttachment | getDepthAttachment (): RenderPassDepthStencilAttachment | undefined {
const framebuffer = this.framebuffer;
if (framebuffer) {
const depthTexture = framebuffer.getDepthTexture();
const texture = depthTexture ? this.getDepthTexture(depthTexture, framebuffer.externalStorage) : undefined;
return {
storageType: framebuffer.depthStencilStorageType,
storage: framebuffer.depthStorage,
texture,
};
}
} | /**
* 获取深度 Attachment,可能没有
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-pass.ts#L578-L591 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderPass.getStencilAttachment | getStencilAttachment (): RenderPassDepthStencilAttachment | undefined {
const framebuffer = this.framebuffer;
if (framebuffer) {
const stencilTexture = framebuffer.getStencilTexture();
const texture = stencilTexture ? this.getDepthTexture(stencilTexture, framebuffer.externalStorage) : undefined;
return {
storageType: framebuffer.depthStencilStorageType,
storage: framebuffer.stencilStorage,
texture,
};
}
} | /**
* 获取蒙版 Attachment,可能没有
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-pass.ts#L596-L609 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderPass.initialize | initialize (renderer: Renderer): RenderPass {
if (!this.initialized) {
this._resetAttachments();
this.initialized = true;
}
return this;
} | // 生成并初始化帧缓冲 | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-pass.ts#L644-L651 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | RenderPass.dispose | dispose (options?: RenderPassDestroyOptions) {
if (this.destroyed) {
return;
}
const destroyMeshOption = options?.meshes || undefined;
if (destroyMeshOption !== DestroyOptions.keep) {
this.meshes.forEach(mesh => {
(mesh as Mesh).dispose(destroyMeshOption);
});
}
this.meshes.length = 0;
const colorOpt = options?.colorAttachment ? options.colorAttachment : RenderPassDestroyAttachmentType.force;
this.attachments.forEach(att => {
const keep = (att.externalTexture && colorOpt === RenderPassDestroyAttachmentType.keepExternal) || colorOpt === RenderPassDestroyAttachmentType.keep;
if (!keep) {
att.dispose();
}
});
this.attachments.length = 0;
if (options?.semantics !== DestroyOptions.keep) {
this.semantics.dispose();
}
this.destroyed = true;
const depthStencilOpt = options?.depthStencilAttachment ? options.depthStencilAttachment : RenderPassDestroyAttachmentType.force;
const fbo = this.framebuffer;
if (fbo) {
fbo.dispose({ depthStencilAttachment: depthStencilOpt });
const keep = (fbo.externalStorage && depthStencilOpt === RenderPassDestroyAttachmentType.keepExternal) || depthStencilOpt === RenderPassDestroyAttachmentType.keep;
if (!keep) {
this.stencilTexture?.dispose();
this.depthTexture?.dispose();
}
}
// @ts-expect-error safe to assign
this.options = this.renderer = null;
this.initialize = throwDestroyedError as unknown as (r: Renderer) => RenderPass;
} | /**
* 销毁 RenderPass
* @param options - 有选择销毁内部对象
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/render-pass.ts#L657-L701 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | Renderer.addLostHandler | addLostHandler (lostHandler: LostHandler) {
// OVERRIDE
} | /**
* 添加 webglcontextlost 事件回调
* @override
* @param lostHandler
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/renderer.ts#L88-L90 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | Renderer.addRestoreHandler | addRestoreHandler (restoreHandler: RestoreHandler) {
// OVERRIDE
} | /**
* 添加 webglContextrestored 事件的回调
* @override
* @param restoreHandler
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/renderer.ts#L97-L99 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | Renderer.lost | lost (e: Event): void {
// OVERRIDE
} | /**
* @override
* @param e
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/renderer.ts#L105-L107 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | Renderer.restore | restore (): void {
// OVERRIDE
} | /**
* @override
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/renderer.ts#L112-L114 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | Renderer.getShaderLibrary | getShaderLibrary (): ShaderLibrary | undefined {
// OVERRIDE
return undefined;
} | /**
*
* @override
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/render/renderer.ts#L121-L124 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ShaderFactory.genFinalShaderCode | static genFinalShaderCode (options: ShaderCodeOptions): string {
const { level, shaderType, shader, macros, removeVersion } = options;
const macroString = ShaderFactory.genMacroString(level, macros);
const versionString = ShaderFactory.genShaderVersion(level);
let source = ShaderFactory.parseIncludes(shader);
const isVersion300 = ShaderFactory.isVersion300(source);
source = ShaderFactory.removeWebGLVersion(source);
if (level === 2 && !isVersion300) {
source = ShaderFactory.convertTo300(source, shaderType === ShaderType.fragment);
}
if (removeVersion) {
return macroString + source;
}
return versionString + macroString + source;
} | /**
* 生成 shader,检测到 WebGL1 上下文会降级
* @param macros - 宏定义数组
* @param shader - 原始 shader 文本
* @param shaderType - shader 类型
* @return 去除版本号的 shader 文本
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/shader/shader-factory.ts#L40-L58 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ShaderFactory.convertTo300 | private static convertTo300 (source: string, isFragment?: boolean) {
source = source.replace(/\bvarying\b/g, isFragment ? 'in' : 'out');
source = source.replace(/\btexture(2D|Cube)\b/g, 'texture');
// Remove extensions
const regex = /#extension.+(GL_OES_standard_derivatives|GL_EXT_shader_texture_lod|GL_EXT_frag_depth|GL_EXT_draw_buffers).+(enable|require)/g;
source = source.replace(regex, '');
if (isFragment) {
source = source.replace(/\btexture(2D|Cube)LodEXT\b/g, 'textureLod');
source = source.replace(/\btexture(2D|Cube)GradEXT\b/g, 'textureGrad');
source = source.replace(/\bgl_FragDepthEXT\b/g, 'gl_FragDepth');
if (!ShaderFactory.has300Output(source)) {
const isMRT = /\bgl_FragData\[.+?\]/g.test(source);
if (isMRT) {
source = source.replace(/\bgl_FragColor\b/g, 'gl_FragData[0]');
const result = source.match(/\bgl_FragData\[.+?\]/g);
if (result) {
source = ShaderFactory.replaceMRTShader(source, result);
}
} else {
source = source.replace(/void\s+?main\s*\(/g, 'out vec4 glFragColor;\nvoid main(');
source = source.replace(/\bgl_FragColor\b/g, 'glFragColor');
}
}
} else {
source = source.replace(/\battribute\b/g, 'in');
}
return source;
} | /**
* Convert lower GLSL version to GLSL 300 es.
* @param source - code
* @param isFragment - Whether it is a fragment shader.
* */ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/shader/shader-factory.ts#L65-L98 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | hackEarcutLinked | function hackEarcutLinked (ear: Node, triangles: number[], dim: number, minX?: number, minY?: number, invSize?: number, pass?: number) {
if (!ear) {
return;
}
// interlink polygon nodes in z-order
if (!pass && invSize) {
indexCurve(ear, minX!, minY!, invSize);
}
let stop = ear, prev, next;
// iterate through ears, slicing them one by one
while (ear.prev !== ear.next) {
prev = ear.prev;
next = ear.next;
if (invSize ? isEarHashed(ear, minX!, minY!, invSize) : isEar(ear)) {
// cut off the triangle
triangles.push(prev.i / dim + indexBase);
triangles.push(ear.i / dim + indexBase);
triangles.push(next.i / dim + indexBase);
removeNode(ear);
// skipping the next vertex leads to less sliver triangles
ear = next.next;
stop = next.next;
continue;
}
ear = next;
// if we looped through the whole remaining polygon and can't find any more ears
if (ear === stop) {
// try filtering triangles and slicing again
if (!pass) {
hackEarcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
// if this didn't work, try curing all small self-intersections locally
} else if (pass === 1) {
ear = hackCureLocalIntersections(filterPoints(ear), triangles, dim);
hackEarcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
// as a last resort, try splitting the remaining polygon into two
} else if (pass === 2) {
hackSplitEarcut(ear, triangles, dim, minX, minY, invSize);
}
break;
}
}
} | // main ear slicing loop which triangulates a polygon (given as a linked list) | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/shape/earcut.ts#L58-L111 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | hackCureLocalIntersections | function hackCureLocalIntersections (start: Node, triangles: number[], dim: number) {
let p = start;
do {
const a = p.prev, b = p.next.next;
if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
triangles.push(a.i / dim + indexBase);
triangles.push(p.i / dim + indexBase);
triangles.push(b.i / dim + indexBase);
// remove two nodes involved
removeNode(p);
removeNode(p.next);
p = start = b;
}
p = p.next;
} while (p !== start);
return filterPoints(p);
} | // go through all polygon nodes and cure small local self-intersections | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/shape/earcut.ts#L114-L135 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | hackSplitEarcut | function hackSplitEarcut (start: Node, triangles: number[], dim: number, minX?: number, minY?: number, invSize?: number) {
// look for a valid diagonal that divides the polygon into two
let a = start;
do {
let b = a.next.next;
while (b !== a.prev) {
if (a.i !== b.i && isValidDiagonal(a, b)) {
// split the polygon in two by the diagonal
let c = splitPolygon(a, b);
// filter colinear triangles around the cuts
a = filterPoints(a, a.next);
c = filterPoints(c, c.next);
// run earcut on each half
hackEarcutLinked(a, triangles, dim, minX, minY, invSize);
hackEarcutLinked(c, triangles, dim, minX, minY, invSize);
return;
}
b = b.next;
}
a = a.next;
} while (a !== start);
} | // try splitting polygon into two and triangulate them independently | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/shape/earcut.ts#L138-L164 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | getGeometriesByShapeData | function getGeometriesByShapeData (shape: ShapeGeometryData) {
const geometries: spec.ShapeGeometry[] = [];
// 该版本的单个形状数据可以包含多个形状,可以加个埋点,五福之后没有就可以下掉
if ('gs' in shape) {
shape.gs.forEach(gs => {
geometries.push({
p: [spec.ValueType.SHAPE_POINTS, gs.p],
s: [spec.ValueType.SHAPE_SPLITS, gs.s],
});
});
} else if ('g' in shape) {
geometries.push({
p: [spec.ValueType.SHAPE_POINTS, shape.g.p],
s: [spec.ValueType.SHAPE_SPLITS, shape.g.s],
});
} else {
geometries.push(shape);
}
return geometries;
} | /**
* 根据新老版形状数据获取形状几何数据
* @param shape 新老版形状数据
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/shape/geometry.ts#L98-L119 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | info | function info (message: string, ...args: any[]) {
console.debug(...format(message));
localLogger?.('info', message, args);
} | /**
* info 会转换成浏览器的 console.debug
* @param message
* @param args
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/utils/logger.ts#L26-L29 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | register | function register (fn: (type: LogType, message: string, ...args: any[]) => void) {
if (fn && isFunction(fn)) {
localLogger = fn;
}
} | /**
* 注册自定义埋点函数
*
* @param fn
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-core/src/utils/logger.ts#L41-L45 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeComposition.getRendererOptions | override getRendererOptions (): MeshRendererOptions {
const emptyTexture = ThreeTexture.createWithData(
this.renderer.engine,
{
data: new Uint8Array(4).fill(255),
width: 1,
height: 1,
});
(emptyTexture as ThreeTexture).texture.needsUpdate = true;
if (!this.rendererOptions) {
this.rendererOptions = {
emptyTexture,
cachePrefix: '-',
};
}
return this.rendererOptions;
} | /**
* 获取 render 参数
*
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-composition.ts#L99-L117 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeDisplayObject.constructor | constructor (
context: WebGLRenderingContext | WebGL2RenderingContext,
options: ThreeDisplayObjectOptions,
) {
super();
const { width, height, camera } = options;
this.renderer = new ThreeRenderer(context);
this.width = width;
this.height = height;
this.camera = camera;
} | /**
*
* @param context
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-display-object.ts#L47-L59 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeDisplayObject.currentComposition | get currentComposition () {
return this.compositions[0];
} | /**
* 获取当前播放合成,如果是多个合成同时播放,返回第一个合成
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-display-object.ts#L63-L65 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeDisplayObject.update | update (delta: number) {
this.compositions.forEach(composition => {
composition.update(delta);
});
} | /**
*
* @param delta
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-display-object.ts#L189-L193 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.constructor | constructor (engine: Engine, props?: GeometryProps) {
super(engine);
if (!props) {
return;
}
const {
drawStart = 0, drawCount, indices, mode,
name = `effectsGeometry:${seed++}`,
} = props;
this.name = name;
this.mode = mode ?? glContext.TRIANGLES;
const attributesName: string[] = [];
const attributes: Record<string, ThreeAttributeWithType> = {};
const geometry = new THREE.BufferGeometry();
Object.keys(props.attributes).forEach(name => {
const attr = props.attributes[name];
if (!('dataSource' in attr)) {
this.setAttributeType(name, attr, geometry, attributes, props.maxVertex);
} else {
// 使用AttributeWithType构造的attribute
const { dataSource } = attr as spec.AttributeWithType;
if (dataSource) {
if (attributes[dataSource] === undefined) {
this.setAttributeType(dataSource, attr, geometry, attributes, props.maxVertex);
}
const { size, offset, normalize } = attr;
const dataSourceAttribute = attributes[dataSource];
const buffer = dataSourceAttribute.buffer;
const dataLength = dataSourceAttribute.dataLength;
const attribute = new THREE.InterleavedBufferAttribute(buffer, size, (offset ?? 0) / dataLength, normalize);
geometry.setAttribute(name, attribute);
attributes[name] = {
buffer,
attribute,
type: dataSourceAttribute.type,
dataLength,
};
}
}
attributesName.push(name);
});
if (indices && indices.data) {
geometry.setIndex(new THREE.BufferAttribute(indices.data, 1));
}
this.geometry = geometry;
this.attributes = attributes;
this.attributesName = attributesName;
this.drawStart = drawStart;
this.drawCount = drawCount ?? 0;
} | /**
* 构造函数
* @param props - geometry 创建参数
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L53-L113 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.drawCount | get drawCount (): number {
return this.geometry.drawRange.count;
} | /**
* 获取绘制数量
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L118-L120 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.drawCount | set drawCount (val: number) {
this.geometry.drawRange.count = val;
} | /**
* 设置绘制数量
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L125-L127 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.drawStart | get drawStart (): number {
return this.geometry.drawRange.start;
} | /**
* 获取绘制起点
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L132-L134 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.drawStart | set drawStart (val: number) {
this.geometry.drawRange.start = val;
} | /**
* 设置绘制起点
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L139-L141 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.getAttributeData | getAttributeData (name: string): spec.TypedArray | undefined {
if (this.attributes[name] == undefined) {
return;
}
return this.attributes[name].buffer.array as spec.TypedArray;
} | /**
* 获取 attribute 数据
*
* @param name - attribute 名称
* @returns 返回 attribute 数据,如果为空返回 undefined
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L149-L155 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.setAttributeData | setAttributeData (name: string, data: spec.TypedArray): void {
if (this.attributes[name] == undefined) {
return;
}
let attributeBuffer = this.attributes[name].buffer;
if (data.length > attributeBuffer.array.length) {
const buffer = new THREE.InterleavedBuffer(data, attributeBuffer.stride);
attributeBuffer = this.attributes[name].attribute.data = buffer;
this.attributes[name].buffer = buffer;
this.geometry.setAttribute(name, this.attributes[name].attribute);
} else {
attributeBuffer.set(data, 0);
attributeBuffer.updateRange.count = data.length;
attributeBuffer.updateRange.offset = 0;
}
this.geometry.attributes[name].needsUpdate = true;
} | /**
* 设置 attribute 数据
*
* @param name - attribute 名称
* @param data - attribute 数据
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L164-L184 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.setAttributeSubData | setAttributeSubData (name: string, dataOffset: number, data: spec.TypedArray): void {
if (this.attributes[name] == undefined) {
return;
}
const attributeBuffer = this.attributes[name].buffer;
attributeBuffer.set(data, dataOffset);
this.geometry.attributes[name].needsUpdate = true;
} | /**
* 设置可变的 attribute 数据
*
* @param name - attribute 名称
* @param dataOffset - 数据偏移
* @param data - 数据内容
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L194-L204 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.getAttributeStride | getAttributeStride (name: string): number {
const attribute = this.attributes[name];
return attribute.buffer.stride * BYTES_TYPE_MAP[attribute.type];
} | /**
* 获取 attribute 数据步长
*
* @param name - attribute名称
* @returns 返回步长值
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L212-L216 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.getAttributeNames | getAttributeNames (): string[] {
return this.attributesName;
} | /**
* 获取用到的所有 attribute 名称
* @returns 返回名称数组
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L222-L224 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.getIndexData | getIndexData (): spec.TypedArray | undefined {
const index = this.geometry.getIndex();
return index === null ? undefined : index.array as spec.TypedArray;
} | /**
* 获取 index attribute 数据
* @returns 返回数据,如果为空返回 undefined
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L230-L234 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.setIndexData | setIndexData (data?: spec.TypedArray): void {
if (data) {
this.geometry.setIndex(new THREE.BufferAttribute(data, 1));
this.geometry.index!.needsUpdate = true;
}
} | /**
* 设置 index attribute 数据
*
* @param data - index 数据
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L241-L246 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.setIndexSubData | setIndexSubData (offset: number, data: spec.TypedArray): void {
const index = this.geometry.getIndex();
if (index !== null) {
const start = offset;
const length = offset + data.length;
const array = index.count;
if (array < length) {
// @ts-expect-error safe to use
const newData = new data.constructor(end);
newData.set(index.array);
index.array = newData;
}
//@ts-expect-error
index.array.set(data, start);
this.geometry.index!.needsUpdate = true;
}
} | /**
* 设置偏移 index 数据
*
* @param offset - 数据偏移量
* @param data - 数据内容
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L254-L274 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.setDrawStart | setDrawStart (start: number): void {
this.drawStart = start;
} | /**
* 设置绘制偏移
*
* @param start - 绘制偏移
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L281-L283 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.getDrawStart | getDrawStart (): number {
return this.drawStart;
} | /**
* 获取绘制偏移
*
* @returns 返回绘制移
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L290-L292 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.setDrawCount | setDrawCount (count: number): void {
this.drawCount = count;
} | /**
* 设置绘制数量
*
* @param count - 绘制数量
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L299-L301 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.getDrawCount | getDrawCount (): number {
return this.drawCount;
} | /**
* 获取绘制数量
*
* @returns 返回绘制数量
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L308-L310 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.getSkinProps | getSkinProps (): SkinProps {
return {};
} | /**
* 获取蒙皮数据
*
* @returns 返回蒙皮数据
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L317-L319 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeGeometry.dispose | override dispose (): void {
if (this.destroyed) {
return;
}
this.geometry.dispose();
this.destroyed = true;
} | /**
* 销毁方法
*
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-geometry.ts#L326-L332 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeMesh.constructor | constructor (engine: Engine, props?: GeometryMeshProps) {
if (!props) {
return;
}
const {
material, geometry,
priority = 0,
} = props;
super(engine, props);
this.geometry = geometry;
this.material = material;
if ((geometry as ThreeGeometry).mode === glContext.LINES) {
this.mesh = new THREE.LineSegments(
(geometry as ThreeGeometry).geometry,
(material as ThreeMaterial).material);
} else {
this.mesh = new THREE.Mesh(
(geometry as ThreeGeometry).geometry,
(material as ThreeMaterial).material
);
}
// 在抽象Mesh设置priority时,THREE 的 Mesh 还未创建
this.priority = priority;
} | /**
* 构造函数
* @param props - mesh 创建参数
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-mesh.ts#L24-L51 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeMesh.priority | override set priority (v: number) {
if (this.mesh) {
this.mesh.renderOrder = v;
}
} | /**
* 设置 mesh 的渲染顺序
*
* @param v - 顺序 index
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-mesh.ts#L58-L62 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeMesh.priority | override get priority () {
return this.mesh.renderOrder;
} | /**
* 获取 mesh 的渲染顺序
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-mesh.ts#L67-L69 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeMesh.setVisible | override setVisible (val: boolean): void {
this.mesh.visible = val;
} | /**
* 设置 mesh 可见性
*
* @param val - 可见性开关
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-mesh.ts#L76-L78 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeMesh.getVisible | override getVisible (): boolean {
return this.mesh.visible;
} | /**
* 获取 mesh 的可见性
*
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-mesh.ts#L85-L87 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeMesh.firstGeometry | override firstGeometry (): Geometry {
return this.geometry;
} | /**
* 获取 mesh 中的首个 geometry
*
* @returns 返回 geometry 对象
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-mesh.ts#L94-L96 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeMesh.setMaterial | override setMaterial (mtl: Material, destroy?: MaterialDestroyOptions | DestroyOptions.keep): void {
// TODO: 这里可以放到抽象类里
if (destroy !== DestroyOptions.keep) {
this.material.dispose(destroy);
}
this.material = mtl;
this.mesh.material = (mtl as ThreeMaterial).material;
} | /**
* 设置 material
*
* @param mtl - material 对象
* @param destroy 销毁参数
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-mesh.ts#L104-L111 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeMesh.restore | override restore (): void {
} | /**
* 重建方法
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-mesh.ts#L121-L122 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeMesh.dispose | override dispose (options?: MeshDestroyOptions): void {
if (!this.destroyed) {
this.mesh.clear();
this.destroyed = true;
}
} | /**
* 销毁方法
*
* @param options - 销毁参数
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-mesh.ts#L140-L145 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeRenderPass.constructor | constructor (renderer: any, options: RenderPassOptions) {
super(renderer, options);
} | /**
* 构造函数
* @param options - 设置 RenderPass 的参数选项
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-render-pass.ts#L17-L19 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeRenderPass.resetColorAttachments | override resetColorAttachments (colors: Texture[]) {
} | /**
* 重置颜色附件
* @param colors - 颜色附件数组
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-render-pass.ts#L25-L27 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeRenderPass.resetAttachments | override resetAttachments (options: RenderPassAttachmentOptions) {
} | /**
* 重置所有附件
* @param options - 返回渲染目标附件的选项
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-render-pass.ts#L33-L35 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeRenderPass.getViewport | override getViewport (): spec.vec4 {
return [0, 0, 0, 0];
} | /**
* 获取视口
* @returns vec4 类型的值,表示视口的左上角 x 和 y 坐标以及宽度和高度
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-render-pass.ts#L41-L43 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeRenderPass.getDepthAttachment | override getDepthAttachment (): RenderPassDepthStencilAttachment | undefined {
return;
} | /**
* 获取深度附件
* @returns 返回深度附件信息
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-render-pass.ts#L49-L51 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeRenderPass.getStencilAttachment | override getStencilAttachment (): RenderPassDepthStencilAttachment | undefined {
return;
} | /**
* 获取模板附件
* @returns 返回模板附件信息
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-render-pass.ts#L57-L59 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeRenderPass.dispose | override dispose (options?: RenderPassDestroyOptions) {
} | /**
* 销毁渲染目标及其所有附件
* @param options - 销毁渲染目标的选项
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-render-pass.ts#L65-L67 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeSpriteComponent.priority | override set priority (v: number) {
if (this.threeMesh) {
this.threeMesh.renderOrder = v;
}
} | /**
* 设置 mesh 的渲染顺序
*
* @param v - 顺序 index
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-sprite-component.ts#L16-L20 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeSpriteComponent.priority | override get priority () {
return this.threeMesh.renderOrder;
} | /**
* 获取 mesh 的渲染顺序
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-sprite-component.ts#L25-L27 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeSpriteComponent.setVisible | override setVisible (val: boolean): void {
this.threeMesh.visible = val;
} | /**
* TODO: 待移除
* 设置 mesh 可见性
*
* @param val - 可见性开关
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-sprite-component.ts#L35-L37 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeSpriteComponent.getVisible | override getVisible (): boolean {
return this.threeMesh.visible;
} | /**
* TODO: 待移除
* 获取 mesh 的可见性
*
* @returns
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-sprite-component.ts#L45-L47 | 20512f4406e62c400b2b4255576cfa628db74a22 |
effects-runtime | github_2023 | galacean | typescript | ThreeSpriteComponent.dispose | override dispose (): void {
super.dispose();
if (!this.isActiveAndEnabled) {
this.threeMesh.clear();
}
} | /**
* 销毁方法
*
*/ | https://github.com/galacean/effects-runtime/blob/20512f4406e62c400b2b4255576cfa628db74a22/packages/effects-threejs/src/three-sprite-component.ts#L63-L68 | 20512f4406e62c400b2b4255576cfa628db74a22 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.