GraphPage : Edited mesh is now a child of the connected mesh

This commit is contained in:
Bruno Fargnoli 2026-06-06 11:28:49 +02:00
parent bb8d5f882c
commit 7255c71460
5 changed files with 59 additions and 20 deletions

View file

@ -2072,9 +2072,11 @@ async function saveGeneratedMeshAssets({
provider = 'API',
prompt = '',
metadata = {},
downloadedFiles = []
downloadedFiles = [],
parentAssetId = null
} = {}) {
const savedAssets = [];
const normalizedParentAssetId = Number(parentAssetId) || null;
for (const [index, downloadedFile] of downloadedFiles.entries()) {
const extension = path.extname(downloadedFile.filename).replace('.', '') || getExtensionFromContentType(downloadedFile.contentType, 'glb');
@ -2085,8 +2087,7 @@ async function saveGeneratedMeshAssets({
await fs.mkdir(path.dirname(absoluteFilePath), { recursive: true });
await fs.writeFile(absoluteFilePath, downloadedFile.buffer);
savedAssets.push(await createProjectAsset({
projectId: Number(projectId),
const assetPayload = {
type: 'mesh',
name: downloadedFiles.length > 1 ? `${name} ${index + 1}` : name,
filePath: storedFilePath,
@ -2101,7 +2102,13 @@ async function saveGeneratedMeshAssets({
...metadata
},
createdAt: Date.now() + index
}));
};
// When the mesh was edited from a connected mesh, save it as a version (child)
// of that mesh instead of creating a new root asset.
savedAssets.push(normalizedParentAssetId
? await createAssetVersion({ assetId: normalizedParentAssetId, ...assetPayload })
: await createProjectAsset({ projectId: Number(projectId), ...assetPayload }));
}
return savedAssets;
@ -2838,10 +2845,11 @@ app.post('/api/comfyui/workflows/run', workflowExecutionUpload.any(), async (req
let executionPromptId = null;
try {
const { projectId, workflowId, cardId, name } = req.body;
const { projectId, workflowId, cardId, name, parentAssetId } = req.body;
const normalizedProjectId = Number(projectId);
const hasProjectId = Number.isFinite(normalizedProjectId) && normalizedProjectId > 0;
const trimmedName = String(name || '').trim();
const normalizedParentAssetId = Number(parentAssetId) || null;
const inputValues = JSON.parse(req.body.inputValues || '{}');
const persistProcessingCard = String(req.body.persistProcessingCard || '').toLowerCase() !== 'false';
const persistGeneratedAssets = String(req.body.persistGeneratedAssets || '').toLowerCase() !== 'false';
@ -3058,7 +3066,11 @@ app.post('/api/comfyui/workflows/run', workflowExecutionUpload.any(), async (req
await fs.mkdir(path.dirname(absoluteFilePath), { recursive: true });
await fs.writeFile(absoluteFilePath, downloadedFile.buffer);
const persistedAsset = await createProjectAsset(generatedAssetPayload);
// When a mesh output was edited from a connected mesh, store it as a
// version (child) of that mesh instead of creating a new root asset.
const persistedAsset = (normalizedParentAssetId && inferredAssetType === 'mesh')
? await createAssetVersion({ assetId: normalizedParentAssetId, ...generatedAssetPayload })
: await createProjectAsset(generatedAssetPayload);
generatedAssets.push({
...persistedAsset,
url: `http://localhost:${PORT}/assets/${encodeURI(toAssetUrlPath(storedFilePath))}`,
@ -3148,8 +3160,10 @@ app.post('/api/meshes/generate', async (req, res) => {
enablePBR,
faceCount,
generationType,
polygonType
polygonType,
parentAssetId
} = req.body;
const normalizedParentAssetId = Number(parentAssetId) || null;
const trimmedName = String(name || '').trim();
const trimmedPrompt = String(prompt || '').trim();
const isTencentMeshApi = isTencentMeshGenerationApi(selectedApi);
@ -3447,8 +3461,7 @@ app.post('/api/meshes/generate', async (req, res) => {
await fs.mkdir(path.dirname(absoluteFilePath), { recursive: true });
await fs.writeFile(absoluteFilePath, meshOutput.buffer);
const savedAsset = await createProjectAsset({
projectId: Number(projectId),
const meshAssetPayload = {
type: 'mesh',
name: trimmedName,
filePath: storedFilePath,
@ -3460,7 +3473,13 @@ app.post('/api/meshes/generate', async (req, res) => {
cardId: processingCardId
},
createdAt: Date.now()
});
};
// When a mesh was connected to the node and used to edit it, save the
// result as a version (child) of that mesh instead of a new root asset.
const savedAsset = normalizedParentAssetId
? await createAssetVersion({ assetId: normalizedParentAssetId, ...meshAssetPayload })
: await createProjectAsset({ projectId: Number(projectId), ...meshAssetPayload });
await clearCardProcessingState(processingProjectId, processingCardId, {
name: processingCardName
@ -3490,7 +3509,7 @@ app.post('/api/meshes/generate', async (req, res) => {
app.post('/api/meshes/generate/tencent/result', async (req, res) => {
try {
const { projectId, jobId, region, name, prompt = '', cardId = null, selectedApi = TENCENT_MESH_GENERATION_API_ID } = req.body;
const { projectId, jobId, region, name, prompt = '', cardId = null, selectedApi = TENCENT_MESH_GENERATION_API_ID, parentAssetId = null } = req.body;
const trimmedName = String(name || '').trim();
if (!projectId || !jobId || !region || !trimmedName) {
@ -3589,7 +3608,8 @@ app.post('/api/meshes/generate/tencent/result', async (req, res) => {
selectedApi,
jobId: String(jobId)
},
downloadedFiles
downloadedFiles,
parentAssetId
});
if (cardId) {
@ -3616,7 +3636,7 @@ app.post('/api/meshes/generate/tencent/result', async (req, res) => {
app.post('/api/meshes/generate/tripo/result', async (req, res) => {
try {
const { projectId, taskId, name, prompt = '', cardId = null, selectedApi = TRIPO_MESH_GENERATION_API_ID } = req.body;
const { projectId, taskId, name, prompt = '', cardId = null, selectedApi = TRIPO_MESH_GENERATION_API_ID, parentAssetId = null } = req.body;
const trimmedName = String(name || '').trim();
if (!projectId || !taskId || !trimmedName) {
@ -3700,7 +3720,8 @@ app.post('/api/meshes/generate/tripo/result', async (req, res) => {
sourceUrl: downloadedFile.url,
isPbrModel: downloadedFile.isPbr
},
downloadedFiles: [downloadedFile]
downloadedFiles: [downloadedFile],
parentAssetId
});
if (cardId) {

View file

@ -66,7 +66,7 @@
"61": {
"inputs": {
"lora_name": "flux2-klein9b-albedo-lora.safetensors",
"strength_model": 1,
"strength_model": 0.8,
"model": [
"63",
0

View file

@ -94,7 +94,7 @@
"61": {
"inputs": {
"lora_name": "flux2-klein9b-albedo-lora.safetensors",
"strength_model": 1,
"strength_model": 0.8,
"model": [
"54",
0

View file

@ -802,6 +802,9 @@ export function ProjectProvider({ children }) {
if (workflowData.name) {
formData.append('name', workflowData.name)
}
if (workflowData.parentAssetId) {
formData.append('parentAssetId', workflowData.parentAssetId)
}
if (workflowData.persistProcessingCard === false) {
formData.append('persistProcessingCard', 'false')
}

View file

@ -1568,6 +1568,11 @@ export default function GraphPage({ project }) {
const targetInputSources = buildNodeInputSources(targetNodeId, nodes, edges)
if (targetNode.data.nodeKind === 'meshGen') {
// When a mesh is connected to (and therefore used to edit) this node, the
// generated mesh should become a version (child) of that connected mesh
// instead of a brand-new root asset in the Assets page.
const connectedMeshAssetId = getInputSource(nodes, edges, targetNodeId, 'mesh')?.asset?.id || null
if (targetDraft.mode === 'api') {
const selectedApiSource = resolveImageSourceOption(targetDraft.selectedInputSource, targetInputSources, libraryImageOptions)
const sourceAsset = selectedApiSource?.asset || getConnectedInputAssetFrom(nodes, edges, targetNodeId)
@ -1615,6 +1620,7 @@ export default function GraphPage({ project }) {
enablePBR: Boolean(targetDraft.enablePBR),
faceCount: Number(targetDraft.faceCount) || 500000,
prompt: trimmedPrompt,
parentAssetId: connectedMeshAssetId,
jobStatus: 'WAIT',
detail: 'Submitting Tencent Cloud mesh generation job',
currentNodeLabel: 'Waiting for Tencent Cloud job id'
@ -1703,6 +1709,7 @@ export default function GraphPage({ project }) {
selectedApi: targetDraft.selectedApi,
inputSource: effectiveSourceReference || null,
prompt: trimmedPrompt,
parentAssetId: connectedMeshAssetId,
modelVersion: targetDraft.modelVersion || 'v2.5-20250123',
modelSeed: targetDraft.modelSeed,
enableImageAutofix: Boolean(targetDraft.enableImageAutofix),
@ -1813,7 +1820,8 @@ export default function GraphPage({ project }) {
imageSource: sourceReference,
name: targetDraft.name.trim(),
selectedApi: targetDraft.selectedApi,
prompt: targetDraft.prompt.trim()
prompt: targetDraft.prompt.trim(),
parentAssetId: connectedMeshAssetId
})
const savedMeshes = (Array.isArray(response) ? response : [response]).filter(asset => asset?.type === 'mesh')
if (savedMeshes.length === 0) {
@ -1908,7 +1916,11 @@ export default function GraphPage({ project }) {
name: targetDraft.name.trim(),
inputs: inputValues,
promptId,
clientId
clientId,
parentAssetId: connectedMeshAssetId,
// A version is nested under its parent mesh, so don't spawn a new
// standalone Kanban card for it (progress is tracked via the node).
persistProcessingCard: connectedMeshAssetId ? false : true
})
const meshAssets = (Array.isArray(generatedAssets) ? generatedAssets : [generatedAssets]).filter(asset => asset?.type === 'mesh')
if (meshAssets.length === 0) {
@ -2159,13 +2171,15 @@ export default function GraphPage({ project }) {
region: runtimeMetadata.region,
name: targetNode.data.name || targetNode.data.asset?.name || 'Generated Mesh',
prompt: runtimeMetadata.prompt || '',
selectedApi: runtimeMetadata.selectedApi || TENCENT_MESH_GENERATION_API_ID
selectedApi: runtimeMetadata.selectedApi || TENCENT_MESH_GENERATION_API_ID,
parentAssetId: runtimeMetadata.parentAssetId || null
})
: await queryTripoMeshGenerationResult(project.id, {
taskId: runtimeMetadata.taskId,
name: targetNode.data.name || targetNode.data.asset?.name || 'Generated Mesh',
prompt: runtimeMetadata.prompt || '',
selectedApi: runtimeMetadata.selectedApi || TRIPO_MESH_GENERATION_API_ID
selectedApi: runtimeMetadata.selectedApi || TRIPO_MESH_GENERATION_API_ID,
parentAssetId: runtimeMetadata.parentAssetId || null
})
if (response.status === 'processing') {
@ -2234,6 +2248,7 @@ export default function GraphPage({ project }) {
jobStatus: null,
taskId: null,
taskStatus: null,
parentAssetId: null,
detail: null,
currentNodeLabel: null,
error: null