shichao Posted October 31, 2018 Share Posted October 31, 2018 i want to render six viewport and each viewport has its viewport mask and i want each viewport only show the object with the same viewport mask how can i do that #include <samples/render/common/render.h> #include <core/scripts/projection.h> WidgetSpriteViewport sprites[0]; /* */ void update_scene() { int grid_x = 3; int grid_y = 2; int space_x = engine.app.getWidth() / 64; int space_y = engine.app.getHeight() / 64; int width = (engine.app.getWidth() - space_x * 2) / grid_x; int height = (engine.app.getHeight() - space_y * 2) / grid_y; float aspect = float(width) / height; float bezel_x = 0.04f; float bezel_y = 0.02f; float angle = 0.0f; while(1) { if(sprites.size() == 0 || sprites[0] == NULL) { WidgetVBox vbox = new WidgetVBox(engine.getGui()); vbox.setBackground(1); vbox.setWidth(engine.app.getWidth()); vbox.setHeight(engine.app.getHeight()); engine.gui.addChild(vbox,GUI_ALIGN_OVERLAP | GUI_ALIGN_BACKGROUND); sprites.clear(); forloop(int y = 0; grid_y) { forloop(int x = 0; grid_x) { WidgetSpriteViewport sprite = new WidgetSpriteViewport(engine.getGui(),width - space_x,height - space_y); sprite.setPosition(space_x * 3 / 2 + width * x,space_y * 3 / 2 + height * y); engine.gui.addChild(sprite,GUI_ALIGN_OVERLAP | GUI_ALIGN_BACKGROUND); sprites.append(sprite); } } } Player player = Unigine::getPlayer(); mat4 projection = player.getProjection(); Mat4 modelview = player.getIWorldTransform(); forloop(int y = 0; grid_y) { forloop(int x = 0; grid_x) { mat4 ret_projection; Mat4 ret_modelview; WidgetSpriteViewport sprite = sprites[grid_x * y + x]; Unigine::getWallProjection(projection,modelview,aspect,1,1,0,0,bezel_x,bezel_y,angle,ret_projection,ret_modelview); sprite.setProjection(ret_projection); sprite.setModelview(ret_modelview); sprite.setViewportMask(grid_x * y + x); } } wait; } } /* */ void create_scene() { int size = 1; float space = 16.0f; engine.render.setEnabled(0); for(int y = -size; y <= size; y++) { for(int x = -size; x <= size; x++) { ObjectMeshStatic mesh = add_editor(new ObjectMeshStatic("samples/common/meshes/statue.mesh")); mesh.setWorldTransform(translate(Vec3(x,y,0.0f) * space)); mesh.setMaterial(get_phong_mesh_material(x ^ y),"*"); mesh.setProperty("surface_base","*"); } } return "WidgetSpriteViewport"; } Link to comment
silent Posted November 1, 2018 Share Posted November 1, 2018 Hi Schichao, Just tried to manually reproduce this inside Editor2 and it seems that everything is working fine. Please, keep in mind that you will have to manually set required viewport masks to the each and every object that you want to display, including the world light. By default light has 00000001 mask, so it will be visible only if you have this bit set in the corresponding viewport. Please, consider to check the bitmasking article: https://developer.unigine.com/en/docs/2.7.2/principles/bit_masking/ How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Recommended Posts