为什么不显示模型?
Why is the model not displayed?
我正在尝试实现多模型模型加载,但我加载的模型没有显示。我的代码与此代码相同 https://github.com/Autodesk-Forge/learn.forge.viewmodels/tree/nodejs,the only difference is in the ForgeViewer.js file, where I use the code from this article https://forge.autodesk.com/cloud_and_mobile/2016/02/model-aggregation-with-view-data-api-exposed.html。
在编写函数 launchViewer (token, urn) 时,我得到了这个 "GET error https://developer.api.autodesk.com/derivativeservice/v2/manifest/undefined?domain=http%3A%2F%2Flocalhost%3A3000 400 (Bad Request)",并且在不添加令牌的情况下,我没有收到错误,但模型没有显示。 oss.js 文件与第一篇文章中的文件完全相同。
下面是 ForgeViewer.js 文件的代码。
function launchViewer(urn) {
return new Promise((resolve, reject) => {
try {
var options = {
env: 'AutodeskProduction',
getAccessToken: getForgeToken
};
console.log(options);
Autodesk.Viewing.Initializer(options, () => {
Autodesk.Viewing.Document.load(
'urn:' + urn,
(document) => {
var rootItem = document.getRootItem();
var geometryItems3d = Autodesk.Viewing.Document.
getSubItemsWithProperties(
rootItem, {
'type': 'geometry',
'role': '3d'
},
true
);
var geometryItems2d = Autodesk.Viewing.Document.
getSubItemsWithProperties(
rootItem, {
'type': 'geometry',
'role': '2d'
},
true
);
var got2d = (geometryItems2d && geometryItems2d.length > 0);
var got3d = (geometryItems3d && geometryItems3d.length > 0);
console.log(options);
console.log(document);
console.log(rootItem);
console.log(geometryItems2d);
console.log(geometryItems3d);
console.log(got2d);
console.log(got3d);
if (got2d || got3d) {
var pathCollection = [];
geometryItems2d.forEach((item) => {
pathCollection.push(document.getViewablePath(item));
});
geometryItems3d.forEach((item) => {
pathCollection.push(document.getViewablePath(item));
});
return resolve(pathCollection);
} else {
return reject('no viewable content')
};
},
(err) => {
console.log(options);
console.log('Error loading document... ');
//Autodesk.Viewing.ErrorCode
switch (err) {
// removed for clarity, see full sample
}
});
});
} catch (ex) {
return reject(ex);
}
});
}
function getForgeToken(callback) {
jQuery.ajax({
url: '/api/forge/oauth/token',
success: function (res) {
callback(res.access_token, res.expires_in)
}
});
}
您是否成功并完整地转换了模型(参见教程 here)并将模型的 based64 编码对象 ID(例如 var urn = btoa('urn:adsk.a360betadev:fs.file:business.lmvtest.DS5a730QTbf1122d07')
)提供给加载方法?
Autodesk.Viewing.Document.load(
'urn:' + urn, //The base64 encoded object ID of your translated model object goes here
...
如果没有它,您的错误消息中的清单请求中的骨灰盒部分将是 undefined
,因此会出现错误。
我正在尝试实现多模型模型加载,但我加载的模型没有显示。我的代码与此代码相同 https://github.com/Autodesk-Forge/learn.forge.viewmodels/tree/nodejs,the only difference is in the ForgeViewer.js file, where I use the code from this article https://forge.autodesk.com/cloud_and_mobile/2016/02/model-aggregation-with-view-data-api-exposed.html。 在编写函数 launchViewer (token, urn) 时,我得到了这个 "GET error https://developer.api.autodesk.com/derivativeservice/v2/manifest/undefined?domain=http%3A%2F%2Flocalhost%3A3000 400 (Bad Request)",并且在不添加令牌的情况下,我没有收到错误,但模型没有显示。 oss.js 文件与第一篇文章中的文件完全相同。
下面是 ForgeViewer.js 文件的代码。
function launchViewer(urn) {
return new Promise((resolve, reject) => {
try {
var options = {
env: 'AutodeskProduction',
getAccessToken: getForgeToken
};
console.log(options);
Autodesk.Viewing.Initializer(options, () => {
Autodesk.Viewing.Document.load(
'urn:' + urn,
(document) => {
var rootItem = document.getRootItem();
var geometryItems3d = Autodesk.Viewing.Document.
getSubItemsWithProperties(
rootItem, {
'type': 'geometry',
'role': '3d'
},
true
);
var geometryItems2d = Autodesk.Viewing.Document.
getSubItemsWithProperties(
rootItem, {
'type': 'geometry',
'role': '2d'
},
true
);
var got2d = (geometryItems2d && geometryItems2d.length > 0);
var got3d = (geometryItems3d && geometryItems3d.length > 0);
console.log(options);
console.log(document);
console.log(rootItem);
console.log(geometryItems2d);
console.log(geometryItems3d);
console.log(got2d);
console.log(got3d);
if (got2d || got3d) {
var pathCollection = [];
geometryItems2d.forEach((item) => {
pathCollection.push(document.getViewablePath(item));
});
geometryItems3d.forEach((item) => {
pathCollection.push(document.getViewablePath(item));
});
return resolve(pathCollection);
} else {
return reject('no viewable content')
};
},
(err) => {
console.log(options);
console.log('Error loading document... ');
//Autodesk.Viewing.ErrorCode
switch (err) {
// removed for clarity, see full sample
}
});
});
} catch (ex) {
return reject(ex);
}
});
}
function getForgeToken(callback) {
jQuery.ajax({
url: '/api/forge/oauth/token',
success: function (res) {
callback(res.access_token, res.expires_in)
}
});
}
您是否成功并完整地转换了模型(参见教程 here)并将模型的 based64 编码对象 ID(例如 var urn = btoa('urn:adsk.a360betadev:fs.file:business.lmvtest.DS5a730QTbf1122d07')
)提供给加载方法?
Autodesk.Viewing.Document.load(
'urn:' + urn, //The base64 encoded object ID of your translated model object goes here
...
如果没有它,您的错误消息中的清单请求中的骨灰盒部分将是 undefined
,因此会出现错误。