mirror of
https://github.com/eliasstepanik/voxel-simulation.git
synced 2026-01-11 13:58:30 +00:00
Added Rotation and scale sync
This commit is contained in:
parent
8673ff7c88
commit
9442befb27
17
.idea/runConfigurations/PublishServer_OSX.xml
generated
Normal file
17
.idea/runConfigurations/PublishServer_OSX.xml
generated
Normal file
@ -0,0 +1,17 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="PublishServer OSX" type="ShConfigurationType">
|
||||
<option name="SCRIPT_TEXT" value="" />
|
||||
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
|
||||
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/publish_server.sh" />
|
||||
<option name="SCRIPT_OPTIONS" value="" />
|
||||
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
|
||||
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
|
||||
<option name="INTERPRETER_PATH" value="/bin/zsh" />
|
||||
<option name="INTERPRETER_OPTIONS" value="" />
|
||||
<option name="EXECUTE_IN_TERMINAL" value="true" />
|
||||
<option name="EXECUTE_SCRIPT_FILE" value="true" />
|
||||
<envs />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
17
.idea/runConfigurations/PublishServer_Win.xml
generated
Normal file
17
.idea/runConfigurations/PublishServer_Win.xml
generated
Normal file
@ -0,0 +1,17 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="PublishServer Win" type="ShConfigurationType">
|
||||
<option name="SCRIPT_TEXT" value="" />
|
||||
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
|
||||
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/publish_server.bat" />
|
||||
<option name="SCRIPT_OPTIONS" value="" />
|
||||
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
|
||||
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
|
||||
<option name="INTERPRETER_PATH" value="$PROJECT_DIR$/../../../../Windows/System32/WindowsPowerShell/v1.0/powershell.exe" />
|
||||
<option name="INTERPRETER_OPTIONS" value="" />
|
||||
<option name="EXECUTE_IN_TERMINAL" value="true" />
|
||||
<option name="EXECUTE_SCRIPT_FILE" value="true" />
|
||||
<envs />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
@ -6,7 +6,7 @@ use bevy_render::camera::{Exposure, PhysicalCameraParameters, Projection};
|
||||
use bevy_window::CursorGrabMode;
|
||||
use rand::Rng;
|
||||
use random_word::Lang;
|
||||
use crate::module_bindings::{set_name, set_position, spawn_entity, DbVector3};
|
||||
use crate::module_bindings::{set_name, set_position, spawn_entity, DbTransform, DbVector3, DbVector4};
|
||||
use crate::plugins::network::systems::database::DbConnectionResource;
|
||||
|
||||
#[derive(Component)]
|
||||
@ -117,10 +117,25 @@ pub fn camera_controller_system(
|
||||
}
|
||||
if keyboard_input.just_pressed(KeyCode::KeyE) {
|
||||
let rand_position = random_vec3(-10.0,10.0);
|
||||
ctx.0.reducers.spawn_entity(DbVector3{
|
||||
let rand_rotation = random_vec3(-10.0,10.0);
|
||||
let rand_scale = random_vec3(0.1,1.0);
|
||||
ctx.0.reducers.spawn_entity(DbTransform{
|
||||
position: DbVector3{
|
||||
x: rand_position.x,
|
||||
y: rand_position.y,
|
||||
z: rand_position.z,
|
||||
},
|
||||
rotation: DbVector4 {
|
||||
x: rand_rotation.x,
|
||||
y: rand_rotation.y,
|
||||
z: rand_position.z,
|
||||
w: 0.0,
|
||||
},
|
||||
scale: DbVector3 {
|
||||
x: rand_scale.x,
|
||||
y: rand_scale.x,
|
||||
z: rand_scale.x,
|
||||
},
|
||||
}).unwrap();
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use std::collections::HashSet;
|
||||
use bevy::math::Vec3;
|
||||
use bevy::pbr::{MeshMaterial3d, StandardMaterial};
|
||||
use bevy::prelude::{default, Bundle, Commands, Component, Cuboid, DespawnRecursiveExt, Entity, GlobalTransform, Mesh, Query, Res, ResMut, Sphere, Transform};
|
||||
use bevy::prelude::{default, Bundle, Commands, Component, Cuboid, DespawnRecursiveExt, Entity, GlobalTransform, Mesh, Quat, Query, Res, ResMut, Sphere, Transform};
|
||||
use bevy_asset::Assets;
|
||||
use bevy_reflect::Reflect;
|
||||
use bevy_render::mesh::Mesh3d;
|
||||
@ -33,11 +33,7 @@ pub fn init(mut commands: Commands,
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::default()),),
|
||||
MeshMaterial3d(debug_material.clone ()),
|
||||
Transform::from_xyz(
|
||||
entity.transform.position.x,
|
||||
entity.transform.position.y,
|
||||
entity.transform.position.z,
|
||||
),
|
||||
db_transfrom_to_transfrom(entity.transform.clone()),
|
||||
EntityDto{
|
||||
entity_id: entity.entity_id,
|
||||
transform: entity.transform
|
||||
@ -97,12 +93,7 @@ pub fn sync_entities_system(
|
||||
};
|
||||
|
||||
commands.spawn((
|
||||
|
||||
Transform::from_xyz(
|
||||
db_entity.transform.position.x,
|
||||
db_entity.transform.position.y,
|
||||
db_entity.transform.position.z,
|
||||
),
|
||||
db_transfrom_to_transfrom(db_entity.transform.clone()),
|
||||
GlobalTransform::default(),
|
||||
entity_type,
|
||||
MeshMaterial3d(debug_material),
|
||||
@ -123,3 +114,24 @@ pub fn sync_entities_system(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn db_transfrom_to_transfrom(db_transform: DbTransform) -> Transform{
|
||||
Transform::from_xyz(
|
||||
db_transform.position.x,
|
||||
db_transform.position.y,
|
||||
db_transform.position.z,
|
||||
).with_rotation(
|
||||
Quat::from_xyzw(
|
||||
db_transform.rotation.x,
|
||||
db_transform.rotation.y,
|
||||
db_transform.rotation.z,
|
||||
db_transform.rotation.w
|
||||
)
|
||||
).with_scale(
|
||||
Vec3::new(
|
||||
db_transform.scale.x,
|
||||
db_transform.scale.y,
|
||||
db_transform.scale.z,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@ -24,16 +24,11 @@ pub enum EntityType {
|
||||
|
||||
|
||||
#[spacetimedb::reducer]
|
||||
pub fn spawn_entity(ctx: &ReducerContext, position: DbVector3) -> Result<(), String> {
|
||||
pub fn spawn_entity(ctx: &ReducerContext, transform: DbTransform) -> Result<(), String> {
|
||||
|
||||
ctx.db.entity().try_insert(Entity {
|
||||
entity_id: 0,
|
||||
transform: DbTransform{
|
||||
position: position,
|
||||
rotation: DBVector4{x: 0.0, y: 0.0, z: 0.0, w: 1.0},
|
||||
scale: DbVector3 {x: 1.0, y: 1.0, z: 1.0 },
|
||||
|
||||
},
|
||||
transform,
|
||||
entity_type: EntityType::Cube,
|
||||
}).expect("TODO: panic message");
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user