Everything returning to normal in 3D, still a long way to go
-implemented the scene part of visual server and rasterizer, objects without lighting and material are rendererd only
This commit is contained in:
parent
1527cf8c0d
commit
4428115916
23 changed files with 5196 additions and 272 deletions
|
|
@ -33,6 +33,75 @@
|
|||
#include "servers/visual_server.h"
|
||||
#include "camera_matrix.h"
|
||||
|
||||
#include "self_list.h"
|
||||
|
||||
|
||||
class RasterizerScene {
|
||||
public:
|
||||
|
||||
|
||||
struct InstanceBase : RID_Data {
|
||||
|
||||
VS::InstanceType base_type;
|
||||
RID base;
|
||||
|
||||
RID skeleton;
|
||||
RID material_override;
|
||||
|
||||
Transform transform;
|
||||
|
||||
int depth_layer;
|
||||
|
||||
//RID sampled_light;
|
||||
|
||||
Vector<RID> materials;
|
||||
Vector<RID> light_instances;
|
||||
|
||||
Vector<float> morph_values;
|
||||
|
||||
//BakedLightData *baked_light;
|
||||
VS::ShadowCastingSetting cast_shadows;
|
||||
//Transform *baked_light_octree_xform;
|
||||
//int baked_lightmap_id;
|
||||
|
||||
bool mirror :8;
|
||||
bool depth_scale :8;
|
||||
bool billboard :8;
|
||||
bool billboard_y :8;
|
||||
bool receive_shadows : 8;
|
||||
|
||||
SelfList<InstanceBase> dependency_item;
|
||||
|
||||
virtual void base_removed()=0;
|
||||
virtual void base_changed()=0;
|
||||
|
||||
InstanceBase() : dependency_item(this) {
|
||||
|
||||
base_type=VS::INSTANCE_NONE;
|
||||
cast_shadows=VS::SHADOW_CASTING_SETTING_ON;
|
||||
receive_shadows=true;
|
||||
depth_scale=false;
|
||||
billboard=false;
|
||||
billboard_y=false;
|
||||
depth_layer=0;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
virtual RID light_instance_create(RID p_light)=0;
|
||||
virtual void light_instance_set_transform(RID p_light_instance,const Transform& p_transform)=0;
|
||||
|
||||
virtual void render_scene(const Transform& p_cam_transform,CameraMatrix& p_cam_projection,bool p_cam_ortogonal,InstanceBase** p_cull_result,int p_cull_count,RID* p_light_cull_result,int p_light_cull_count,RID* p_directional_lights,int p_directional_light_count,RID p_environment)=0;
|
||||
|
||||
virtual bool free(RID p_rid)=0;
|
||||
|
||||
virtual ~RasterizerScene() {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class RasterizerStorage {
|
||||
|
|
@ -88,7 +157,7 @@ public:
|
|||
|
||||
virtual RID mesh_create()=0;
|
||||
|
||||
virtual void mesh_add_surface(RID p_mesh,uint32_t p_format,VS::PrimitiveType p_primitive,const DVector<uint8_t>& p_array,int p_vertex_count,const DVector<uint8_t>& p_index_array,int p_index_count,const Vector<DVector<uint8_t> >& p_blend_shapes=Vector<DVector<uint8_t> >())=0;
|
||||
virtual void mesh_add_surface(RID p_mesh,uint32_t p_format,VS::PrimitiveType p_primitive,const DVector<uint8_t>& p_array,int p_vertex_count,const DVector<uint8_t>& p_index_array,int p_index_count,const AABB& p_aabb,const Vector<DVector<uint8_t> >& p_blend_shapes=Vector<DVector<uint8_t> >(),const Vector<AABB>& p_bone_aabbs=Vector<AABB>())=0;
|
||||
|
||||
virtual void mesh_set_morph_target_count(RID p_mesh,int p_amount)=0;
|
||||
virtual int mesh_get_morph_target_count(RID p_mesh) const=0;
|
||||
|
|
@ -116,7 +185,7 @@ public:
|
|||
virtual void mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb)=0;
|
||||
virtual AABB mesh_get_custom_aabb(RID p_mesh) const=0;
|
||||
|
||||
virtual AABB mesh_get_aabb(RID p_mesh) const=0;
|
||||
virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton) const=0;
|
||||
virtual void mesh_clear(RID p_mesh)=0;
|
||||
|
||||
/* MULTIMESH API */
|
||||
|
|
@ -184,9 +253,11 @@ public:
|
|||
virtual void light_set_cull_mask(RID p_light,uint32_t p_mask)=0;
|
||||
virtual void light_set_shader(RID p_light,RID p_shader)=0;
|
||||
|
||||
|
||||
virtual void light_directional_set_shadow_mode(RID p_light,VS::LightDirectionalShadowMode p_mode)=0;
|
||||
|
||||
virtual VS::LightType light_get_type(RID p_light) const=0;
|
||||
virtual AABB light_get_aabb(RID p_light) const=0;
|
||||
|
||||
/* PROBE API */
|
||||
|
||||
virtual RID reflection_probe_create()=0;
|
||||
|
|
@ -220,6 +291,10 @@ public:
|
|||
virtual void portal_set_disabled_color(RID p_portal, const Color& p_color)=0;
|
||||
|
||||
|
||||
|
||||
virtual void instance_add_dependency(RID p_base,RasterizerScene::InstanceBase *p_instance)=0;
|
||||
virtual void instance_remove_dependency(RID p_base,RasterizerScene::InstanceBase *p_instance)=0;
|
||||
|
||||
/* RENDER TARGET */
|
||||
|
||||
enum RenderTargetFlags {
|
||||
|
|
@ -246,6 +321,8 @@ public:
|
|||
virtual RID canvas_light_occluder_create()=0;
|
||||
virtual void canvas_light_occluder_set_polylines(RID p_occluder, const DVector<Vector2>& p_lines)=0;
|
||||
|
||||
|
||||
virtual VS::InstanceType get_base_type(RID p_rid) const=0;
|
||||
virtual bool free(RID p_rid)=0;
|
||||
|
||||
|
||||
|
|
@ -257,6 +334,7 @@ public:
|
|||
|
||||
|
||||
|
||||
|
||||
class RasterizerCanvas {
|
||||
public:
|
||||
|
||||
|
|
@ -563,7 +641,7 @@ public:
|
|||
case Item::Command::TYPE_MESH: {
|
||||
|
||||
const Item::CommandMesh* mesh = static_cast< const Item::CommandMesh*>(c);
|
||||
AABB aabb = RasterizerStorage::base_signleton->mesh_get_aabb(mesh->mesh);
|
||||
AABB aabb = RasterizerStorage::base_signleton->mesh_get_aabb(mesh->mesh,mesh->skeleton);
|
||||
|
||||
r=Rect2(aabb.pos.x,aabb.pos.y,aabb.size.x,aabb.size.y);
|
||||
|
||||
|
|
@ -654,17 +732,6 @@ public:
|
|||
};
|
||||
|
||||
|
||||
|
||||
class RasterizerScene {
|
||||
public:
|
||||
|
||||
|
||||
|
||||
virtual ~RasterizerScene() {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Rasterizer {
|
||||
protected:
|
||||
static Rasterizer* (*_create_func)();
|
||||
|
|
@ -689,8 +756,6 @@ public:
|
|||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
|
|
|
|||
|
|
@ -58,8 +58,8 @@ ShaderTypes::ShaderTypes()
|
|||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["NORMAL"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["ALBEDO"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["ALPHA"]=ShaderLanguage::TYPE_FLOAT;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["METAL"]=ShaderLanguage::TYPE_FLOAT;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["ROUGH"]=ShaderLanguage::TYPE_FLOAT;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["SPECULAR"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["ROUGHNESS"]=ShaderLanguage::TYPE_FLOAT;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["EMISSION"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["SPECIAL"]=ShaderLanguage::TYPE_FLOAT;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["DISCARD"]=ShaderLanguage::TYPE_BOOL;
|
||||
|
|
@ -77,10 +77,6 @@ ShaderTypes::ShaderTypes()
|
|||
shader_modes[VS::SHADER_SPATIAL].modes.insert("blend_sub");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("blend_mul");
|
||||
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("special_glow");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("special_subsurf");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("special_specular");
|
||||
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("depth_draw_opaque");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("depth_draw_always");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("depth_draw_never");
|
||||
|
|
@ -90,12 +86,10 @@ ShaderTypes::ShaderTypes()
|
|||
shader_modes[VS::SHADER_SPATIAL].modes.insert("cull_back");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("cull_disable");
|
||||
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("lightmap_on_uv2");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("unshaded");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("ontop");
|
||||
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("vertex_model_space");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("vertex_camera_space");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("skip_transform");
|
||||
|
||||
/************ CANVAS ITEM **************************/
|
||||
|
||||
|
|
@ -158,4 +152,5 @@ ShaderTypes::ShaderTypes()
|
|||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,183 +34,12 @@
|
|||
#include "io/marshalls.h"
|
||||
#include "visual_server_canvas.h"
|
||||
#include "visual_server_global.h"
|
||||
#include "visual_server_scene.h"
|
||||
|
||||
// careful, these may run in different threads than the visual server
|
||||
|
||||
|
||||
|
||||
/* CAMERA API */
|
||||
|
||||
RID VisualServerRaster::camera_create() {
|
||||
|
||||
return RID();
|
||||
}
|
||||
void VisualServerRaster::camera_set_perspective(RID p_camera,float p_fovy_degrees, float p_z_near, float p_z_far) {
|
||||
|
||||
}
|
||||
void VisualServerRaster::camera_set_orthogonal(RID p_camera,float p_size, float p_z_near, float p_z_far){
|
||||
|
||||
}
|
||||
void VisualServerRaster::camera_set_transform(RID p_camera,const Transform& p_transform) {
|
||||
|
||||
}
|
||||
void VisualServerRaster::camera_set_cull_mask(RID p_camera,uint32_t p_layers){
|
||||
|
||||
}
|
||||
void VisualServerRaster::camera_set_environment(RID p_camera,RID p_env){
|
||||
|
||||
}
|
||||
void VisualServerRaster::camera_set_use_vertical_aspect(RID p_camera,bool p_enable){
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* ENVIRONMENT API */
|
||||
|
||||
RID VisualServerRaster::environment_create(){
|
||||
|
||||
return RID();
|
||||
}
|
||||
|
||||
void VisualServerRaster::environment_set_background(RID p_env,EnvironmentBG p_bg){
|
||||
|
||||
}
|
||||
void VisualServerRaster::environment_set_skybox(RID p_env,RID p_skybox,float p_energy){
|
||||
|
||||
}
|
||||
void VisualServerRaster::environment_set_bg_color(RID p_env,const Color& p_color){
|
||||
|
||||
}
|
||||
void VisualServerRaster::environment_set_canvas_max_layer(RID p_env,int p_max_layer){
|
||||
|
||||
}
|
||||
void VisualServerRaster::environment_set_ambient_light(RID p_env,const Color& p_color,float p_energy){
|
||||
|
||||
}
|
||||
|
||||
void VisualServerRaster::environment_set_glow(RID p_env,bool p_enable,int p_radius,float p_intensity,float p_strength,float p_bloom_treshold,EnvironmentGlowBlendMode p_blend_mode){
|
||||
|
||||
}
|
||||
void VisualServerRaster::environment_set_fog(RID p_env,bool p_enable,float p_begin,float p_end,RID p_gradient_texture){
|
||||
|
||||
}
|
||||
|
||||
void VisualServerRaster::environment_set_tonemap(RID p_env,bool p_enable,float p_exposure,float p_white,float p_min_luminance,float p_max_luminance,float p_auto_exp_speed,EnvironmentToneMapper p_tone_mapper){
|
||||
|
||||
}
|
||||
void VisualServerRaster::environment_set_brightness(RID p_env,bool p_enable,float p_brightness){
|
||||
|
||||
}
|
||||
void VisualServerRaster::environment_set_contrast(RID p_env,bool p_enable,float p_contrast){
|
||||
|
||||
}
|
||||
void VisualServerRaster::environment_set_saturation(RID p_env,bool p_enable,float p_saturation){
|
||||
|
||||
}
|
||||
void VisualServerRaster::environment_set_color_correction(RID p_env,bool p_enable,RID p_ramp){
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* SCENARIO API */
|
||||
|
||||
|
||||
RID VisualServerRaster::scenario_create() {
|
||||
|
||||
return RID();
|
||||
}
|
||||
|
||||
void VisualServerRaster::scenario_set_debug(RID p_scenario,ScenarioDebugMode p_debug_mode){
|
||||
|
||||
}
|
||||
void VisualServerRaster::scenario_set_environment(RID p_scenario, RID p_environment){
|
||||
|
||||
}
|
||||
RID VisualServerRaster::scenario_get_environment(RID p_scenario, RID p_environment) const{
|
||||
|
||||
return RID();
|
||||
}
|
||||
void VisualServerRaster::scenario_set_fallback_environment(RID p_scenario, RID p_environment){
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* INSTANCING API */
|
||||
// from can be mesh, light, area and portal so far.
|
||||
RID VisualServerRaster::instance_create(){
|
||||
|
||||
return RID();
|
||||
}
|
||||
|
||||
void VisualServerRaster::instance_set_base(RID p_instance, RID p_base){
|
||||
|
||||
}
|
||||
void VisualServerRaster::instance_set_scenario(RID p_instance, RID p_scenario){
|
||||
|
||||
}
|
||||
void VisualServerRaster::instance_set_layer_mask(RID p_instance, uint32_t p_mask){
|
||||
|
||||
}
|
||||
void VisualServerRaster::instance_set_transform(RID p_instance, const Transform& p_transform){
|
||||
|
||||
}
|
||||
void VisualServerRaster::instance_attach_object_instance_ID(RID p_instance,ObjectID p_ID){
|
||||
|
||||
}
|
||||
void VisualServerRaster::instance_set_morph_target_weight(RID p_instance,int p_shape, float p_weight){
|
||||
|
||||
}
|
||||
void VisualServerRaster::instance_set_surface_material(RID p_instance,int p_surface, RID p_material){
|
||||
|
||||
}
|
||||
|
||||
void VisualServerRaster::instance_attach_skeleton(RID p_instance,RID p_skeleton){
|
||||
|
||||
}
|
||||
void VisualServerRaster::instance_set_exterior( RID p_instance, bool p_enabled ){
|
||||
|
||||
}
|
||||
void VisualServerRaster::instance_set_room( RID p_instance, RID p_room ){
|
||||
|
||||
}
|
||||
|
||||
void VisualServerRaster::instance_set_extra_visibility_margin( RID p_instance, real_t p_margin ){
|
||||
|
||||
}
|
||||
|
||||
// don't use these in a game!
|
||||
Vector<ObjectID> VisualServerRaster::instances_cull_aabb(const AABB& p_aabb, RID p_scenario) const{
|
||||
|
||||
return Vector<ObjectID>();
|
||||
}
|
||||
|
||||
Vector<ObjectID> VisualServerRaster::instances_cull_ray(const Vector3& p_from, const Vector3& p_to, RID p_scenario) const{
|
||||
|
||||
return Vector<ObjectID>();
|
||||
}
|
||||
Vector<ObjectID> VisualServerRaster::instances_cull_convex(const Vector<Plane>& p_convex, RID p_scenario) const {
|
||||
|
||||
return Vector<ObjectID>();
|
||||
}
|
||||
|
||||
|
||||
void VisualServerRaster::instance_geometry_set_flag(RID p_instance,InstanceFlags p_flags,bool p_enabled){
|
||||
|
||||
}
|
||||
void VisualServerRaster::instance_geometry_set_cast_shadows_setting(RID p_instance, ShadowCastingSetting p_shadow_casting_setting) {
|
||||
|
||||
}
|
||||
void VisualServerRaster::instance_geometry_set_material_override(RID p_instance, RID p_material){
|
||||
|
||||
}
|
||||
|
||||
|
||||
void VisualServerRaster::instance_geometry_set_draw_range(RID p_instance,float p_min,float p_max,float p_min_margin,float p_max_margin){
|
||||
|
||||
}
|
||||
void VisualServerRaster::instance_geometry_set_as_instance_lod(RID p_instance,RID p_as_lod_of_instance){
|
||||
|
||||
}
|
||||
|
||||
/* CURSOR */
|
||||
void VisualServerRaster::cursor_set_rotation(float p_rotation, int p_cursor ){
|
||||
|
|
@ -247,6 +76,8 @@ void VisualServerRaster::free( RID p_rid ){
|
|||
return;
|
||||
if (VSG::viewport->free(p_rid))
|
||||
return;
|
||||
if (VSG::scene->free(p_rid))
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -258,6 +89,9 @@ void VisualServerRaster::draw(){
|
|||
// print_line("changes: "+itos(changes));
|
||||
|
||||
changes=0;
|
||||
|
||||
VSG::scene->update_dirty_instances(); //update scene stuff
|
||||
|
||||
VSG::rasterizer->begin_frame();
|
||||
VSG::viewport->draw_viewports();
|
||||
//_draw_cursors_and_margins();
|
||||
|
|
@ -322,6 +156,7 @@ VisualServerRaster::VisualServerRaster() {
|
|||
|
||||
VSG::canvas = memnew( VisualServerCanvas);
|
||||
VSG::viewport = memnew( VisualServerViewport);
|
||||
VSG::scene = memnew( VisualServerScene );
|
||||
VSG::rasterizer = Rasterizer::create();
|
||||
VSG::storage=VSG::rasterizer->get_storage();
|
||||
VSG::canvas_render=VSG::rasterizer->get_canvas();
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@
|
|||
#include "visual_server_global.h"
|
||||
#include "visual_server_viewport.h"
|
||||
#include "visual_server_canvas.h"
|
||||
#include "visual_server_scene.h"
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
|
|
@ -600,6 +601,7 @@ public:
|
|||
#define BIND6(m_name,m_type1,m_type2,m_type3,m_type4,m_type5,m_type6) void m_name(m_type1 arg1,m_type2 arg2,m_type3 arg3,m_type4 arg4,m_type5 arg5,m_type6 arg6) { DISPLAY_CHANGED BINDBASE->m_name(arg1,arg2,arg3,arg4,arg5,arg6); }
|
||||
#define BIND7(m_name,m_type1,m_type2,m_type3,m_type4,m_type5,m_type6,m_type7) void m_name(m_type1 arg1,m_type2 arg2,m_type3 arg3,m_type4 arg4,m_type5 arg5,m_type6 arg6,m_type7 arg7) { DISPLAY_CHANGED BINDBASE->m_name(arg1,arg2,arg3,arg4,arg5,arg6,arg7); }
|
||||
#define BIND8(m_name,m_type1,m_type2,m_type3,m_type4,m_type5,m_type6,m_type7,m_type8) void m_name(m_type1 arg1,m_type2 arg2,m_type3 arg3,m_type4 arg4,m_type5 arg5,m_type6 arg6,m_type7 arg7,m_type8 arg8) { DISPLAY_CHANGED BINDBASE->m_name(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8); }
|
||||
#define BIND9(m_name,m_type1,m_type2,m_type3,m_type4,m_type5,m_type6,m_type7,m_type8,m_type9) void m_name(m_type1 arg1,m_type2 arg2,m_type3 arg3,m_type4 arg4,m_type5 arg5,m_type6 arg6,m_type7 arg7,m_type8 arg8,m_type9 arg9) { DISPLAY_CHANGED BINDBASE->m_name(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9); }
|
||||
#define BIND10(m_name,m_type1,m_type2,m_type3,m_type4,m_type5,m_type6,m_type7,m_type8,m_type9,m_type10) void m_name(m_type1 arg1,m_type2 arg2,m_type3 arg3,m_type4 arg4,m_type5 arg5,m_type6 arg6,m_type7 arg7,m_type8 arg8,m_type9 arg9,m_type10 arg10) { DISPLAY_CHANGED BINDBASE->m_name(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10); }
|
||||
|
||||
//from now on, calls forwarded to this singleton
|
||||
|
|
@ -659,7 +661,7 @@ public:
|
|||
|
||||
BIND0R(RID,mesh_create)
|
||||
|
||||
BIND8(mesh_add_surface,RID,uint32_t,PrimitiveType,const DVector<uint8_t>&,int ,const DVector<uint8_t>& ,int ,const Vector<DVector<uint8_t> >& )
|
||||
BIND10(mesh_add_surface,RID,uint32_t,PrimitiveType,const DVector<uint8_t>&,int ,const DVector<uint8_t>& ,int ,const AABB&,const Vector<DVector<uint8_t> >&,const Vector<AABB>& )
|
||||
|
||||
BIND2(mesh_set_morph_target_count,RID,int)
|
||||
BIND1RC(int,mesh_get_morph_target_count,RID)
|
||||
|
|
@ -788,13 +790,18 @@ public:
|
|||
|
||||
/* CAMERA API */
|
||||
|
||||
virtual RID camera_create();
|
||||
virtual void camera_set_perspective(RID p_camera,float p_fovy_degrees, float p_z_near, float p_z_far);
|
||||
virtual void camera_set_orthogonal(RID p_camera,float p_size, float p_z_near, float p_z_far);
|
||||
virtual void camera_set_transform(RID p_camera,const Transform& p_transform);
|
||||
virtual void camera_set_cull_mask(RID p_camera,uint32_t p_layers);
|
||||
virtual void camera_set_environment(RID p_camera,RID p_env);
|
||||
virtual void camera_set_use_vertical_aspect(RID p_camera,bool p_enable);
|
||||
#undef BINDBASE
|
||||
//from now on, calls forwarded to this singleton
|
||||
#define BINDBASE VSG::scene
|
||||
|
||||
|
||||
BIND0R(RID, camera_create)
|
||||
BIND4(camera_set_perspective,RID,float, float , float )
|
||||
BIND4(camera_set_orthogonal,RID,float , float , float )
|
||||
BIND2(camera_set_transform,RID,const Transform&)
|
||||
BIND2(camera_set_cull_mask,RID,uint32_t )
|
||||
BIND2(camera_set_environment,RID ,RID )
|
||||
BIND2(camera_set_use_vertical_aspect,RID,bool)
|
||||
|
||||
#undef BINDBASE
|
||||
//from now on, calls forwarded to this singleton
|
||||
|
|
@ -839,66 +846,69 @@ public:
|
|||
|
||||
/* ENVIRONMENT API */
|
||||
|
||||
virtual RID environment_create();
|
||||
#undef BINDBASE
|
||||
//from now on, calls forwarded to this singleton
|
||||
#define BINDBASE VSG::scene
|
||||
|
||||
virtual void environment_set_background(RID p_env,EnvironmentBG p_bg);
|
||||
virtual void environment_set_skybox(RID p_env,RID p_skybox,float p_energy=1.0);
|
||||
virtual void environment_set_bg_color(RID p_env,const Color& p_color);
|
||||
virtual void environment_set_canvas_max_layer(RID p_env,int p_max_layer);
|
||||
virtual void environment_set_ambient_light(RID p_env,const Color& p_color,float p_energy=1.0);
|
||||
BIND0R(RID,environment_create)
|
||||
|
||||
virtual void environment_set_glow(RID p_env,bool p_enable,int p_radius,float p_intensity,float p_strength,float p_bloom_treshold,EnvironmentGlowBlendMode p_blend_mode);
|
||||
virtual void environment_set_fog(RID p_env,bool p_enable,float p_begin,float p_end,RID p_gradient_texture);
|
||||
BIND2(environment_set_background,RID ,EnvironmentBG )
|
||||
BIND3(environment_set_skybox,RID,RID ,float )
|
||||
BIND2(environment_set_bg_color,RID,const Color& )
|
||||
BIND2(environment_set_canvas_max_layer,RID,int )
|
||||
BIND3(environment_set_ambient_light,RID,const Color& ,float )
|
||||
|
||||
virtual void environment_set_tonemap(RID p_env,bool p_enable,float p_exposure,float p_white,float p_min_luminance,float p_max_luminance,float p_auto_exp_speed,EnvironmentToneMapper p_tone_mapper);
|
||||
virtual void environment_set_brightness(RID p_env,bool p_enable,float p_brightness);
|
||||
virtual void environment_set_contrast(RID p_env,bool p_enable,float p_contrast);
|
||||
virtual void environment_set_saturation(RID p_env,bool p_enable,float p_saturation);
|
||||
virtual void environment_set_color_correction(RID p_env,bool p_enable,RID p_ramp);
|
||||
BIND7(environment_set_glow,RID,bool ,int ,float ,float ,float ,EnvironmentGlowBlendMode )
|
||||
BIND5(environment_set_fog,RID,bool ,float ,float ,RID )
|
||||
|
||||
BIND8(environment_set_tonemap,RID,bool ,float ,float ,float ,float ,float ,EnvironmentToneMapper )
|
||||
BIND3(environment_set_brightness,RID,bool ,float )
|
||||
BIND3(environment_set_contrast,RID,bool ,float )
|
||||
BIND3(environment_set_saturation,RID,bool ,float )
|
||||
BIND3(environment_set_color_correction,RID,bool ,RID )
|
||||
|
||||
|
||||
/* SCENARIO API */
|
||||
|
||||
|
||||
virtual RID scenario_create();
|
||||
BIND0R(RID,scenario_create)
|
||||
|
||||
virtual void scenario_set_debug(RID p_scenario,ScenarioDebugMode p_debug_mode);
|
||||
virtual void scenario_set_environment(RID p_scenario, RID p_environment);
|
||||
virtual RID scenario_get_environment(RID p_scenario, RID p_environment) const;
|
||||
virtual void scenario_set_fallback_environment(RID p_scenario, RID p_environment);
|
||||
BIND2(scenario_set_debug,RID,ScenarioDebugMode )
|
||||
BIND2(scenario_set_environment,RID, RID )
|
||||
BIND2(scenario_set_fallback_environment,RID, RID )
|
||||
|
||||
|
||||
/* INSTANCING API */
|
||||
// from can be mesh, light, area and portal so far.
|
||||
virtual RID instance_create(); // from can be mesh, light, poly, area and portal so far.
|
||||
BIND0R(RID,instance_create)
|
||||
|
||||
virtual void instance_set_base(RID p_instance, RID p_base); // from can be mesh, light, poly, area and portal so far.
|
||||
virtual void instance_set_scenario(RID p_instance, RID p_scenario); // from can be mesh, light, poly, area and portal so far.
|
||||
virtual void instance_set_layer_mask(RID p_instance, uint32_t p_mask);
|
||||
virtual void instance_set_transform(RID p_instance, const Transform& p_transform);
|
||||
virtual void instance_attach_object_instance_ID(RID p_instance,ObjectID p_ID);
|
||||
virtual void instance_set_morph_target_weight(RID p_instance,int p_shape, float p_weight);
|
||||
virtual void instance_set_surface_material(RID p_instance,int p_surface, RID p_material);
|
||||
BIND2(instance_set_base,RID, RID ) // from can be mesh, light, poly, area and portal so far.
|
||||
BIND2(instance_set_scenario,RID, RID ) // from can be mesh, light, poly, area and portal so far.
|
||||
BIND2(instance_set_layer_mask,RID, uint32_t )
|
||||
BIND2(instance_set_transform,RID, const Transform& )
|
||||
BIND2(instance_attach_object_instance_ID,RID,ObjectID )
|
||||
BIND3(instance_set_morph_target_weight,RID,int , float )
|
||||
BIND3(instance_set_surface_material,RID,int , RID )
|
||||
|
||||
virtual void instance_attach_skeleton(RID p_instance,RID p_skeleton);
|
||||
virtual void instance_set_exterior( RID p_instance, bool p_enabled );
|
||||
virtual void instance_set_room( RID p_instance, RID p_room );
|
||||
BIND2(instance_attach_skeleton,RID,RID )
|
||||
BIND2(instance_set_exterior, RID, bool )
|
||||
BIND2(instance_set_room, RID, RID )
|
||||
|
||||
virtual void instance_set_extra_visibility_margin( RID p_instance, real_t p_margin );
|
||||
BIND2(instance_set_extra_visibility_margin, RID, real_t )
|
||||
|
||||
// don't use these in a game!
|
||||
virtual Vector<ObjectID> instances_cull_aabb(const AABB& p_aabb, RID p_scenario=RID()) const;
|
||||
virtual Vector<ObjectID> instances_cull_ray(const Vector3& p_from, const Vector3& p_to, RID p_scenario=RID()) const;
|
||||
virtual Vector<ObjectID> instances_cull_convex(const Vector<Plane>& p_convex, RID p_scenario=RID()) const;
|
||||
BIND2RC(Vector<ObjectID>,instances_cull_aabb,const AABB& , RID)
|
||||
BIND3RC(Vector<ObjectID>,instances_cull_ray,const Vector3& , const Vector3& , RID )
|
||||
BIND2RC(Vector<ObjectID>,instances_cull_convex,const Vector<Plane>& , RID)
|
||||
|
||||
|
||||
virtual void instance_geometry_set_flag(RID p_instance,InstanceFlags p_flags,bool p_enabled);
|
||||
virtual void instance_geometry_set_cast_shadows_setting(RID p_instance, ShadowCastingSetting p_shadow_casting_setting);
|
||||
virtual void instance_geometry_set_material_override(RID p_instance, RID p_material);
|
||||
BIND3(instance_geometry_set_flag,RID,InstanceFlags ,bool )
|
||||
BIND2(instance_geometry_set_cast_shadows_setting,RID, ShadowCastingSetting )
|
||||
BIND2(instance_geometry_set_material_override,RID, RID )
|
||||
|
||||
|
||||
virtual void instance_geometry_set_draw_range(RID p_instance,float p_min,float p_max,float p_min_margin,float p_max_margin);
|
||||
virtual void instance_geometry_set_as_instance_lod(RID p_instance,RID p_as_lod_of_instance);
|
||||
BIND5(instance_geometry_set_draw_range,RID,float ,float ,float ,float )
|
||||
BIND2(instance_geometry_set_as_instance_lod,RID,RID )
|
||||
|
||||
|
||||
#undef BINDBASE
|
||||
|
|
@ -1055,6 +1065,7 @@ public:
|
|||
#undef BIND6
|
||||
#undef BIND7
|
||||
#undef BIND8
|
||||
#undef BIND9
|
||||
#undef BIND10
|
||||
|
||||
};
|
||||
|
|
|
|||
1517
servers/visual/visual_server_scene.cpp
Normal file
1517
servers/visual/visual_server_scene.cpp
Normal file
File diff suppressed because it is too large
Load diff
390
servers/visual/visual_server_scene.h
Normal file
390
servers/visual/visual_server_scene.h
Normal file
|
|
@ -0,0 +1,390 @@
|
|||
#ifndef VISUALSERVERSCENE_H
|
||||
#define VISUALSERVERSCENE_H
|
||||
|
||||
#include "servers/visual/rasterizer.h"
|
||||
|
||||
#include "geometry.h"
|
||||
#include "allocators.h"
|
||||
#include "octree.h"
|
||||
#include "self_list.h"
|
||||
|
||||
class VisualServerScene {
|
||||
public:
|
||||
|
||||
|
||||
enum {
|
||||
|
||||
MAX_INSTANCE_CULL=65536,
|
||||
MAX_LIGHTS_CULLED=4096,
|
||||
MAX_ROOM_CULL=32,
|
||||
MAX_EXTERIOR_PORTALS=128,
|
||||
};
|
||||
|
||||
uint64_t render_pass;
|
||||
|
||||
|
||||
static VisualServerScene *singleton;
|
||||
#if 0
|
||||
struct Portal {
|
||||
|
||||
bool enabled;
|
||||
float disable_distance;
|
||||
Color disable_color;
|
||||
float connect_range;
|
||||
Vector<Point2> shape;
|
||||
Rect2 bounds;
|
||||
|
||||
|
||||
Portal() { enabled=true; disable_distance=50; disable_color=Color(); connect_range=0.8; }
|
||||
};
|
||||
|
||||
struct BakedLight {
|
||||
|
||||
Rasterizer::BakedLightData data;
|
||||
DVector<int> sampler;
|
||||
AABB octree_aabb;
|
||||
Size2i octree_tex_size;
|
||||
Size2i light_tex_size;
|
||||
|
||||
};
|
||||
|
||||
struct BakedLightSampler {
|
||||
|
||||
float params[BAKED_LIGHT_SAMPLER_MAX];
|
||||
int resolution;
|
||||
Vector<Vector3> dp_cache;
|
||||
|
||||
BakedLightSampler() {
|
||||
params[BAKED_LIGHT_SAMPLER_STRENGTH]=1.0;
|
||||
params[BAKED_LIGHT_SAMPLER_ATTENUATION]=1.0;
|
||||
params[BAKED_LIGHT_SAMPLER_RADIUS]=1.0;
|
||||
params[BAKED_LIGHT_SAMPLER_DETAIL_RATIO]=0.1;
|
||||
resolution=16;
|
||||
}
|
||||
};
|
||||
|
||||
void _update_baked_light_sampler_dp_cache(BakedLightSampler * blsamp);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
struct Camera : public RID_Data {
|
||||
|
||||
enum Type {
|
||||
PERSPECTIVE,
|
||||
ORTHOGONAL
|
||||
};
|
||||
Type type;
|
||||
float fov;
|
||||
float znear,zfar;
|
||||
float size;
|
||||
uint32_t visible_layers;
|
||||
bool vaspect;
|
||||
RID env;
|
||||
|
||||
Transform transform;
|
||||
|
||||
Camera() {
|
||||
|
||||
visible_layers=0xFFFFFFFF;
|
||||
fov=60;
|
||||
type=PERSPECTIVE;
|
||||
znear=0.1; zfar=100;
|
||||
size=1.0;
|
||||
vaspect=false;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
mutable RID_Owner<Camera> camera_owner;
|
||||
|
||||
virtual RID camera_create();
|
||||
virtual void camera_set_perspective(RID p_camera,float p_fovy_degrees, float p_z_near, float p_z_far);
|
||||
virtual void camera_set_orthogonal(RID p_camera,float p_size, float p_z_near, float p_z_far);
|
||||
virtual void camera_set_transform(RID p_camera,const Transform& p_transform);
|
||||
virtual void camera_set_cull_mask(RID p_camera,uint32_t p_layers);
|
||||
virtual void camera_set_environment(RID p_camera,RID p_env);
|
||||
virtual void camera_set_use_vertical_aspect(RID p_camera,bool p_enable);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
struct RoomInfo {
|
||||
|
||||
Transform affine_inverse;
|
||||
Room *room;
|
||||
List<Instance*> owned_geometry_instances;
|
||||
List<Instance*> owned_portal_instances;
|
||||
List<Instance*> owned_room_instances;
|
||||
List<Instance*> owned_light_instances; //not used, but just for the sake of it
|
||||
Set<Instance*> disconnected_child_portals;
|
||||
Set<Instance*> owned_autoroom_geometry;
|
||||
uint64_t last_visited_pass;
|
||||
RoomInfo() { last_visited_pass=0; }
|
||||
|
||||
};
|
||||
|
||||
struct InstancePortal {
|
||||
|
||||
Portal *portal;
|
||||
Set<Instance*> candidate_set;
|
||||
Instance *connected;
|
||||
uint64_t last_visited_pass;
|
||||
|
||||
Plane plane_cache;
|
||||
Vector<Vector3> transformed_point_cache;
|
||||
|
||||
|
||||
PortalInfo() { connected=NULL; last_visited_pass=0;}
|
||||
};
|
||||
*/
|
||||
|
||||
/* ENVIRONMENT API */
|
||||
|
||||
virtual RID environment_create();
|
||||
|
||||
virtual void environment_set_background(RID p_env,VS::EnvironmentBG p_bg);
|
||||
virtual void environment_set_skybox(RID p_env,RID p_skybox,float p_energy=1.0);
|
||||
virtual void environment_set_bg_color(RID p_env,const Color& p_color);
|
||||
virtual void environment_set_canvas_max_layer(RID p_env,int p_max_layer);
|
||||
virtual void environment_set_ambient_light(RID p_env,const Color& p_color,float p_energy=1.0);
|
||||
|
||||
virtual void environment_set_glow(RID p_env,bool p_enable,int p_radius,float p_intensity,float p_strength,float p_bloom_treshold,VS::EnvironmentGlowBlendMode p_blend_mode);
|
||||
virtual void environment_set_fog(RID p_env,bool p_enable,float p_begin,float p_end,RID p_gradient_texture);
|
||||
|
||||
virtual void environment_set_tonemap(RID p_env,bool p_enable,float p_exposure,float p_white,float p_min_luminance,float p_max_luminance,float p_auto_exp_speed,VS::EnvironmentToneMapper p_tone_mapper);
|
||||
virtual void environment_set_brightness(RID p_env,bool p_enable,float p_brightness);
|
||||
virtual void environment_set_contrast(RID p_env,bool p_enable,float p_contrast);
|
||||
virtual void environment_set_saturation(RID p_env,bool p_enable,float p_saturation);
|
||||
virtual void environment_set_color_correction(RID p_env,bool p_enable,RID p_ramp);
|
||||
|
||||
|
||||
/* SCENARIO API */
|
||||
|
||||
struct Instance;
|
||||
|
||||
struct Scenario : RID_Data {
|
||||
|
||||
|
||||
VS::ScenarioDebugMode debug;
|
||||
RID self;
|
||||
// well wtf, balloon allocator is slower?
|
||||
|
||||
Octree<Instance,true> octree;
|
||||
|
||||
List<Instance*> directional_lights;
|
||||
RID environment;
|
||||
RID fallback_environment;
|
||||
|
||||
SelfList<Instance>::List instances;
|
||||
|
||||
Scenario() { debug=VS::SCENARIO_DEBUG_DISABLED; }
|
||||
};
|
||||
|
||||
RID_Owner<Scenario> scenario_owner;
|
||||
|
||||
static void* _instance_pair(void *p_self, OctreeElementID, Instance *p_A,int, OctreeElementID, Instance *p_B,int);
|
||||
static void _instance_unpair(void *p_self, OctreeElementID, Instance *p_A,int, OctreeElementID, Instance *p_B,int,void*);
|
||||
|
||||
virtual RID scenario_create();
|
||||
|
||||
virtual void scenario_set_debug(RID p_scenario,VS::ScenarioDebugMode p_debug_mode);
|
||||
virtual void scenario_set_environment(RID p_scenario, RID p_environment);
|
||||
virtual void scenario_set_fallback_environment(RID p_scenario, RID p_environment);
|
||||
|
||||
|
||||
/* INSTANCING API */
|
||||
|
||||
struct InstanceBaseData {
|
||||
|
||||
|
||||
virtual ~InstanceBaseData() {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct Instance : RasterizerScene::InstanceBase {
|
||||
|
||||
RID self;
|
||||
//scenario stuff
|
||||
OctreeElementID octree_id;
|
||||
Scenario *scenario;
|
||||
SelfList<Instance> scenario_item;
|
||||
|
||||
//aabb stuff
|
||||
bool update_aabb;
|
||||
bool update_materials;
|
||||
SelfList<Instance> update_item;
|
||||
|
||||
|
||||
AABB aabb;
|
||||
AABB transformed_aabb;
|
||||
float extra_margin;
|
||||
uint32_t object_ID;
|
||||
bool visible;
|
||||
uint32_t layer_mask;
|
||||
|
||||
float lod_begin;
|
||||
float lod_end;
|
||||
float lod_begin_hysteresis;
|
||||
float lod_end_hysteresis;
|
||||
RID lod_instance;
|
||||
|
||||
Instance *room;
|
||||
SelfList<Instance> room_item;
|
||||
bool visible_in_all_rooms;
|
||||
|
||||
uint64_t last_render_pass;
|
||||
uint64_t last_frame_pass;
|
||||
|
||||
uint64_t version; // changes to this, and changes to base increase version
|
||||
|
||||
InstanceBaseData *base_data;
|
||||
|
||||
virtual void base_removed() {
|
||||
|
||||
singleton->instance_set_base(self,RID());
|
||||
}
|
||||
|
||||
virtual void base_changed() {
|
||||
|
||||
singleton->_instance_queue_update(this,true,true);
|
||||
}
|
||||
|
||||
|
||||
Instance() : scenario_item(this), update_item(this), room_item(this) {
|
||||
|
||||
octree_id=0;
|
||||
scenario=NULL;
|
||||
|
||||
|
||||
update_aabb=false;
|
||||
update_materials=false;
|
||||
|
||||
extra_margin=0;
|
||||
|
||||
|
||||
object_ID=0;
|
||||
visible=true;
|
||||
layer_mask=1;
|
||||
|
||||
lod_begin=0;
|
||||
lod_end=0;
|
||||
lod_begin_hysteresis=0;
|
||||
lod_end_hysteresis=0;
|
||||
|
||||
room=NULL;
|
||||
visible_in_all_rooms=false;
|
||||
|
||||
|
||||
|
||||
last_render_pass=0;
|
||||
last_frame_pass=0;
|
||||
version=1;
|
||||
base_data=NULL;
|
||||
|
||||
}
|
||||
|
||||
~Instance() {
|
||||
|
||||
if (base_data)
|
||||
memdelete(base_data);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
SelfList<Instance>::List _instance_update_list;
|
||||
void _instance_queue_update(Instance *p_instance,bool p_update_aabb,bool p_update_materials=false);
|
||||
|
||||
|
||||
struct InstanceGeometryData : public InstanceBaseData {
|
||||
|
||||
List<Instance*> lighting;
|
||||
bool lighting_dirty;
|
||||
|
||||
InstanceGeometryData() {
|
||||
|
||||
lighting_dirty=false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct InstanceLightData : public InstanceBaseData {
|
||||
|
||||
struct PairInfo {
|
||||
List<Instance*>::Element *L; //light iterator in geometry
|
||||
Instance *geometry;
|
||||
};
|
||||
|
||||
RID instance;
|
||||
uint64_t last_hash;
|
||||
List<Instance*>::Element *D; // directional light in scenario
|
||||
|
||||
bool shadow_sirty;
|
||||
|
||||
List<PairInfo> geometries;
|
||||
|
||||
InstanceLightData() {
|
||||
|
||||
shadow_sirty=true;
|
||||
D=NULL;
|
||||
last_hash=0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Instance *instance_cull_result[MAX_INSTANCE_CULL];
|
||||
Instance *instance_shadow_cull_result[MAX_INSTANCE_CULL]; //used for generating shadowmaps
|
||||
Instance *light_cull_result[MAX_LIGHTS_CULLED];
|
||||
RID light_instance_cull_result[MAX_LIGHTS_CULLED];
|
||||
int light_cull_count;
|
||||
|
||||
|
||||
RID_Owner<Instance> instance_owner;
|
||||
|
||||
// from can be mesh, light, area and portal so far.
|
||||
virtual RID instance_create(); // from can be mesh, light, poly, area and portal so far.
|
||||
|
||||
virtual void instance_set_base(RID p_instance, RID p_base); // from can be mesh, light, poly, area and portal so far.
|
||||
virtual void instance_set_scenario(RID p_instance, RID p_scenario); // from can be mesh, light, poly, area and portal so far.
|
||||
virtual void instance_set_layer_mask(RID p_instance, uint32_t p_mask);
|
||||
virtual void instance_set_transform(RID p_instance, const Transform& p_transform);
|
||||
virtual void instance_attach_object_instance_ID(RID p_instance,ObjectID p_ID);
|
||||
virtual void instance_set_morph_target_weight(RID p_instance,int p_shape, float p_weight);
|
||||
virtual void instance_set_surface_material(RID p_instance,int p_surface, RID p_material);
|
||||
|
||||
virtual void instance_attach_skeleton(RID p_instance,RID p_skeleton);
|
||||
virtual void instance_set_exterior( RID p_instance, bool p_enabled );
|
||||
virtual void instance_set_room( RID p_instance, RID p_room );
|
||||
|
||||
virtual void instance_set_extra_visibility_margin( RID p_instance, real_t p_margin );
|
||||
|
||||
|
||||
// don't use these in a game!
|
||||
virtual Vector<ObjectID> instances_cull_aabb(const AABB& p_aabb, RID p_scenario=RID()) const;
|
||||
virtual Vector<ObjectID> instances_cull_ray(const Vector3& p_from, const Vector3& p_to, RID p_scenario=RID()) const;
|
||||
virtual Vector<ObjectID> instances_cull_convex(const Vector<Plane>& p_convex, RID p_scenario=RID()) const;
|
||||
|
||||
|
||||
virtual void instance_geometry_set_flag(RID p_instance,VS::InstanceFlags p_flags,bool p_enabled);
|
||||
virtual void instance_geometry_set_cast_shadows_setting(RID p_instance, VS::ShadowCastingSetting p_shadow_casting_setting);
|
||||
virtual void instance_geometry_set_material_override(RID p_instance, RID p_material);
|
||||
|
||||
|
||||
virtual void instance_geometry_set_draw_range(RID p_instance,float p_min,float p_max,float p_min_margin,float p_max_margin);
|
||||
virtual void instance_geometry_set_as_instance_lod(RID p_instance,RID p_as_lod_of_instance);
|
||||
|
||||
|
||||
_FORCE_INLINE_ void _update_instance(Instance *p_instance);
|
||||
_FORCE_INLINE_ void _update_instance_aabb(Instance *p_instance);
|
||||
_FORCE_INLINE_ void _update_dirty_instance(Instance *p_instance);
|
||||
|
||||
|
||||
void render_camera(RID p_camera, RID p_scenario, Size2 p_viewport_size);
|
||||
void update_dirty_instances();
|
||||
bool free(RID p_rid);
|
||||
|
||||
VisualServerScene();
|
||||
};
|
||||
|
||||
#endif // VISUALSERVERSCENE_H
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
#include "visual_server_viewport.h"
|
||||
#include "visual_server_global.h"
|
||||
#include "visual_server_canvas.h"
|
||||
#include "visual_server_scene.h"
|
||||
#include "globals.h"
|
||||
|
||||
|
||||
|
||||
void VisualServerViewport::_draw_viewport(Viewport *p_viewport) {
|
||||
|
||||
/* Camera should always be BEFORE any other 3D */
|
||||
|
|
@ -58,6 +61,12 @@ void VisualServerViewport::_draw_viewport(Viewport *p_viewport) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (!p_viewport->disable_3d && p_viewport->camera.is_valid()) {
|
||||
|
||||
VSG::scene->render_camera(p_viewport->camera,p_viewport->scenario,p_viewport->size);
|
||||
}
|
||||
|
||||
if (!p_viewport->hide_canvas) {
|
||||
int i=0;
|
||||
|
||||
|
|
@ -248,6 +257,11 @@ void VisualServerViewport::draw_viewports() {
|
|||
|
||||
ERR_CONTINUE( !vp->render_target.is_valid() );
|
||||
|
||||
bool visible = vp->viewport_to_screen_rect!=Rect2() || vp->update_mode==VS::VIEWPORT_UPDATE_ALWAYS || vp->update_mode==VS::VIEWPORT_UPDATE_ONCE;
|
||||
|
||||
if (!visible)
|
||||
continue;
|
||||
|
||||
VSG::rasterizer->set_current_render_target(vp->render_target);
|
||||
_draw_viewport(vp);
|
||||
|
||||
|
|
|
|||
|
|
@ -345,8 +345,754 @@ RID VisualServer::get_white_texture() {
|
|||
}
|
||||
|
||||
|
||||
Error VisualServer::_surface_set_data(Array p_arrays,uint32_t p_format,uint32_t *p_offsets,uint32_t p_stride,DVector<uint8_t> &r_vertex_array,int p_vertex_array_len,DVector<uint8_t> &r_index_array,int p_index_array_len,AABB &r_aabb,Vector<AABB> r_bone_aabb) {
|
||||
|
||||
DVector<uint8_t>::Write vw = r_vertex_array.write();
|
||||
|
||||
DVector<uint8_t>::Write iw;
|
||||
if (r_index_array.size()) {
|
||||
iw=r_index_array.write();
|
||||
}
|
||||
|
||||
int max_bone=0;
|
||||
|
||||
|
||||
for(int ai=0;ai<VS::ARRAY_MAX;ai++) {
|
||||
|
||||
if (!(p_format&(1<<ai))) // no array
|
||||
continue;
|
||||
|
||||
|
||||
switch(ai) {
|
||||
|
||||
case VS::ARRAY_VERTEX: {
|
||||
|
||||
if (p_format& VS::ARRAY_FLAG_USE_2D_VERTICES) {
|
||||
|
||||
DVector<Vector2> array = p_arrays[ai];
|
||||
ERR_FAIL_COND_V( array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER );
|
||||
|
||||
|
||||
DVector<Vector2>::Read read = array.read();
|
||||
const Vector2* src=read.ptr();
|
||||
|
||||
// setting vertices means regenerating the AABB
|
||||
Rect2 aabb;
|
||||
|
||||
|
||||
if (p_format&ARRAY_COMPRESS_VERTEX) {
|
||||
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
|
||||
uint16_t vector[2]={ Math::make_half_float(src[i].x), Math::make_half_float(src[i].y) };
|
||||
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], vector, sizeof(uint16_t)*2);
|
||||
|
||||
if (i==0) {
|
||||
|
||||
aabb=Rect2(src[i],Vector2());
|
||||
} else {
|
||||
|
||||
aabb.expand_to( src[i] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
|
||||
float vector[2]={ src[i].x, src[i].y };
|
||||
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], vector, sizeof(float)*2);
|
||||
|
||||
if (i==0) {
|
||||
|
||||
aabb=Rect2(src[i],Vector2());
|
||||
} else {
|
||||
|
||||
aabb.expand_to( src[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r_aabb=AABB(Vector3(aabb.pos.x,aabb.pos.y,0),Vector3(aabb.size.x,aabb.size.y,0));
|
||||
|
||||
|
||||
} else {
|
||||
DVector<Vector3> array = p_arrays[ai];
|
||||
ERR_FAIL_COND_V( array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER );
|
||||
|
||||
|
||||
DVector<Vector3>::Read read = array.read();
|
||||
const Vector3* src=read.ptr();
|
||||
|
||||
// setting vertices means regenerating the AABB
|
||||
AABB aabb;
|
||||
|
||||
|
||||
if (p_format&ARRAY_COMPRESS_VERTEX) {
|
||||
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
|
||||
uint16_t vector[3]={ Math::make_half_float(src[i].x), Math::make_half_float(src[i].y), Math::make_half_float(src[i].z) };
|
||||
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], vector, sizeof(uint16_t)*3);
|
||||
|
||||
if (i==0) {
|
||||
|
||||
aabb=AABB(src[i],Vector3());
|
||||
} else {
|
||||
|
||||
aabb.expand_to( src[i] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
|
||||
float vector[3]={ src[i].x, src[i].y, src[i].z };
|
||||
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], vector, sizeof(float)*3);
|
||||
|
||||
if (i==0) {
|
||||
|
||||
aabb=AABB(src[i],Vector3());
|
||||
} else {
|
||||
|
||||
aabb.expand_to( src[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r_aabb=aabb;
|
||||
|
||||
}
|
||||
|
||||
|
||||
} break;
|
||||
case VS::ARRAY_NORMAL: {
|
||||
|
||||
ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::VECTOR3_ARRAY, ERR_INVALID_PARAMETER );
|
||||
|
||||
DVector<Vector3> array = p_arrays[ai];
|
||||
ERR_FAIL_COND_V( array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER );
|
||||
|
||||
|
||||
DVector<Vector3>::Read read = array.read();
|
||||
const Vector3* src=read.ptr();
|
||||
|
||||
// setting vertices means regenerating the AABB
|
||||
|
||||
if (p_format&ARRAY_COMPRESS_NORMAL) {
|
||||
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
uint8_t vector[4]={
|
||||
CLAMP(src[i].x*127,-128,127),
|
||||
CLAMP(src[i].y*127,-128,127),
|
||||
CLAMP(src[i].z*127,-128,127),
|
||||
0,
|
||||
};
|
||||
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], vector, 4);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
|
||||
float vector[3]={ src[i].x, src[i].y, src[i].z };
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], vector, 3*4);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} break;
|
||||
|
||||
case VS::ARRAY_TANGENT: {
|
||||
|
||||
ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER );
|
||||
|
||||
DVector<real_t> array = p_arrays[ai];
|
||||
|
||||
ERR_FAIL_COND_V( array.size() != p_vertex_array_len*4, ERR_INVALID_PARAMETER );
|
||||
|
||||
|
||||
DVector<real_t>::Read read = array.read();
|
||||
const real_t* src = read.ptr();
|
||||
|
||||
if (p_format&ARRAY_COMPRESS_TANGENT) {
|
||||
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
uint8_t xyzw[4]={
|
||||
CLAMP(src[i*4+0]*127,-128,127),
|
||||
CLAMP(src[i*4+1]*127,-128,127),
|
||||
CLAMP(src[i*4+2]*127,-128,127),
|
||||
CLAMP(src[i*4+3]*127,-128,127)
|
||||
};
|
||||
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], xyzw, 4);
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
float xyzw[4]={
|
||||
src[i*4+0],
|
||||
src[i*4+1],
|
||||
src[i*4+2],
|
||||
src[i*4+3]
|
||||
};
|
||||
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], xyzw, 4*4);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} break;
|
||||
case VS::ARRAY_COLOR: {
|
||||
|
||||
ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::COLOR_ARRAY, ERR_INVALID_PARAMETER );
|
||||
|
||||
|
||||
DVector<Color> array = p_arrays[ai];
|
||||
|
||||
ERR_FAIL_COND_V( array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER );
|
||||
|
||||
|
||||
DVector<Color>::Read read = array.read();
|
||||
const Color* src = read.ptr();
|
||||
|
||||
if (p_format&ARRAY_COMPRESS_COLOR) {
|
||||
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
|
||||
uint8_t colors[4];
|
||||
|
||||
for(int j=0;j<4;j++) {
|
||||
|
||||
colors[j]=CLAMP( int((src[i][j])*255.0), 0,255 );
|
||||
}
|
||||
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], colors, 4);
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], &src[i], 4*4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} break;
|
||||
case VS::ARRAY_TEX_UV: {
|
||||
|
||||
ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::VECTOR3_ARRAY && p_arrays[ai].get_type() != Variant::VECTOR2_ARRAY, ERR_INVALID_PARAMETER );
|
||||
|
||||
DVector<Vector2> array = p_arrays[ai];
|
||||
|
||||
ERR_FAIL_COND_V( array.size() != p_vertex_array_len , ERR_INVALID_PARAMETER);
|
||||
|
||||
DVector<Vector2>::Read read = array.read();
|
||||
|
||||
const Vector2 * src=read.ptr();
|
||||
|
||||
|
||||
|
||||
if (p_format&ARRAY_COMPRESS_TEX_UV) {
|
||||
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
uint16_t uv[2]={ Math::make_half_float(src[i].x) , Math::make_half_float(src[i].y) };
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], uv, 2*2);
|
||||
}
|
||||
|
||||
} else {
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
float uv[2]={ src[i].x , src[i].y };
|
||||
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], uv, 2*4);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} break;
|
||||
|
||||
case VS::ARRAY_TEX_UV2: {
|
||||
|
||||
|
||||
ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::VECTOR3_ARRAY && p_arrays[ai].get_type() != Variant::VECTOR2_ARRAY, ERR_INVALID_PARAMETER );
|
||||
|
||||
DVector<Vector2> array = p_arrays[ai];
|
||||
|
||||
ERR_FAIL_COND_V( array.size() != p_vertex_array_len , ERR_INVALID_PARAMETER);
|
||||
|
||||
DVector<Vector2>::Read read = array.read();
|
||||
|
||||
const Vector2 * src=read.ptr();
|
||||
|
||||
|
||||
|
||||
if (p_format&ARRAY_COMPRESS_TEX_UV2) {
|
||||
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
uint16_t uv[2]={ Math::make_half_float(src[i].x) , Math::make_half_float(src[i].y) };
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], uv, 2*2);
|
||||
}
|
||||
|
||||
} else {
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
float uv[2]={ src[i].x , src[i].y };
|
||||
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], uv, 2*4);
|
||||
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case VS::ARRAY_WEIGHTS: {
|
||||
|
||||
ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER );
|
||||
|
||||
DVector<real_t> array = p_arrays[ai];
|
||||
|
||||
ERR_FAIL_COND_V( array.size() != p_vertex_array_len*VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER );
|
||||
|
||||
|
||||
DVector<real_t>::Read read = array.read();
|
||||
|
||||
const real_t * src = read.ptr();
|
||||
|
||||
if (p_format&ARRAY_COMPRESS_WEIGHTS) {
|
||||
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
uint16_t data[VS::ARRAY_WEIGHTS_SIZE];
|
||||
for (int j=0;j<VS::ARRAY_WEIGHTS_SIZE;j++) {
|
||||
data[j]=CLAMP(src[i*VS::ARRAY_WEIGHTS_SIZE+j]*65535,0,65535);
|
||||
}
|
||||
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], data, 2*4);
|
||||
}
|
||||
} else {
|
||||
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
float data[VS::ARRAY_WEIGHTS_SIZE];
|
||||
for (int j=0;j<VS::ARRAY_WEIGHTS_SIZE;j++) {
|
||||
data[j]=src[i*VS::ARRAY_WEIGHTS_SIZE+j];
|
||||
}
|
||||
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], data, 4*4);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} break;
|
||||
case VS::ARRAY_BONES: {
|
||||
|
||||
ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER );
|
||||
|
||||
DVector<int> array = p_arrays[ai];
|
||||
|
||||
ERR_FAIL_COND_V( array.size() != p_vertex_array_len*VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER );
|
||||
|
||||
|
||||
DVector<int>::Read read = array.read();
|
||||
|
||||
const int * src = read.ptr();
|
||||
|
||||
|
||||
if (!(p_format&ARRAY_FLAG_USE_16_BIT_BONES)) {
|
||||
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
uint8_t data[VS::ARRAY_WEIGHTS_SIZE];
|
||||
for (int j=0;j<VS::ARRAY_WEIGHTS_SIZE;j++) {
|
||||
data[j]=CLAMP(src[i*VS::ARRAY_WEIGHTS_SIZE+j],0,255);
|
||||
max_bone=MAX(data[j],max_bone);
|
||||
|
||||
}
|
||||
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], data, 4);
|
||||
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
for (int i=0;i<p_vertex_array_len;i++) {
|
||||
|
||||
uint16_t data[VS::ARRAY_WEIGHTS_SIZE];
|
||||
for (int j=0;j<VS::ARRAY_WEIGHTS_SIZE;j++) {
|
||||
data[j]=src[i*VS::ARRAY_WEIGHTS_SIZE+j];
|
||||
max_bone=MAX(data[j],max_bone);
|
||||
|
||||
}
|
||||
|
||||
copymem(&vw[p_offsets[ai]+i*p_stride], data, 2*4);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} break;
|
||||
case VS::ARRAY_INDEX: {
|
||||
|
||||
|
||||
ERR_FAIL_COND_V( p_index_array_len<=0, ERR_INVALID_DATA );
|
||||
ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::INT_ARRAY, ERR_INVALID_PARAMETER );
|
||||
|
||||
DVector<int> indices = p_arrays[ai];
|
||||
ERR_FAIL_COND_V( indices.size() == 0, ERR_INVALID_PARAMETER );
|
||||
ERR_FAIL_COND_V( indices.size() != p_index_array_len, ERR_INVALID_PARAMETER );
|
||||
|
||||
/* determine wether using 16 or 32 bits indices */
|
||||
|
||||
DVector<int>::Read read = indices.read();
|
||||
const int *src=read.ptr();
|
||||
|
||||
for (int i=0;i<p_index_array_len;i++) {
|
||||
|
||||
|
||||
if (p_vertex_array_len<(1<<16)) {
|
||||
uint16_t v=src[i];
|
||||
|
||||
copymem(&iw[i*2], &v, 2);
|
||||
} else {
|
||||
uint32_t v=src[i];
|
||||
|
||||
copymem(&iw[i*4], &v, 4);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
ERR_FAIL_V( ERR_INVALID_DATA );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (p_format&VS::ARRAY_FORMAT_BONES) {
|
||||
//create AABBs for each detected bone
|
||||
int total_bones = max_bone+1;
|
||||
|
||||
bool first = r_bone_aabb.size()==0;
|
||||
|
||||
r_bone_aabb.resize(total_bones);
|
||||
|
||||
if (first) {
|
||||
for(int i=0;i<total_bones;i++) {
|
||||
r_bone_aabb[i].size==Vector3(-1,-1,-1); //negative means unused
|
||||
}
|
||||
}
|
||||
|
||||
DVector<Vector3> vertices = p_arrays[VS::ARRAY_VERTEX];
|
||||
DVector<int> bones = p_arrays[VS::ARRAY_BONES];
|
||||
DVector<float> weights = p_arrays[VS::ARRAY_WEIGHTS];
|
||||
|
||||
bool any_valid=false;
|
||||
|
||||
if (vertices.size() && bones.size()==vertices.size()*4 && weights.size()==bones.size()) {
|
||||
|
||||
int vs = vertices.size();
|
||||
DVector<Vector3>::Read rv =vertices.read();
|
||||
DVector<int>::Read rb=bones.read();
|
||||
DVector<float>::Read rw=weights.read();
|
||||
|
||||
AABB *bptr = r_bone_aabb.ptr();
|
||||
|
||||
for(int i=0;i<vs;i++) {
|
||||
|
||||
Vector3 v = rv[i];
|
||||
for(int j=0;j<4;j++) {
|
||||
|
||||
int idx = rb[i*4+j];
|
||||
float w = rw[i*4+j];
|
||||
if (w==0)
|
||||
continue;//break;
|
||||
ERR_FAIL_INDEX_V(idx,total_bones,ERR_INVALID_DATA);
|
||||
|
||||
if (bptr->size.x<0) {
|
||||
//first
|
||||
bptr[idx]=AABB();
|
||||
bptr[idx].pos=v;
|
||||
any_valid=true;
|
||||
} else {
|
||||
bptr[idx].expand_to(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!any_valid && first) {
|
||||
|
||||
r_bone_aabb.clear();
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
void VisualServer::mesh_add_surface_from_arrays(RID p_mesh,PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes,uint32_t p_compress_format) {
|
||||
|
||||
ERR_FAIL_INDEX( p_primitive, VS::PRIMITIVE_MAX );
|
||||
ERR_FAIL_COND(p_arrays.size()!=VS::ARRAY_MAX);
|
||||
|
||||
uint32_t format=0;
|
||||
|
||||
// validation
|
||||
int index_array_len=0;
|
||||
int array_len=0;
|
||||
|
||||
for(int i=0;i<p_arrays.size();i++) {
|
||||
|
||||
if (p_arrays[i].get_type()==Variant::NIL)
|
||||
continue;
|
||||
|
||||
format|=(1<<i);
|
||||
|
||||
if (i==VS::ARRAY_VERTEX) {
|
||||
|
||||
Variant var = p_arrays[i];
|
||||
switch(var.get_type()) {
|
||||
case Variant::VECTOR2_ARRAY: {
|
||||
DVector<Vector2> v2 = var;
|
||||
array_len=v2.size();
|
||||
} break;
|
||||
case Variant::VECTOR3_ARRAY: {
|
||||
DVector<Vector3> v3 = var;
|
||||
array_len=v3.size();
|
||||
} break;
|
||||
default: {
|
||||
Array v = var;
|
||||
array_len=v.size();
|
||||
} break;
|
||||
}
|
||||
|
||||
array_len=Vector3Array(p_arrays[i]).size();
|
||||
ERR_FAIL_COND(array_len==0);
|
||||
} else if (i==VS::ARRAY_INDEX) {
|
||||
|
||||
index_array_len=IntArray(p_arrays[i]).size();
|
||||
}
|
||||
}
|
||||
|
||||
ERR_FAIL_COND((format&VS::ARRAY_FORMAT_VERTEX)==0); // mandatory
|
||||
|
||||
|
||||
if (p_blend_shapes.size()) {
|
||||
//validate format for morphs
|
||||
for(int i=0;i<p_blend_shapes.size();i++) {
|
||||
|
||||
uint32_t bsformat=0;
|
||||
Array arr = p_blend_shapes[i];
|
||||
for(int j=0;j<arr.size();j++) {
|
||||
|
||||
|
||||
if (arr[j].get_type()!=Variant::NIL)
|
||||
bsformat|=(1<<j);
|
||||
}
|
||||
|
||||
ERR_FAIL_COND( (bsformat)!=(format&(VS::ARRAY_FORMAT_BONES-1)));
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t offsets[VS::ARRAY_MAX];
|
||||
|
||||
int total_elem_size=0;
|
||||
|
||||
for (int i=0;i<VS::ARRAY_MAX;i++) {
|
||||
|
||||
|
||||
offsets[i]=0; //reset
|
||||
|
||||
if (!(format&(1<<i))) // no array
|
||||
continue;
|
||||
|
||||
|
||||
int elem_size=0;
|
||||
|
||||
switch(i) {
|
||||
|
||||
case VS::ARRAY_VERTEX: {
|
||||
|
||||
Variant arr = p_arrays[0];
|
||||
if (arr.get_type()==Variant::VECTOR2_ARRAY) {
|
||||
elem_size=2;
|
||||
p_compress_format|=ARRAY_FLAG_USE_2D_VERTICES;
|
||||
} else if (arr.get_type()==Variant::VECTOR3_ARRAY) {
|
||||
p_compress_format&=~ARRAY_FLAG_USE_2D_VERTICES;
|
||||
elem_size=3;
|
||||
} else {
|
||||
elem_size=(p_compress_format&ARRAY_FLAG_USE_2D_VERTICES)?2:3;
|
||||
}
|
||||
|
||||
if (p_compress_format&ARRAY_COMPRESS_VERTEX) {
|
||||
elem_size*=sizeof(int16_t);
|
||||
} else {
|
||||
elem_size*=sizeof(float);
|
||||
}
|
||||
|
||||
} break;
|
||||
case VS::ARRAY_NORMAL: {
|
||||
|
||||
if (p_compress_format&ARRAY_COMPRESS_NORMAL) {
|
||||
elem_size=sizeof(uint32_t);
|
||||
} else {
|
||||
elem_size=sizeof(float)*3;
|
||||
}
|
||||
|
||||
} break;
|
||||
|
||||
case VS::ARRAY_TANGENT: {
|
||||
if (p_compress_format&ARRAY_COMPRESS_TANGENT) {
|
||||
elem_size=sizeof(uint32_t);
|
||||
} else {
|
||||
elem_size=sizeof(float)*4;
|
||||
}
|
||||
|
||||
} break;
|
||||
case VS::ARRAY_COLOR: {
|
||||
|
||||
if (p_compress_format&ARRAY_COMPRESS_COLOR) {
|
||||
elem_size=sizeof(uint32_t);
|
||||
} else {
|
||||
elem_size=sizeof(float)*4;
|
||||
}
|
||||
} break;
|
||||
case VS::ARRAY_TEX_UV: {
|
||||
if (p_compress_format&ARRAY_COMPRESS_TEX_UV) {
|
||||
elem_size=sizeof(uint32_t);
|
||||
} else {
|
||||
elem_size=sizeof(float)*2;
|
||||
}
|
||||
|
||||
} break;
|
||||
|
||||
case VS::ARRAY_TEX_UV2: {
|
||||
if (p_compress_format&ARRAY_COMPRESS_TEX_UV2) {
|
||||
elem_size=sizeof(uint32_t);
|
||||
} else {
|
||||
elem_size=sizeof(float)*2;
|
||||
}
|
||||
|
||||
} break;
|
||||
case VS::ARRAY_WEIGHTS: {
|
||||
|
||||
if (p_compress_format&ARRAY_COMPRESS_WEIGHTS) {
|
||||
elem_size=sizeof(uint16_t)*4;
|
||||
} else {
|
||||
elem_size=sizeof(float)*4;
|
||||
}
|
||||
|
||||
} break;
|
||||
case VS::ARRAY_BONES: {
|
||||
|
||||
if (p_compress_format&ARRAY_FLAG_USE_16_BIT_BONES) {
|
||||
elem_size=sizeof(uint32_t);
|
||||
} else {
|
||||
elem_size=sizeof(uint16_t)*4;
|
||||
}
|
||||
|
||||
} break;
|
||||
case VS::ARRAY_INDEX: {
|
||||
|
||||
if (index_array_len<=0) {
|
||||
ERR_PRINT("index_array_len==NO_INDEX_ARRAY");
|
||||
break;
|
||||
}
|
||||
/* determine wether using 16 or 32 bits indices */
|
||||
if (array_len>(1<<16)) {
|
||||
|
||||
elem_size=4;
|
||||
|
||||
} else {
|
||||
elem_size=2;
|
||||
}
|
||||
offsets[i]=elem_size;
|
||||
continue;
|
||||
} break;
|
||||
default: {
|
||||
ERR_FAIL( );
|
||||
}
|
||||
}
|
||||
|
||||
print_line("type "+itos(i)+" size: "+itos(elem_size)+" offset "+itos(total_elem_size));
|
||||
offsets[i]=total_elem_size;
|
||||
total_elem_size+=elem_size;
|
||||
|
||||
|
||||
}
|
||||
|
||||
print_line("total elemn size: "+itos(total_elem_size));
|
||||
|
||||
uint32_t mask = (1<<ARRAY_MAX)-1;
|
||||
format|=~mask&p_compress_format; //make the full format
|
||||
|
||||
|
||||
int array_size = total_elem_size * array_len;
|
||||
|
||||
print_line("array size: "+itos(array_size));
|
||||
|
||||
DVector<uint8_t> vertex_array;
|
||||
vertex_array.resize(array_size);
|
||||
|
||||
int index_array_size = offsets[VS::ARRAY_INDEX]*index_array_len;
|
||||
|
||||
print_line("index array size: "+itos(index_array_size));
|
||||
|
||||
DVector<uint8_t> index_array;
|
||||
index_array.resize(index_array_size);
|
||||
|
||||
AABB aabb;
|
||||
Vector<AABB> bone_aabb;
|
||||
|
||||
Error err = _surface_set_data(p_arrays,format,offsets,total_elem_size,vertex_array,array_len,index_array,index_array_len,aabb,bone_aabb);
|
||||
|
||||
if (err) {
|
||||
ERR_EXPLAIN("Invalid array format for surface");
|
||||
ERR_FAIL_COND(err!=OK);
|
||||
}
|
||||
|
||||
Vector<DVector<uint8_t> > blend_shape_data;
|
||||
|
||||
for(int i=0;i<p_blend_shapes.size();i++) {
|
||||
|
||||
DVector<uint8_t> vertex_array_shape;
|
||||
vertex_array_shape.resize(array_size);
|
||||
DVector<uint8_t> noindex;
|
||||
|
||||
AABB laabb;
|
||||
Error err = _surface_set_data(p_blend_shapes[i],format&~ARRAY_FORMAT_INDEX,offsets,total_elem_size,vertex_array,array_len,noindex,0,laabb,bone_aabb);
|
||||
aabb.merge_with(laabb);
|
||||
if (err) {
|
||||
ERR_EXPLAIN("Invalid blend shape array format for surface");
|
||||
ERR_FAIL_COND(err!=OK);
|
||||
}
|
||||
|
||||
blend_shape_data.push_back(vertex_array_shape);
|
||||
}
|
||||
|
||||
mesh_add_surface(p_mesh,format,p_primitive,vertex_array,array_len,index_array,index_array_len,aabb,blend_shape_data,bone_aabb);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,6 +59,9 @@ protected:
|
|||
RID test_material;
|
||||
RID material_2d[16];
|
||||
|
||||
|
||||
Error _surface_set_data(Array p_arrays,uint32_t p_format,uint32_t *p_offsets,uint32_t p_stride,DVector<uint8_t> &r_vertex_array,int p_vertex_array_len,DVector<uint8_t> &r_index_array,int p_index_array_len,AABB &r_aabb,Vector<AABB> r_bone_aabb);
|
||||
|
||||
static VisualServer* (*create_func)();
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
|
@ -207,6 +210,7 @@ public:
|
|||
ARRAY_COMPRESS_INDEX=1<<(ARRAY_INDEX+ARRAY_COMPRESS_BASE),
|
||||
|
||||
ARRAY_FLAG_USE_2D_VERTICES=ARRAY_COMPRESS_INDEX<<1,
|
||||
ARRAY_FLAG_USE_16_BIT_BONES=ARRAY_COMPRESS_INDEX<<2,
|
||||
|
||||
ARRAY_COMPRESS_DEFAULT=ARRAY_COMPRESS_VERTEX|ARRAY_COMPRESS_NORMAL|ARRAY_COMPRESS_TANGENT|ARRAY_COMPRESS_COLOR|ARRAY_COMPRESS_TEX_UV|ARRAY_COMPRESS_TEX_UV2|ARRAY_COMPRESS_BONES|ARRAY_COMPRESS_WEIGHTS|ARRAY_COMPRESS_INDEX
|
||||
|
||||
|
|
@ -228,7 +232,7 @@ public:
|
|||
|
||||
|
||||
virtual void mesh_add_surface_from_arrays(RID p_mesh,PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array(),uint32_t p_compress_format=ARRAY_COMPRESS_DEFAULT);
|
||||
virtual void mesh_add_surface(RID p_mesh,uint32_t p_format,PrimitiveType p_primitive,const DVector<uint8_t>& p_array,int p_vertex_count,const DVector<uint8_t>& p_index_array,int p_index_count,const Vector<DVector<uint8_t> >& p_blend_shapes=Vector<DVector<uint8_t> >())=0;
|
||||
virtual void mesh_add_surface(RID p_mesh,uint32_t p_format,PrimitiveType p_primitive,const DVector<uint8_t>& p_array,int p_vertex_count,const DVector<uint8_t>& p_index_array,int p_index_count,const AABB& p_aabb,const Vector<DVector<uint8_t> >& p_blend_shapes=Vector<DVector<uint8_t> >(),const Vector<AABB>& p_bone_aabbs=Vector<AABB>())=0;
|
||||
|
||||
virtual void mesh_set_morph_target_count(RID p_mesh,int p_amount)=0;
|
||||
virtual int mesh_get_morph_target_count(RID p_mesh) const=0;
|
||||
|
|
@ -530,7 +534,6 @@ public:
|
|||
|
||||
virtual void scenario_set_debug(RID p_scenario,ScenarioDebugMode p_debug_mode)=0;
|
||||
virtual void scenario_set_environment(RID p_scenario, RID p_environment)=0;
|
||||
virtual RID scenario_get_environment(RID p_scenario, RID p_environment) const=0;
|
||||
virtual void scenario_set_fallback_environment(RID p_scenario, RID p_environment)=0;
|
||||
|
||||
|
||||
|
|
@ -546,6 +549,7 @@ public:
|
|||
INSTANCE_REFLECTION_PROBE,
|
||||
INSTANCE_ROOM,
|
||||
INSTANCE_PORTAL,
|
||||
INSTANCE_MAX,
|
||||
/*INSTANCE_BAKED_LIGHT,
|
||||
INSTANCE_BAKED_LIGHT_SAMPLER,*/
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue