- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有没有办法从输入类型文件中预览 .gltf (3D) 文件?我尝试上传 3D 文件,但没有显示任何内容。有谁知道是否可以解决我的问题?我已经测试了一切,但我仍然没有得到任何结果。 glTF 需要“转换”才能显示。
谢谢
HTML
<div style="height:100%; width:100%">
<input id="file-input" type="file"
(change)="mychange($event)" />
<canvas id="c"></canvas>
</div>
.TS
mychange(e){
let file = e.target.files[0];
let reader = new FileReader();
reader.onload = function ( gltfText ) {
const canvas = <HTMLCanvasElement> document.querySelector('#c');
const renderer = new THREE.WebGLRenderer({canvas});
const fov = 45;
const aspect = 2; // the canvas default
const near = 0.1;
const far = 100;
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
camera.position.set(0, 10, 20);
const controls = new OrbitControls(camera, canvas);
controls.target.set(0, 5, 0);
controls.update();
const scene = new THREE.Scene();
scene.background = new THREE.Color('black');
{
const planeSize = 40;
const loader = new THREE.TextureLoader();
const texture = loader.load('https://threejsfundamentals.org/threejs/resources/images/checker.png');
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.magFilter = THREE.NearestFilter;
const repeats = planeSize / 2;
texture.repeat.set(repeats, repeats);
const planeGeo = new THREE.PlaneBufferGeometry(planeSize, planeSize);
const planeMat = new THREE.MeshPhongMaterial({
map: texture,
side: THREE.DoubleSide,
});
const mesh = new THREE.Mesh(planeGeo, planeMat);
mesh.rotation.x = Math.PI * -.5;
scene.add(mesh);
}
{
const skyColor = 0xB1E1FF; // light blue
const groundColor = 0xB97A20; // brownish orange
const intensity = 1;
const light = new THREE.HemisphereLight(skyColor, groundColor, intensity);
scene.add(light);
}
{
const color = 0xFFFFFF;
const intensity = 1;
const light = new THREE.DirectionalLight(color, intensity);
light.position.set(5, 10, 2);
scene.add(light);
scene.add(light.target);
}
function frameArea(sizeToFitOnScreen, boxSize, boxCenter, camera) {
const halfSizeToFitOnScreen = sizeToFitOnScreen * 0.5;
const halfFovY = THREE.MathUtils.degToRad(camera.fov * .5);
const distance = halfSizeToFitOnScreen / Math.tan(halfFovY);
const direction = (new THREE.Vector3())
.subVectors(camera.position, boxCenter)
.multiply(new THREE.Vector3(1, 0, 1))
.normalize();
camera.position.copy(direction.multiplyScalar(distance).add(boxCenter));
camera.near = boxSize / 100;
camera.far = boxSize * 100;
camera.updateProjectionMatrix();
camera.lookAt(boxCenter.x, boxCenter.y, boxCenter.z);
}
{
const gltfLoader = new GLTFLoader();
gltfLoader.parse( gltfText.target.result, '', function( gltf ){
const root = gltf.scene;
scene.add(root);
const box = new THREE.Box3().setFromObject(root);
const boxSize = box.getSize(new THREE.Vector3()).length();
const boxCenter = box.getCenter(new THREE.Vector3());
frameArea(boxSize * 0.5, boxSize, boxCenter, camera);
controls.maxDistance = boxSize * 10;
controls.target.copy(boxCenter);
controls.update();
});
}
function resizeRendererToDisplaySize(renderer) {
const canvas = renderer.domElement;
const width = canvas.clientWidth;
const height = canvas.clientHeight;
const needResize = canvas.width !== width || canvas.height !== height;
if (needResize) {
renderer.setSize(width, height, false);
}
return needResize;
}
function render() {
if (resizeRendererToDisplaySize(renderer)) {
const canvas = renderer.domElement;
camera.aspect = canvas.clientWidth / canvas.clientHeight;
camera.updateProjectionMatrix();
}
renderer.render(scene, camera);
requestAnimationFrame(render);
}
requestAnimationFrame(render);
};
}
最佳答案
three.js editor确实支持这个用例。这个想法是使用 FileReader
API。要加载一个 glb
文件,代码如下所示:
const reader = new FileReader();
reader.addEventListener( 'load', function ( event ) {
const contents = event.target.result;
const loader = new GLTFLoader();
loader.parse( contents, '', function ( gltf ) {
const scene = gltf.scene;
console.log( scene );
} );
}, false );
reader.readAsArrayBuffer( file );
关于angular - 上传和预览 GLTF 文件 (3D),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64538909/
我有一个 gltf,它是一组建筑。 我想为每个建筑物添加一些信息,为此,我需要向我的 gltf 模型添加一些属性。 但是,我试着添加这样的东西 { "accessors": [ {
我有一个 gltf,它是一组建筑。 我想为每个建筑物添加一些信息,为此,我需要向我的 gltf 模型添加一些属性。 但是,我试着添加这样的东西 { "accessors": [ {
我之前曾在 gltf 1.0 上工作,现在正尝试更新我的应用程序以呈现 khronos 提供的 gltf2.0 示例模型。我了解着色器 (glsl) 和技术不再是 gltf 2.0 中核心属性的一部分
我正在阅读规范,但我无法理解采样器的属性。 这是我的动画 "animations" : [ { "channels" : [ {
您好,我正在尝试使用 Three.Js 实现 3D 模型查看器,但是我在加载时间方面遇到了问题,我不知道问题出在哪里。 作为一个例子,我试图在这里上传这个模型(下载链接):https://opensp
所以官方文档说: Note that the node transform is the local transform of the node relative to the joint, like
阅读 tinygltf 的源代码,我看到了这个: struct Skin { std::string name; int inverseBindMatrices; // required h
我已经使用网站上的 Collada 转换器将 dae 文件转换为 gltf 文件(我使用的是 Linux,所以我找不到转换前后的调试说明)。当我将模型加载到铯中时,它太暗了。然后我编辑 gltf 文件
我正在努力学习 WebGL,玩得很开心!我决定使用 glTF 作为这个项目的 3d 格式。我让它运行良好,但有一个奇怪的异常(exception)。当索引计数较低时(比如一个简单的三 Angular
我在 Blender (2.79) 中制作了一个非常基本的动画,我正在尝试将其导出为 GLTF 或 GLB。我已经成功安装了 gltf exporter并且能够毫无问题地导出非动画模型的 gltfs
IM 使用三个 js 并尝试从 blender 导入 3d 模型,我还使用 webpack 来处理它。我试图加载一个 glb 文件,但无法让它工作。它现在将文件添加到构建时的 dist 文件夹,但它没
我写了一个关于故障的演示场景来测试我在一个框架中导出的 gltf 模型,但我在控制台中收到一个错误: 我的代码 Basic Scene - A-Frame
我们正在尝试在服务器端合并多个 GLTF,并将合并的 gltf 作为最终结果导出到服务器上。 我们已经证实有效但无效的事情: 我们使用了三个 js GLTFLoader 解析方法来加载多个 gltf
我有一个大 obj 306 mb 的文件.所以我把它转换成 glb文件以减小其大小。文件的大小减少了很多到82 mb ,但还是很大。我想让这个文件更小。有办法吗?如果有,请告诉我。 如果不能减少glb
出于调试目的,我想渲染蒙皮网格的骨架。但是,在 glTF 中,它们似乎以非常抽象的方式定义。也就是说,没有“骨架”,一组由线连接的顶点。换句话说,这没有明确定义: 相反,“骨架”实际上是节点的集合,它
我正在尝试操作 gltf 3D 模型,但我不确定颜色是如何导出的。 baseColorFactor 中介于 0 到 1(或小于 1)之间的所有数字。 这肯定不是RGB也不是RGBA(我把这个页面作为引
我是 THREEJS 的新人。过去,我使用过 AFRAME、CESIUM、XEOGL 和 BABYLONJS。但最终,由于内存消耗和性能,我意识到制作 CAD 可视化工具的最佳产品是 THREEJS。
我正在尝试操作 gltf 3D 模型,但我不确定颜色是如何导出的。 baseColorFactor 中介于 0 到 1(或小于 1)之间的所有数字。 这肯定不是RGB也不是RGBA(我把这个页面作为引
有了这个答案作为引用,我已经成功改变了gltf模型的颜色。 ( Change the color of an object (.dae or gltf) in "AR.JS" ) 但是,模型纹理会消失
我正在测试 a-frame 并尝试加载不是本教程中提供的示例的其他 glTF 文件。我从 Sketchfab 下载了几个 glTF 包文件,但它们似乎无法加载。 如果我使用给定文件链接的 aframe
我是一名优秀的程序员,十分优秀!