playcanvas制作3d地球
代码语言:html
所属分类:其他
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ISS Tracker (PlayCanvas)</title>
<style>
body {
overflow: hidden;
background-color: #000;
}
canvas {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
#logo {
z-index: 2;
position: fixed;
padding: 24px;
top: 0;
right: 0;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
</style>
</head>
<body translate="no">
<script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/playcanvas-1.22.0.js"></script>
<script >
/**********************************************
* UTILS
**********************************************/
const fetchData = async endpoint => {
const res = await fetch(endpoint);
if (res.ok) {
const data = await res.json();
return data;
}
throw new Error('unexpected status', response);
};
const applyMaterialTextures = (textures, material, assetPrefix = 'root', cb) => {
let count = 0;
Object.entries(textures).forEach(([property, url], i, l) => {
const asset = new pc.Asset(`${assetPrefix}-${property}`, 'texture', { url });
app.assets.add(asset);
app.assets.load(asset);
asset.ready(() => {
count++;
material[property] = asset.resource;
if (count === l.length) {
if (typeof cb === 'function') cb(material);
}
});
});
};
/**********************************************
* SETUP
* ---------------------------------------------
* create canvas and add it to the DOM
* create app and attach canvas and inputs
* enable crossorigin asset loading
* setup window resize listeners
* setup canvasFillMode, canvasResolution
* load slighly higher res sphere model
**********************************************/
const canvas = document.createElement('canvas');
document.body.appendChild(canvas);
const app = new pc.Application(canvas, {
elementInput: new pc.ElementInput(canvas),
keyboard: new pc.Keyboard(canvas),
mouse: new pc.Mouse(canvas),
touch: 'ontouchstart' in window ? new pc.TouchDevice(canvas) : null });
app.start();
app.loader.getHandler('texture').crossOrigin = 'anonymous';
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
app.setCanvasResolution(pc.RESOLUTION_AUTO);
window.addEventListener('resize', function () {
app.resizeCanvas(canvas.width, canvas.height);
});
app.scene.ambientLight = new pc.Color(0.1529, 0.1529, 0.1529);
app.scene.gammaCorrection = pc.GAMMA_SRGB;
app.scene.toneMapping = pc.TONEMAP_ACES;
app.scene.lightmapMaxResolution = 2048;
app.scene.lightmapMode = pc.BAKE_COLORDIR;
app.scene.lightmapSizeMultiplier = 16;
const SPHERE_MODEL = 'https://s.halvves.com/sphere.json';
const sphereModel = new pc.Asset('sphere', 'model', { url: SPHERE_MODEL });
app.assets.add(sphereModel);
app.assets.load(sphereModel);
/**********************************************
* SCRIPT: LOADING MANAGER
* ---------------------------------------------
* rotate entity based on a speed attribute
.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0