Skip to content

Commit

Permalink
[feat] 修复新增 shader node 连线报错以及清理 block 与 menu 缓存
Browse files Browse the repository at this point in the history
修复新增 shader node 连线报错以及清理 block 与 menu 缓存
  • Loading branch information
wuzhiming authored Sep 19, 2024
2 parents 656ef49 + 2f4ed45 commit e66e1a7
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions extensions/shader-graph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@types/fs-extra": "^9.0.5",
"@types/node": "^16.0.1",
"adm-zip": "^0.5.10",
"globby": "^8.0.2",
"less": "^4.2.0",
"ts-node": "^10.9.1",
"tslib": "^2.5.3",
Expand Down
4 changes: 4 additions & 0 deletions extensions/shader-graph/src/block-forge/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ export function removeDeclareBlock(type: string) {
// @ts-ignore
window.removeDeclareBlock = removeDeclareBlock;

export function removeAllDeclareBlock() {
blockMap.clear();
}

/**
* 注册一个 block 类型
* @param block
Expand Down
1 change: 1 addition & 0 deletions extensions/shader-graph/src/block-forge/forge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ export class HTMLGraphForgeElement extends HTMLElement {

const $svg = $graph.shadowRoot.querySelector('#lines')!;
function searchG(htmlArray: (HTMLElement | SVGGElement)[]) {
if (!htmlArray) return;
const length = Math.min(htmlArray.length, 4);
for (let i = 0; i < length; i++) {
const $elem = htmlArray[i];
Expand Down
1 change: 1 addition & 0 deletions extensions/shader-graph/src/block-forge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export {
hasDeclareBlock,
getDeclareBlock,
removeDeclareBlock,
removeAllDeclareBlock,
} from './block';

export {
Expand Down
7 changes: 7 additions & 0 deletions extensions/shader-graph/src/contributions/scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ function createSlot(slot: SlotDefine) {
}

exports.methods = {
/**
* 注册后需要让场景进程同步一下节点数据
*/
afterDeclared() {
shaderGraph.reset();
},

async queryShaderNode() {
const { shaderNodeMap, shaderPropertyMap } = await Editor.Module.importProjectModule('db://shader-graph/graph/index.ts') as IModuleOptions;

Expand Down
5 changes: 5 additions & 0 deletions extensions/shader-graph/src/importer/shader-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export class ShaderGraph {
public cacheSourceMap: Map<string, string> = new Map();

_initedGraph = false;

reset() {
this._initedGraph = false;
}

async initGraph() {
if (this._initedGraph && this.shaderContext?.shaderTemplatesDir) {
return;
Expand Down
3 changes: 2 additions & 1 deletion extensions/shader-graph/src/shader-graph/declare/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { BlockTemplateData } from '../internal';
import type { BlockData, IBlockDescription, IPinDescription, PinData } from '../../block-forge/interface';
import type { PropertyDefine, NodeDefine, SlotDefine } from '../../../@types/shader-node-type';

import { declareBlock, declareEnum, declareDynamicEnumToType } from '../../block-forge';
import { declareBlock, declareEnum, declareDynamicEnumToType, removeAllDeclareBlock } from '../../block-forge';
import { generatePinID } from '../utils';

type SlotTag = 'input' | 'out' | 'prop';
Expand Down Expand Up @@ -171,6 +171,7 @@ export function declareShaderNodeBlock(shaderNodeMap: Map<string, NodeDefine>) {
// 清空缓存
normalBlockCacheMap.clear();
pinMap.clear();
removeAllDeclareBlock();
for (const [blockType, item] of shaderNodeMap) {
const inputPins: PinData[] = [];
const inputPinDescriptions: IPinDescription[] = [];
Expand Down
1 change: 1 addition & 0 deletions extensions/shader-graph/src/shader-graph/declare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async function declareGraphBlock() {
applyBlockToMenu();

MessageMgr.Instance.send(MessageType.Declared);
MessageMgr.Instance.callSceneMethod('afterDeclared');
}

function iteratePropertyDefines(handle: (define: PropertyDefine) => void) {
Expand Down

0 comments on commit e66e1a7

Please sign in to comment.