@yangyc
2019-03-10T10:03:24.000000Z
字数 3304
阅读 503
未分类
Wonder.js is a Functional, High performance 3D WebGL Engine.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>cube</title>
</head>
<body>
<script src="https://github.com/Wonder-Technology/Wonder.js/tree/master/examples/wd.js"></script>
<script>
window.onload = function () {
return wd.loadConfig(["https://github.com/Wonder-Technology/Wonder.js/tree/master/examples/config/setting.json", "https://github.com/Wonder-Technology/Wonder.js/tree/master/examples/config/"]).forEach(function (state) {
}).then(function () {
return initSample(wd.unsafeGetState());
})
function _createBox(state) {
var [state, material] = wd.createLightMaterial(state);
var state = wd.setLightMaterialDiffuseColor(material, [0.0, 0.5, 0.2], state);
var state = wd.setLightMaterialSpecularColor(material, [0.3, 0.1, 0.6], state);
var [state, meshRenderer] = wd.createMeshRenderer(state);
var [state, gameObject] = wd.createGameObject(state);
var state = wd.addGameObjectLightMaterialComponent(gameObject, material, state);
var state = wd.addGameObjectMeshRendererComponent(gameObject, meshRenderer, state);
var [state, geometry] = wd.createBoxGeometry(state);
var state = wd.addGameObjectGeometryComponent(gameObject, geometry, state);
return [state, gameObject];
};
function _createCamera(state) {
var [state, basicCameraView] = wd.createBasicCameraView(state);
var state =
wd.activeBasicCameraView(
basicCameraView, state
);
var [state, perspectiveCameraProjection] = wd.createPerspectiveCameraProjection(state);
var state = wd.setPerspectiveCameraProjectionNear(perspectiveCameraProjection, 0.1, state);
var state = wd.setPerspectiveCameraProjectionFar(perspectiveCameraProjection, 2000, state);
var state = wd.setPerspectiveCameraProjectionFovy(perspectiveCameraProjection, 60, state);
var [state, gameObject] = wd.createGameObject(state);
var state = wd.addGameObjectBasicCameraViewComponent(gameObject, basicCameraView, state);
var state = wd.addGameObjectPerspectiveCameraProjectionComponent(gameObject, perspectiveCameraProjection, state);
var transform = wd.unsafeGetGameObjectTransformComponent(gameObject, state);
var state = wd.setTransformLocalPosition(transform, [0, 10, 50], state);
return [state, gameObject];
};
function _createDirectionLight(state) {
var [state, light] = wd.createDirectionLight(state);
var state = wd.setDirectionLightColor(light, [1.0, 0.0, 0.0], state);
var [state, gameObject] = wd.createGameObject(state);
var transform = wd.unsafeGetGameObjectTransformComponent(gameObject, state);
var state = wd.setTransformLocalEulerAngles(transform, [0, 180, 0], state);
var state = wd.addGameObjectDirectionLightComponent(gameObject, light, state);
return [state, gameObject];
};
function initSample(state) {
var [state, box] = _createBox(state);
var state = wd.setAmbientLightColor([0.2, 0.2, 0.2], state);
var [state, directionLightGameObject] = _createDirectionLight(state);
var [state, cameraGameObject] = _createCamera(state);
wd.startDirector(state);
}
};
</script>
</body>
</html>
Design is Art
Code is Art
Everything is Art
Chrome
Firefox
Join us, We can create the amazing 3D world together!
MIT Licence