mirror of https://github.com/mode777/rayjs.git
126 lines
4.6 KiB
JavaScript
126 lines
4.6 KiB
JavaScript
function log(v) { traceLog(LOG_INFO, v) }
|
|
|
|
setConfigFlags(FLAG_MSAA_4X_HINT | FLAG_WINDOW_HIGHDPI | FLAG_VSYNC_HINT);
|
|
|
|
initWindow(1024,768,"Test");
|
|
|
|
const scene = {}
|
|
|
|
let m = scene.raylib_model = loadModel("levels/test.obj");
|
|
|
|
|
|
//let m = loadModel("levels/test.obj");
|
|
// if(m.meshCount > 1){
|
|
// traceLog(LOG_INFO, "Starting merge of "+ m.meshCount + " meshes")
|
|
// let currentMesh = getModelMesh(m, 0);
|
|
// for (let i = 1; i < m.meshCount; i++) {
|
|
// const mesh = getModelMesh(m, i)
|
|
// const merged = meshMerge(mesh, currentMesh);
|
|
// if(i > 1) unloadMesh(currentMesh)
|
|
// currentMesh = merged
|
|
// }
|
|
// unloadModel(m)
|
|
// uploadMesh(currentMesh)
|
|
// traceLog(LOG_INFO, "Mesh successfully merged")
|
|
// m = loadModelFromMesh(currentMesh)
|
|
// }
|
|
|
|
const bbox = getModelBoundingBox(scene.raylib_model)
|
|
|
|
scene.w = 256;
|
|
scene.h = 256;
|
|
|
|
const img = new Image();
|
|
const data = new Uint8ClampedArray([255,255,255])
|
|
img.data = data.buffer
|
|
img.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8
|
|
img.width = 1
|
|
img.height = 1
|
|
img.mipmaps = 1
|
|
|
|
const position = new Vector3( 0, bbox.min.y + ((bbox.max.y - bbox.min.y) / 2), bbox.max.z - bbox.min.z ); // Camera position
|
|
const target = new Vector3( 0.0, bbox.min.y + ((bbox.max.y - bbox.min.y) / 2), 0.0); // Camera looking at point
|
|
const up = new Vector3(0.0, 1.0, 0.0); // Camera up vector (rotation towards target)
|
|
const fovy = 45.0; // Camera field-of-view Y
|
|
const projection = CAMERA_PERSPECTIVE; // Camera mode type
|
|
scene.camera = new Camera3D(position, target, up, fovy, projection);
|
|
|
|
// const config = getDefaultLightmapperConfig();
|
|
// //config.backgroundColor = new Color(10,10,10);
|
|
// //config.hemisphereSize = 512;
|
|
// const mesh = getModelMesh(scene.raylib_model, 0);
|
|
// const lm = loadLightmapper(scene.w, scene.h, mesh, config);
|
|
// const lmMat = loadMaterialLightmapper(BLACK, 0);
|
|
// const light = genMeshCube(0.2,0.2,0.2);
|
|
// const lightMaterial = loadMaterialLightmapper(ORANGE, .1);
|
|
|
|
const rt = loadRenderTexture(256,265)
|
|
|
|
|
|
while (!windowShouldClose())
|
|
{
|
|
const wm = getMouseWheelMove()
|
|
if(wm !== 0){
|
|
const camPos = scene.camera.position;
|
|
const fac = 1 + (wm * -0.1)
|
|
scene.camera.position = vector3Multiply(camPos, new Vector3(fac, fac, fac));
|
|
}
|
|
|
|
if(isMouseButtonDown(MOUSE_BUTTON_LEFT))
|
|
updateCamera(scene.camera, CAMERA_THIRD_PERSON);
|
|
|
|
// if(lm.progress < 1.0){
|
|
// let startTime = getTime();
|
|
// beginLightmap();
|
|
// while(beginLightmapFragment(lm)){
|
|
// drawMesh(mesh, lmMat, matrixIdentity());
|
|
// // drawMesh(light, lightMaterial, matrixTranslate(0.0,0.3,0.5));
|
|
// // drawMesh(light, lightMaterial, matrixTranslate(0.0,0.3,-0.5));
|
|
// //drawMesh(light, lightMaterial, matrixMultiply(matrixScale(60,60,60), matrixTranslate(0.0,150,0)));
|
|
// // drawMesh(light, lightMaterial, matrixTranslate(0.5,0.3,0));
|
|
// // drawMesh(light, lightMaterial, matrixTranslate(-0.5,0.3,0));
|
|
// endLightmapFragment(lm);
|
|
// // display progress every second (printf is expensive)
|
|
// let time = getTime();
|
|
// if (getTime() - startTime > 0.03) break;
|
|
// }
|
|
// endLightmap();
|
|
// if(lm.progress == 1.0){
|
|
// const img = loadImageFromLightmapper(lm);
|
|
// //exportImage(img, "my_result.png");
|
|
// const old = scene.raylib_texture;
|
|
// scene.raylib_texture = loadTextureFromImage(img);
|
|
// setTextureFilter(scene.raylib_texture, TEXTURE_FILTER_TRILINEAR);
|
|
// unloadTexture(old);
|
|
// let mat = loadMaterialDefault();
|
|
// setMaterialTexture(mat, MATERIAL_MAP_DIFFUSE, scene.raylib_texture);
|
|
// setModelMaterial(scene.raylib_model, 0, mat);
|
|
// unloadLightmapper(lm);
|
|
// }
|
|
// }
|
|
|
|
// beginTextureMode(rt)
|
|
// clearBackground(RED);
|
|
// drawTexture(getModelMaterial(m,1))
|
|
// endTextureMode()
|
|
|
|
beginDrawing();
|
|
clearBackground(BLUE);
|
|
|
|
beginMode3D(scene.camera);
|
|
drawModel(scene.raylib_model, new Vector3(0,0,0), 1, WHITE);
|
|
|
|
endMode3D();
|
|
|
|
// if(lm.progress < 1.0){
|
|
// drawRectangle(0,0,getScreenWidth(),20, fade(GREEN,0.5));
|
|
// drawRectangle(0,0,getScreenWidth()*lm.progress,20, GREEN);
|
|
// }
|
|
|
|
|
|
endDrawing();
|
|
}
|
|
|
|
unloadModel(scene.raylib_model);
|
|
//unloadTexture(scene.raylib_texture);
|
|
closeWindow(); |