1 Star 0 Fork 0

ing10010/verge3d-code-examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
webxr_ar_paint.html 3.21 KB
一键复制 编辑 原始数据 按行查看 历史
<!DOCTYPE html>
<html lang="en">
<head>
<title>Verge3D ar - paint</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link type="text/css" rel="stylesheet" href="main.css">
</head>
<body>
<div id="info">
<a href="https://www.soft8soft.com/verge3d" target="_blank" rel="noopener">Verge3D</a> ar - paint<br/>(Chrome Android 81+)
</div>
<script type="module">
import * as v3d from '../build/v3d.module.js';
import { TubePainter } from './jsm/misc/TubePainter.js';
import { ARButton } from './jsm/webxr/ARButton.js';
let container;
let camera, scene, renderer;
let controller, painter;
const cursor = new v3d.Vector3();
init();
animate();
function init() {
container = document.createElement('div');
document.body.appendChild(container);
scene = new v3d.Scene();
camera = new v3d.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.01, 20);
//
renderer = new v3d.WebGLRenderer({ antialias: true, alpha: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.xr.enabled = true;
container.appendChild(renderer.domElement);
//
document.body.appendChild(ARButton.createButton(renderer));
// model
const light = new v3d.HemisphereLight(0xffffff, 0xbbbbff, 1);
light.position.set(0, 1, 0);
scene.add(light);
//
painter = new TubePainter();
painter.setSize(0.4);
painter.mesh.material.side = v3d.DoubleSide;
scene.add(painter.mesh);
//
function onSelectStart() {
this.userData.isSelecting = true;
this.userData.skipFrames = 2;
}
function onSelectEnd() {
this.userData.isSelecting = false;
}
controller = renderer.xr.getController(0);
controller.addEventListener('selectstart', onSelectStart);
controller.addEventListener('selectend', onSelectEnd);
controller.userData.skipFrames = 0;
scene.add(controller);
//
window.addEventListener('resize', onWindowResize, false);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
//
function handleController(controller) {
const userData = controller.userData;
cursor.set(0, 0, - 0.2).applyMatrix4(controller.matrixWorld);
if (userData.isSelecting === true) {
if (userData.skipFrames >= 0) {
// TODO(mrdoob) Revisit this
userData.skipFrames --;
painter.moveTo(cursor);
} else {
painter.lineTo(cursor);
painter.update();
}
}
}
function animate() {
renderer.setAnimationLoop(render);
}
function render() {
handleController(controller);
renderer.render(scene, camera);
}
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
HTML
1
https://gitee.com/ing/verge3d-code-examples.git
git@gitee.com:ing/verge3d-code-examples.git
ing
verge3d-code-examples
verge3d-code-examples
master

搜索帮助