Index: trunk/src/core/random.cc
===================================================================
--- trunk/src/core/random.cc	(revision 508)
+++ trunk/src/core/random.cc	(revision 509)
@@ -271,4 +271,5 @@
 nv::random_base::seed_type nv::random_xor128::set_seed( seed_type seed /*= 0 */ )
 {
+	if ( seed == 0 ) seed = randomized_seed();
 	uint32 s = uint32( 4294967296 - seed );
 	m_state[0] = 123456789 * s;
Index: trunk/src/engine/animation.cc
===================================================================
--- trunk/src/engine/animation.cc	(revision 508)
+++ trunk/src/engine/animation.cc	(revision 509)
@@ -34,4 +34,5 @@
 
 	nv::animator_data* animator = new nv::animator_data;
+	animator->id = table.get_string64( "id" );
 	animator->poses = poses;
 	if ( poses == nullptr )
Index: trunk/src/engine/default_resource_manager.cc
===================================================================
--- trunk/src/engine/default_resource_manager.cc	(revision 508)
+++ trunk/src/engine/default_resource_manager.cc	(revision 509)
@@ -9,5 +9,5 @@
 using namespace nv;
 
-default_resource_manager::default_resource_manager( context* context )
+default_resource_manager::default_resource_manager( context* context, bool clear_material_paths )
 {
 	m_images        = register_resource_handler< image_data >( new image_manager );
@@ -15,5 +15,5 @@
 	m_binds         = register_resource_handler< animator_bind_data >( new animator_bind_manager );
 	m_animators     = register_resource_handler< animator_data >( new animator_manager );
-	m_materials     = register_resource_handler< material >( new material_manager );
+	m_materials     = register_resource_handler< material >( new material_manager( clear_material_paths ) );
 	m_programs      = register_resource_handler< program >( new program_manager( context ) );
 	m_gpu_meshes    = register_resource_handler< gpu_mesh >( new gpu_mesh_manager( context, m_meshes ) );
@@ -27,4 +27,19 @@
 	m_lua = lua;
 
+	m_lua->register_enum( "RND_LINEAR",     static_cast<int>( random_dist::LINEAR ) );
+	m_lua->register_enum( "RND_GAUSSIAN",   static_cast<int>( random_dist::GAUSSIAN ) );
+	m_lua->register_enum( "RND_RGAUSSIAN",  static_cast<int>( random_dist::RGAUSSIAN ) );
+	m_lua->register_enum( "RND_STEP_1",     static_cast<int>( random_dist::STEP_1 ) );
+	m_lua->register_enum( "RND_STEP_2",     static_cast<int>( random_dist::STEP_2 ) );
+	m_lua->register_enum( "RND_STEP_3",     static_cast<int>( random_dist::STEP_3 ) );
+	m_lua->register_enum( "RND_STEP_4",     static_cast<int>( random_dist::STEP_4 ) );
+	m_lua->register_enum( "RND_LINEAR",     static_cast<int>( random_dist::LINEAR ) );
+	m_lua->register_enum( "RND_MGAUSSIAN",  static_cast<int>( random_dist::MGAUSSIAN ) );
+	m_lua->register_enum( "RND_MRGAUSSIAN", static_cast<int>( random_dist::MRGAUSSIAN ) );
+	m_lua->register_enum( "RND_MSTEP_1",    static_cast<int>( random_dist::MSTEP_1 ) );
+	m_lua->register_enum( "RND_MSTEP_2",    static_cast<int>( random_dist::MSTEP_2 ) );
+	m_lua->register_enum( "RND_MSTEP_3",    static_cast<int>( random_dist::MSTEP_3 ) );
+	m_lua->register_enum( "RND_MSTEP_4",    static_cast<int>( random_dist::MSTEP_4 ) );
+	
 	m_lua->register_enum( "INT_NONE",       static_cast<int>( interpolation::NONE ) );
 	m_lua->register_enum( "INT_LINEAR",     static_cast<int>( interpolation::LINEAR ) );
Index: trunk/src/engine/material_manager.cc
===================================================================
--- trunk/src/engine/material_manager.cc	(revision 508)
+++ trunk/src/engine/material_manager.cc	(revision 509)
@@ -63,4 +63,5 @@
 	if ( table.is_string( "path" ) )
 	{
+		m->id = table.get_string128( "id" );
 		string128 path = table.get_string128( "path" );
 		for ( uint32 i = 0; i < 5; ++i )
@@ -77,5 +78,6 @@
 				if ( i != TEX_EMISSIVE )
 					NV_LOG_ERROR( "Texture file not found! : ", m->paths[i] );
-				//m->paths[i].clear();
+				if ( m_clear_paths )
+					m->paths[i].clear();
 			}
 		}
Index: trunk/src/engine/mesh_manager.cc
===================================================================
--- trunk/src/engine/mesh_manager.cc	(revision 508)
+++ trunk/src/engine/mesh_manager.cc	(revision 509)
@@ -114,4 +114,7 @@
 			result->node_names[(*nd)[i].name] = i;
 	}
+	
+	resource< mesh_data > rmesh = add( id, result );
+
 	for ( uint32 i = 0; i < loader->get_mesh_count(); ++i )
 	{
@@ -122,8 +125,8 @@
 		auto mesh = m_mesh_manager->add( shash64( id.get_hash() + i ), data );
 		result->meshes.push_back( mesh );
+		m_source_map[mesh.id()] = mesh_source{ rmesh, i };
 	}
+	result->path.assign( id );
 	delete loader;
-	if ( result )
-		add( id, result );
 	return result != nullptr;
 }
Index: trunk/src/engine/model_manager.cc
===================================================================
--- trunk/src/engine/model_manager.cc	(revision 508)
+++ trunk/src/engine/model_manager.cc	(revision 509)
@@ -13,8 +13,11 @@
 bool nv::model_manager::load_resource( lua::table_guard& table, shash64 id )
 {
+	auto vec4_to_quat = [] ( const vec4& v ) { return quat( v.w, v.x, v.y, v.z ); };
+
 	model* gm = new model;
 	gm->attach = table.get_string_hash_64( "attach" );
-	gm->root = transform( table.get<vec3>( "position", vec3() ) );
-
+	gm->root.set_position( table.get<vec3>( "root_position", vec3() ) );
+	gm->root.set_orientation( vec4_to_quat( table.get<vec4>( "root_orientation", vec4(0.0f,0.0f,0.0f,1.0f) ) ) );
+	
 	resource< mesh_data > def_data;
 	if ( table.is_string( "path" ) )
@@ -45,4 +48,6 @@
 void nv::model_manager::read_model_node( lua::table_guard& table, model_node* node, resource< mesh_data > def_data )
 {
+	auto vec4_to_quat = [] ( const vec4& v ) { return quat( v.w, v.x, v.y, v.z ); };
+
 	resource< data_channel_set > cmesh;
 	resource< material >         cmaterial;
@@ -59,4 +64,26 @@
 		attach_id = info.parent_id;
 	}
+
+	if ( table.has_field( "local_position" ) )
+		node->local.set_position( table.get<vec3>( "local_position", vec3() ) );
+	if ( table.has_field( "local_orientation" ) )
+		node->local.set_orientation( vec4_to_quat( table.get<vec4>( "local_orientation", vec4( 0.0f, 0.0f, 0.0f, 1.0f ) ) ) );
+
+	if ( table.has_field( "position" ) )
+	{
+		node->position.min = table.get<vec3>( "position", vec3() );
+		node->position.max = node->position.min;
+	}
+	if ( table.has_field( "rotation" ) )
+	{
+		node->rotation.min = table.get<vec3>( "rotation", vec3() );
+		node->rotation.max = node->rotation.min;
+	}
+	if ( table.has_field( "position_min" ) )  node->position.min  = table.get<vec3>( "position_min", vec3() );
+	if ( table.has_field( "position_max" ) )  node->position.max  = table.get<vec3>( "position_max", vec3() );
+	if ( table.has_field( "position_dist" ) ) node->position.dist = random_dist( table.get_unsigned( "position_dist", 0 ) );
+	if ( table.has_field( "rotation_min" ) )  node->rotation.min  = table.get<vec3>( "rotation_min", vec3() );
+	if ( table.has_field( "rotation_max" ) )  node->rotation.max  = table.get<vec3>( "rotation_max", vec3() );
+	if ( table.has_field( "rotation_dist" ) ) node->rotation.dist = random_dist( table.get_unsigned( "rotation_dist", 0 ) );
 
 	if ( table.has_field( "attach" ) )
@@ -76,11 +103,11 @@
 	}
 
-	node->force = table.get_boolean( "force", false );
-	node->chance = table.get_float( "chance", 1.0f );
-	node->random_rotate_y = table.get_boolean( "random_rotate", false );
-
-	node->mesh = cmesh;
+	node->force     = table.get_boolean( "force", false );
+	node->choice    = table.get_boolean( "choice", false );
+	node->chance    = table.get_float( "chance", 1.0f );
+	node->weight    = table.get_unsigned( "weight", 1 );
+	node->mesh      = cmesh;
 	node->attach_id = attach_id;
-	node->material = cmaterial;
+	node->material  = cmaterial;
 
 	for ( uint32 i = 1; i <= table.get_size(); ++i )
Index: trunk/src/gfx/debug_draw.cc
===================================================================
--- trunk/src/gfx/debug_draw.cc	(revision 508)
+++ trunk/src/gfx/debug_draw.cc	(revision 509)
@@ -86,4 +86,19 @@
 }
 
+void nv::debug_data::push_gizmo( const transform& tr, float length )
+{
+	vec3 s( 0.0f,   0.0f,   0.0f );
+	vec3 r( length, 0.0f,   0.0f );
+	vec3 g( 0.0f,   length, 0.0f );
+	vec3 b( 0.0f,   0.0f,   length );
+	s = s * tr;
+	r = r * tr;
+	g = g * tr;
+	b = b * tr;
+	push_line( s, r, vec3( 1.0f, 0.0f, 0.0f ) );
+	push_line( s, g, vec3( 0.0f, 1.0f, 0.0f ) );
+	push_line( s, b, vec3( 0.0f, 0.0f, 1.0f ) );
+}
+
 nv::debug_data::~debug_data()
 {
Index: trunk/src/lua/lua_state.cc
===================================================================
--- trunk/src/lua/lua_state.cc	(revision 508)
+++ trunk/src/lua/lua_state.cc	(revision 509)
@@ -324,4 +324,24 @@
 	return result;
 }
+
+nv::string64 nv::lua::table_guard::get_string64( string_view element, string_view defval /*= string_view() */ )
+{
+	lua_getfield( m_state, -1, element.data() );
+	size_t l = 0;
+	const char* str = nullptr;
+	if ( lua_type( m_state, -1 ) == LUA_TSTRING )
+	{
+		str = lua_tolstring( m_state, -1, &l );
+	}
+	else
+	{
+		l = defval.size();
+		str = defval.data();
+	}
+	string64 result( str, l );
+	lua_pop( m_state, 1 );
+	return result;
+}
+
 
 char lua::table_guard::get_char( string_view element, char defval /*= "" */ )
