mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
98 lines
2.6 KiB
HTML
98 lines
2.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<title>load material</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
|
<style>
|
|
body {
|
|
background-color: #333;
|
|
margin: 0px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.fit {
|
|
position: absolute;
|
|
top: 0;
|
|
bottom: 0;
|
|
left: 0;
|
|
right: 0;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body class="fit">
|
|
<canvas id="canvas" tabindex="-1" class="fit"></canvas>
|
|
<script src="../../node_modules/vconsole/dist/vconsole.min.js"></script>
|
|
<script src="../../node_modules/dat.gui/build/dat.gui.min.js"></script>
|
|
<script src="../bin/cocos-3d.dev.js"></script>
|
|
<script src="./camera.js"></script>
|
|
<script>
|
|
new window.VConsole();
|
|
let dgui = new window.dat.GUI({ width: 300 });
|
|
dgui.domElement.classList.add('dgui');
|
|
|
|
const $body = document.body;
|
|
const bcr = $body.getBoundingClientRect();
|
|
const canv = document.getElementById('canvas');
|
|
canv.width = bcr.width;
|
|
canv.height = bcr.height;
|
|
|
|
window.addEventListener('resize', () => {
|
|
const bcr = $body.getBoundingClientRect();
|
|
cc.director.root.resize(bcr.width, bcr.height);
|
|
});
|
|
|
|
function onStart() {
|
|
const root = cc.director.root;
|
|
const scene = new cc.Scene();
|
|
|
|
const cameraNode = new cc.Node('Camera');
|
|
cameraNode.parent = scene;
|
|
cameraNode.setPosition(6, 0, 2);
|
|
cameraNode.setRotationFromEuler(0, 70, 0);
|
|
cameraNode.addComponent(cc.CameraComponent);
|
|
cameraNode.addComponent(FirstPersonCamera);
|
|
|
|
const material = new cc.Material();
|
|
material.initialize({
|
|
effectAsset: effect,
|
|
technique: 1,
|
|
defines: { SOURCE: 'color.r', COUNT: 3.0, ALL_WHITE: true }
|
|
});
|
|
|
|
const modelNode = new cc.Node('test');
|
|
modelNode.parent = scene;
|
|
const modelComp = modelNode.addComponent('cc.ModelComponent');
|
|
modelComp.material = material;
|
|
modelComp.mesh = cc.utils.createMesh(cc.primitives.sphere());
|
|
|
|
cc.director.runSceneImmediate(scene);
|
|
|
|
}
|
|
|
|
cc.AssetLibrary.init({
|
|
libraryPath: 'library',
|
|
rawAssetsBase: 'library',
|
|
rawAssets: {
|
|
assets: {
|
|
"649e73d0-4a7f-4a40-9c9c-3b73c922ff20": ["dev", "cc.EffectAsset"]
|
|
}
|
|
}
|
|
});
|
|
|
|
// cc.sys.__audioSupport.WEB_AUDIO = false;
|
|
|
|
let jobsRemaining = 1, effect;
|
|
cc.loader.loadRes('dev', cc.EffectAsset, (err, asset) => {
|
|
effect = asset;
|
|
if (!--jobsRemaining) run();
|
|
});
|
|
|
|
const run = () => cc.game.run({ id: 'canvas' }, onStart);
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|