<script module="Autodesk" lang="renderjs">
var Autodesk
var v3D;
export default {
mounted() {
this.loadExternalCSS();
if (typeof window.Autodesk === 'function') {
setTimeout(() => this.onInitialized(),5000)
} else {
// 动态引入较大类库避免影响页面展示
var script = document.createElement('script')
// view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
script.src = 'https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/viewers/viewer3D.min.js'
script.onload = this.onInitialized.bind(this)
document.head.appendChild(script)
var script = document.createElement('script')
// view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
script.src = 'https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/viewers/extensions/Markup/Markup.min.js'
script.onload = this.onInitialized.bind(this)
document.head.appendChild(script)
var script = document.createElement('script')
// view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
script.src = 'https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/viewers/viewer3D.min.js'
script.onload = this.onInitialized.bind(this)
document.head.appendChild(script)
// var script = document.createElement('script')
// // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
// script.src = 'https://https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/viewers/viewer3D.min.js'
// script.onload = this.onInitialized.bind(this)
// document.head.appendChild(script)
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href =
'https://https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/viewers/viewer3D.min.js'; // 要引入的CSS文件的URL
script.onload = this.onInitialized.bind(this)
document.head.appendChild(link);
}
},
methods: {
loadExternalCSS() {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href =
'https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/style.min.css'; // 要引入的CSS文件的URL
document.head.appendChild(link);
},
onInitialized() {
// debugger
//定义autodesk需要的数据
var options = {
env: "Local",
};
//初始化查看器
window.Autodesk.Viewing.Initializer(options, () => {
//获取div实例
const myDiv = document.getElementById('forgeViewer ')
const extensions = true
const config3d = {
extensions: [
]
};
console.log('window', window)
//Autodesk获取div实例
v3D = new window.Autodesk.Viewing.GuiViewer3D(myDiv, config3d);
//继续加载模型
var startedCode1 = v3D.start();
if (startedCode1 > 0) {
console.error("Failed to create a Viewer: WebGL not supported.")
return
}
console.log("Initialization complete, loading a model next...")
// debugger
const viewerDocumentemp = new window.Autodesk.Viewing.Document(this.person);
console.log(this.modelUrl, 'hahah')
// const aa="https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/svf/meixiangli2/0.svf";
const aa = "https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/svf/baolong2/0.svf";
//
//将获取道德模型svf文件使用函数调用
v3D.loadModel(aa);
// v3D.loadModel(this.modelUrl);
// }
})
},
}
}
</script>
- 发布:2023-07-04 16:07
- 更新:2023-07-04 16:07
- 阅读:668
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10,win11
HBuilderX类型: 正式
HBuilderX版本号: 3.8.7
手机系统: Android
手机系统版本号: Android 14
手机厂商: 小米
手机机型: 小米11
页面类型: vue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
操作步骤:
预期结果:
app真机显示模型
app真机显示模型
实际结果:
app真机未显示模型
app真机未显示模型
bug描述:
<template>
<view>
<!-- <viewer></viewer> -->
<!-- <link rel="stylesheet" href="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/style.min.css" type="text/css"> -->
<!-- <link rel="stylesheet" href="https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/viewers/style.min.css"
type="text/css"> -->
<!-- https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/viewers/style.min.css -->
<view id="forgeViewer " name = 'forgeViewer'></view>
</view>
</template>
<script>
// import viewer from '../../component/Viewer/Viewer.vue'
import store from '@/store/index.js'; //需要引入store
// import manifestDataJSON from './new.json';
export default {
// components:{
// viewer,
// },
data() {
return {
// options: {
// env: 'Local',
// },
probId:'',
person: {},
modelUrl:''
// person: manifestDataJSON
}
},
onShow() {
this.getId()
//获取接口信息
this.getList()
},
mounted() {
},
onHide(){
// v3D.finish();
// v3D = null;
window.Autodesk.Viewing.shutdown();
},
methods: {
getId(){
const id = uni.getStorageSync('id')
this.probId = id
// console.log(this.probId,'09090')
},
getList() {
console.log(this.probId,'09090')
this.$ajax.get({
url: ``,
param: {
projectId : this.probId,
}
}).then((res) => {
console.log(res.data.data, '789789789')
// this.person =res.data.data.records[0].url
// console.log('onshow',this.person,'676767' )
const a = res.data.data.records[0].url
// const originalString = 'https://example.com/path/to/file.jpg';
const lastIndex = a.lastIndexOf('/');
const replacedString = a.substring(0, lastIndex + 1) + '0.svf';
this.modelUrl = replacedString
console.log(replacedString)
// this.url = res.data.data.records[0].url,// 要获取的JSON文件的URL
// console.log(this.url)
uni.request({
url: res.data.data.records[0].url,
success: (res) => {
// console.log(this.person,'989898')
this.person = res;
// console.log(this.person, '989898')
},
fail: (err) => {
console.error('请求JSON数据失败', err);
},
});
// debugger
})
},
},
}
</script>
<script module="Autodesk" lang="renderjs">
var Autodesk
var v3D;
export default {
mounted() {
this.loadExternalCSS();
if (typeof window.Autodesk === 'function') {
setTimeout(() => this.onInitialized(),5000)
} else {
// 动态引入较大类库避免影响页面展示
var script = document.createElement('script')
// view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
script.src = 'https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/viewers/viewer3D.min.js'
script.onload = this.onInitialized.bind(this)
document.head.appendChild(script)
var script = document.createElement('script')
// view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
script.src = 'https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/viewers/extensions/Markup/Markup.min.js'
script.onload = this.onInitialized.bind(this)
document.head.appendChild(script)
var script = document.createElement('script')
// view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
script.src = 'https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/viewers/viewer3D.min.js'
script.onload = this.onInitialized.bind(this)
document.head.appendChild(script)
// var script = document.createElement('script')
// // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
// script.src = 'https://https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/viewers/viewer3D.min.js'
// script.onload = this.onInitialized.bind(this)
// document.head.appendChild(script)
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href =
'https://https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/viewers/viewer3D.min.js'; // 要引入的CSS文件的URL
script.onload = this.onInitialized.bind(this)
document.head.appendChild(link);
}
},
methods: {
loadExternalCSS() {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href =
'https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/style.min.css'; // 要引入的CSS文件的URL
document.head.appendChild(link);
},
onInitialized() {
// debugger
//定义autodesk需要的数据
var options = {
env: "Local",
};
//初始化查看器
window.Autodesk.Viewing.Initializer(options, () => {
//获取div实例
const myDiv = document.getElementById('forgeViewer ')
const extensions = true
const config3d = {
extensions: [
]
};
console.log('window', window)
//Autodesk获取div实例
v3D = new window.Autodesk.Viewing.GuiViewer3D(myDiv, config3d);
//继续加载模型
var startedCode1 = v3D.start();
if (startedCode1 > 0) {
console.error("Failed to create a Viewer: WebGL not supported.")
return
}
console.log("Initialization complete, loading a model next...")
// debugger
const viewerDocumentemp = new window.Autodesk.Viewing.Document(this.person);
console.log(this.modelUrl, 'hahah')
// const aa="https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/svf/meixiangli2/0.svf";
const aa = "https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/svf/baolong2/0.svf";
//
//将获取道德模型svf文件使用函数调用
v3D.loadModel(aa);
// v3D.loadModel(this.modelUrl);
// }
})
},
}
}
</script>
在web端调试我的模型可以显示但是打包出来后就没有模型了,就报错
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'traverse') at https://bmy-forge-viewer.oss-cn-shenzhen.aliyuncs.com/viewers/viewer3D.min.js:18
0 个回复