Skip to content

Commit

Permalink
USDZExporter: Anchoring support (mrdoob#22854)
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridherbst committed Nov 24, 2022
1 parent e16ffe4 commit 431c49f
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions examples/jsm/exporters/USDZExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,9 @@ class USDZExporterContext {

class USDZExporter {

async parse( scene, extensions ) {
async parse( scene, extensions, sceneAnchoringOptions = { ar: { anchoring: { type: 'plane' }, planeAnchoring: { alignment: 'vertical' } } } ) {

this.sceneAnchoringOptions = sceneAnchoringOptions;
const context = new USDZExporterContext( scene, this, extensions );
extensions = context.extensions;

Expand All @@ -369,7 +370,6 @@ class USDZExporter {

invokeAll( context, 'onAfterHierarchy' );


const header = context.document.buildHeader();
const final = header + '\n' + context.output;

Expand Down Expand Up @@ -512,6 +512,21 @@ function parseDocument( context ) {

writer.beginBlock( `def Xform "${context.document.name}"` );

writer.beginBlock( `def Scope "Scenes" (
kind = "sceneLibrary"
)`);

writer.beginBlock(`def Xform "Scene" (
customData = {
bool preliminary_collidesWithEnvironment = 0
string sceneName = "Scene"
}
sceneName = "Scene"
)`);

writer.appendLine(`token preliminary:anchoring:type = "${this.sceneAnchoringOptions.ar.anchoring.type}"`);
writer.appendLine(`token preliminary:planeAnchoring:alignment = "${this.sceneAnchoringOptions.ar.planeAnchoring.alignment}"`);

for ( const child of context.document.children ) {

buildXform( child, writer, context );
Expand All @@ -520,6 +535,8 @@ function parseDocument( context ) {

writer.closeBlock();

writer.closeBlock();

context.output += writer.toString();

}
Expand Down

0 comments on commit 431c49f

Please sign in to comment.