3Dモデルジェネレーター
ジェネレーターのインポートエンドポイントは、サーバー間の読み取り専用リクエストに対応します。標準のAPIヘッダー、embed:session:create権限、有効なプランが必要です。インポートの認可ではエディターセッションは発行されず、その月間利用枠も消費しません。エディターを開くときは、ほかの埋め込みツールと共通のmonthlyEmbedTokenLimitカウンターを使用します。
ジェネレーター付きモデルの検索とインポート
/model-generator/modelsを使用して、利用可能なジェネレーター付きモデルを取得します。generator記述子はprojectId、revision、configurationId、templateRevision、productId、productModel3dIdを固定します。そのimportPathから、指定されたソースリビジョンを正確に取得してください。製品アセットのマニフェストには、generatorsと各モデルのgenerator記述子も含まれます。テンプレートは構成とリビジョンを指定して個別にインポートできます。
カタログのフィルター
| エンドポイント | 詳細 |
|---|---|
/model-generator/models | モデル一覧:nameまたはq、categoryId、scope(all、own、global)、limit(1-50)、offset。 |
/model-generator/catalog | テンプレートカタログ:generatorType、productId、audience、q、templateKey、configurationId、limit、offset。 |
/model-generator/projects | プロジェクト一覧:configurationId、q、scope(all、own、global)、limit、offset。公開プロキシではscopeのデフォルト値はallです。 |
/model-generator/image-libraries/:kind/assets | テクスチャ・背景ライブラリ:kindはtextureまたはbackgroundです。q、category、mapTypeで利用可能なアセットを絞り込みます。 |
プロジェクトのインポートにはdocument、revision、template、filesマニフェストが含まれます。各ファイルには/v1/model-generator/配下のpathが指定されます。Alter Productからダウンロードするときは、先頭に/public-apiを付けます。必要なファイルを自分のストレージにコピーし、ソース参照をローカル参照に置き換えてください。マネキンとテクスチャライブラリは、それぞれのカタログエンドポイントからインポートします。public-filesでは許可されたアセットパスのみを使用でき、テンプレートは構成・リビジョンのアクセス確認に合格する必要があります。
リクエスト例(fetch)
// Server-side: uses alterFetch and authHeaders from the API connection guide.
const catalog = await alterFetch('/model-generator/models?' + new URLSearchParams({
scope: 'all', limit: '24', offset: '0'
}));
const selected = catalog.items[0];
if (!selected?.generator) throw new Error('Select an available generator model');
const importPath = selected.generator.importPath;
if (!importPath.startsWith('/v1/model-generator/projects/')) {
throw new Error('Invalid generator import path');
}
const bundle = await alterFetch(importPath.slice('/v1'.length));
for (const file of bundle.files) {
if (!file.path.startsWith('/v1/model-generator/')) {
throw new Error('Invalid generator file path');
}
const response = await fetch('https://alterproduct.com/public-api' + file.path, {
headers: authHeaders,
redirect: 'error'
});
if (!response.ok) throw new Error(`File download failed: ${response.status}`);
const bytes = new Uint8Array(await response.arrayBuffer());
// Persist bytes in your local storage; record the mapping from
// file.sourceHref / file.href to the resulting local file reference.
}
// Persist bundle.document, bundle.template and revision metadata locally.
// Import the related product asset and its textures/mockups as needed:
const product = await alterFetch('/assets/products/' + selected.generator.productId);
const mannequins = await alterFetch('/model-generator/mannequins');
console.log({ product, mannequins });エディターセッションとローカル保存
エディターセッションは、tool: model-generator、ローカルのジェネレータープロジェクトを識別する正の数値toolId、および許可されたストアのoriginを指定して作成します。toolIdはプロジェクトのUUIDやWooCommerceの製品IDではありません。このツールではdesignId、orderId、runtimeBindingId、カートのフィールドを渡さないでください。ジェネレータープロジェクトのUUIDは別の識別子です。返されたtokenをiframeのハンドシェイクで渡します。ランタイムのブートストラップは、storageMode: wordpress_localを含むジェネレーターのコンテキストを返します。
// Server-side, after authorizing the merchant's access to this local project.
const localProjectId = 42; // Local generator project ID, not its UUID or WC product ID.
const session = await alterFetch('/embed/session', {
method: 'POST',
body: JSON.stringify({
tool: 'model-generator',
toolId: localProjectId,
origin: 'https://yourstore.com'
})
});
// The iframe receives session.token through ALTER_CUSTOMIZER_SESSION_READY.
// Do not put API credentials or the token in the iframe URL.
const bootstrapResponse = await fetch('https://alterproduct.com/public-api/v1/runtime/bootstrap', {
headers: { Authorization: `Bearer ${session.token}` }
});
if (!bootstrapResponse.ok) throw new Error('Generator bootstrap failed');
const context = await bootstrapResponse.json();
console.log(context);レスポンス例
{
"runtimeBindingId": null,
"designId": null,
"productId": 42,
"toolId": 42,
"runtimeType": "model-generator",
"storageMode": "wordpress_local",
"parentOrigin": "https://yourstore.com"
}// Host page: WordPress returns a numeric toolId and a UUID in id.
const url = new URL('https://alterproduct.com/app/model-generator');
url.search = new URLSearchParams({
embedded: '1',
lng: 'en',
parentOrigin: window.location.origin,
toolId: String(localProject.toolId),
serverProjectId: localProject.id
}).toString();
// Optional: serverProjectRevision pins an existing saved revision.
iframe.src = url.toString();
// Install the authenticated handshake and storage bridge described below.
// Setting iframe.src alone does not authorize the editor or provide storage.WordPressブリッジで使用するiframeメッセージ
WordPressプラグインがストレージブリッジを提供し、管理者またはWooCommerceマネージャーの権限を確認します。iframeのorigin、送信元ウィンドウ、nonce、リクエストID、許可されたプロジェクトパスを検証します。ローカルの読み取りと書き込みは、ブリッジから/wp-json/alter-wc/v1/model-generatorへ送信されます。API認証情報はサーバー上に保持されます。独自の統合では、同等の認証付きストレージ処理を実装する必要があります。公開ジェネレーターAPIはプロジェクトをAlter Productに保存しません。
| 型 | 説明 |
|---|---|
ALTER_CHILD_HELLO / ALTER_PARENT_ACK | 子フレームがnonce付きでハンドシェイクを開始し、親ページが同じnonceを確認します。 |
ALTER_CUSTOMIZER_INIT_SESSION / ALTER_CUSTOMIZER_SESSION_READY | 子フレームがmodel-generatorの編集セッションを要求し、親ページが認可済みトークンを返します。 |
ALTER_MODEL_GENERATOR_REQUEST | 子フレームがrequestId、nonce、およびmethod、path、data、responseTypeを含むrequestを送信します。 |
ALTER_MODEL_GENERATOR_RESPONSE | 親ページは同じrequestIdとnonceに加え、status、data、headers、および発生したerrorを返します。 |
// Messages after ALTER_CHILD_HELLO / ALTER_PARENT_ACK agree on the nonce.
// Iframe -> parent:
const sessionRequest = {
type: 'ALTER_CUSTOMIZER_INIT_SESSION',
nonce: handshakeNonce,
payload: {
tool: 'model-generator', alterProductId: localProject.toolId, mode: 'edit'
}
};
// Parent -> iframe, after the server authorizes the merchant and issues a token:
const sessionReady = {
type: 'ALTER_CUSTOMIZER_SESSION_READY',
nonce: handshakeNonce,
token: session.token,
tool: 'model-generator',
cartKey: `model-generator:${localProject.id}`,
mode: 'edit',
localSession: false,
adminSession: true
};
// Send only to the validated iframe's exact origin and source window.
// An authorized token and successful bootstrap are still required.保存時にはexpectedRevision、templateRevision、document、成果物への参照を渡します。保存によって変更不可のリビジョンが作成され、expectedRevisionが古い場合はHTTP 409が返されます。WordPressはメタデータをデータベースに、ファイルをuploadsディレクトリに保存します。JSONはコンパクト化され、サイズが小さくなる場合にgzipで圧縮されます。
// Example message from the iframe; savedSnapshot and artifact IDs come
// from the generator. The host checks origin/source/nonce/project permissions.
const message = {
type: 'ALTER_MODEL_GENERATOR_REQUEST',
requestId: crypto.randomUUID(),
nonce: handshakeNonce,
request: {
method: 'POST',
path: `/pattern-generator/projects/${projectUuid}/revisions`,
data: {
expectedRevision: loadedRevision,
name: projectName,
templateRevision,
document: savedSnapshot,
references: { artifactIds: savedArtifactIds }
},
responseType: 'json'
}
};「保存済みモデルをデザインで使用」を実行すると、保存済みリビジョン全体が関連付けられたデザインに公開されます。購入者は、通常の製品連携とサブスクリプション確認の下で、既存のCustomizer、Configurator、Viewerからそのモデルを使用します。ジェネレーターのエディターは販売者向けツールです。注文リンクは保存済みのプロジェクトとリビジョンを保持するため、後から編集しても過去の注文が意図せず変更されることはありません。