This commit is contained in:
CortexCore 2023-06-12 15:51:41 +08:00
parent 118c28b187
commit 983cf15fa2
38 changed files with 2118 additions and 0 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf

2
.gitignore vendored
View File

@ -508,3 +508,5 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
# Custom
.idea

BIN
Maps/BaseMap.blend Normal file

Binary file not shown.

338
Maps/Prototype.tscn Normal file

File diff suppressed because one or more lines are too long

25
Maps/new_environment.tres Normal file
View File

@ -0,0 +1,25 @@
[gd_resource type="Environment" load_steps=3 format=3 uid="uid://jt4uyj7mecg4"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_1vmev"]
sky_top_color = Color(0.576471, 0.643137, 0.737255, 1)
sky_horizon_color = Color(0.784314, 0.792157, 0.803922, 1)
ground_bottom_color = Color(0.741176, 0.67451, 0.603922, 1)
[sub_resource type="Sky" id="Sky_8nvpi"]
sky_material = SubResource("ProceduralSkyMaterial_1vmev")
[resource]
background_mode = 2
sky = SubResource("Sky_8nvpi")
ambient_light_source = 3
reflected_light_source = 2
ssr_enabled = true
ssao_enabled = true
ssil_enabled = true
sdfgi_enabled = true
sdfgi_use_occlusion = true
glow_enabled = true
glow_normalized = true
volumetric_fog_enabled = true
adjustment_enabled = true
adjustment_brightness = 0.92

View File

@ -0,0 +1,3 @@
[gd_resource type="StandardMaterial3D" format=3 uid="uid://ccj62rvm47ihr"]
[resource]

View File

@ -0,0 +1,7 @@
[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://bs65ykt5pdvb1"]
[ext_resource type="Texture2D" uid="uid://lxp5hqmmunyg" path="res://Textures/GridBox_Default.png" id="1_lpx43"]
[resource]
albedo_texture = ExtResource("1_lpx43")
albedo_texture_force_srgb = true

115
Models/BaseGround.dae Normal file
View File

@ -0,0 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<asset>
<contributor>
<author>Blender User</author>
<authoring_tool>Blender 3.5.1 commit date:2023-04-24, commit time:18:11, hash:e1ccd9d4a1d3</authoring_tool>
</contributor>
<created>2023-06-09T14:40:15</created>
<modified>2023-06-09T14:40:15</modified>
<unit name="meter" meter="1"/>
<up_axis>Z_UP</up_axis>
</asset>
<library_effects>
<effect id="Material-effect">
<profile_COMMON>
<newparam sid="GridBox_Default_png-surface">
<surface type="2D">
<init_from>GridBox_Default_png</init_from>
</surface>
</newparam>
<newparam sid="GridBox_Default_png-sampler">
<sampler2D>
<source>GridBox_Default_png-surface</source>
</sampler2D>
</newparam>
<technique sid="common">
<lambert>
<emission>
<color sid="emission">0 0 0 1</color>
</emission>
<diffuse>
<texture texture="GridBox_Default_png-sampler" texcoord="UV 贴图"/>
</diffuse>
<index_of_refraction>
<float sid="ior">1.45</float>
</index_of_refraction>
</lambert>
</technique>
</profile_COMMON>
</effect>
</library_effects>
<library_images>
<image id="GridBox_Default_png" name="GridBox_Default_png">
<init_from>GridBox_Default.png</init_from>
</image>
</library_images>
<library_materials>
<material id="Material-material" name="Material">
<instance_effect url="#Material-effect"/>
</material>
</library_materials>
<library_geometries>
<geometry id="平面-mesh" name="平面">
<mesh>
<source id="平面-mesh-positions">
<float_array id="平面-mesh-positions-array" count="12">-32 -32 0 32 -32 0 -32 32 0 32 32 0</float_array>
<technique_common>
<accessor source="#平面-mesh-positions-array" count="4" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="平面-mesh-normals">
<float_array id="平面-mesh-normals-array" count="3">0 0 1</float_array>
<technique_common>
<accessor source="#平面-mesh-normals-array" count="1" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="平面-mesh-map-0">
<float_array id="平面-mesh-map-0-array" count="12">32.5 -31.5 -31.5 32.5 -31.5 -31.5 32.5 -31.5 32.5 32.5 -31.5 32.5</float_array>
<technique_common>
<accessor source="#平面-mesh-map-0-array" count="6" stride="2">
<param name="S" type="float"/>
<param name="T" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="平面-mesh-vertices">
<input semantic="POSITION" source="#平面-mesh-positions"/>
</vertices>
<triangles material="Material-material" count="2">
<input semantic="VERTEX" source="#平面-mesh-vertices" offset="0"/>
<input semantic="NORMAL" source="#平面-mesh-normals" offset="1"/>
<input semantic="TEXCOORD" source="#平面-mesh-map-0" offset="2" set="1"/>
<p>1 0 0 2 0 1 0 0 2 1 0 3 3 0 4 2 0 5</p>
</triangles>
</mesh>
</geometry>
</library_geometries>
<library_visual_scenes>
<visual_scene id="Scene" name="Scene">
<node id="平面" name="平面" type="NODE">
<matrix sid="transform">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</matrix>
<instance_geometry url="#平面-mesh" name="平面">
<bind_material>
<technique_common>
<instance_material symbol="Material-material" target="#Material-material">
<bind_vertex_input semantic="UV 贴图" input_semantic="TEXCOORD" input_set="0"/>
</instance_material>
</technique_common>
</bind_material>
</instance_geometry>
</node>
</visual_scene>
</library_visual_scenes>
<scene>
<instance_visual_scene url="#Scene"/>
</scene>
</COLLADA>

View File

@ -0,0 +1,44 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://df10ceig3k8xr"
path="res://.godot/imported/BaseGround.dae-611612c19afadee73de0d17a2bea7c34.scn"
[deps]
source_file="res://Models/BaseGround.dae"
dest_files=["res://.godot/imported/BaseGround.dae-611612c19afadee73de0d17a2bea7c34.scn"]
[params]
nodes/root_type="Node3D"
nodes/root_name="Scene Root"
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={
"materials": {
"Material": {
"use_external/enabled": true,
"use_external/path": "res://Materials/Material_Grid_New.tres"
}
},
"nodes": {
"PATH:AnimationPlayer": {
"import/skip_import": true
}
}
}
gltf/embedded_image_handling=1

BIN
Models/BaseMap.blend Normal file

Binary file not shown.

BIN
Models/BaseMap.fbx Normal file

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,39 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://cfdqixhj2v06e"
path="res://.godot/imported/Model_SR7CL11.glb-bb57721fed64524642e9fdda3d1ee173.scn"
[deps]
source_file="res://Models/机械臂/Model_SR7CL11.glb"
dest_files=["res://.godot/imported/Model_SR7CL11.glb-bb57721fed64524642e9fdda3d1ee173.scn"]
[params]
nodes/root_type="Node3D"
nodes/root_name="Scene Root"
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={
"materials": {
"Material_White": {
"use_external/enabled": true,
"use_external/path": "res://Materials/Material_Base_Aluminium.tres"
}
}
}
gltf/embedded_image_handling=1

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,32 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://dx56b8ycucqlr"
path="res://.godot/imported/机械臂.dae-d4ece1c8686a1ebbede58311647b817c.scn"
[deps]
source_file="res://Models/机械臂/机械臂.dae"
dest_files=["res://.godot/imported/机械臂.dae-d4ece1c8686a1ebbede58311647b817c.scn"]
[params]
nodes/root_type="Node3D"
nodes/root_name="Scene Root"
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={}
gltf/embedded_image_handling=1

View File

@ -0,0 +1,48 @@
using System.Collections.Generic;
using System.Linq;
using Godot;
namespace BITKit;
/// <summary>
/// 摄像头服务该服务需要加载到Camera3D节点中
/// </summary>
public partial class CameraService:Camera3D
{
/// <summary>
/// 场景中所有的摄像头
/// </summary>
private static readonly List<IVirtualCamera> _cameras=new();
/// <summary>
/// 当前已激活的摄像头
/// </summary>
public static IVirtualCamera ActiveCamera { get; private set; }
/// <summary>
/// 注册摄像头
/// </summary>
/// <param name="camera">摄像头</param>
/// <returns></returns>
public static bool Register(IVirtualCamera camera) => _cameras.TryAdd(camera);
/// <summary>
/// 注销摄像头
/// </summary>
/// <param name="camera">摄像头</param>
/// <returns></returns>
public static bool UnRegister(IVirtualCamera camera) => _cameras.TryRemove(camera);
/// <summary>
/// 处理摄像头的位置
/// </summary>
/// <param name="delta"></param>
public override void _Process(double delta)
{
//获取所有已启用的相机并加载一个虚拟相机的数据
foreach (var x in _cameras.Where(x => x.IsEnabled))
{
//应用相机坐标
Position = x.Position;
//应用相机角度
Rotation = x.Rotation.GetEuler();
//已加载相机位置,退出循环
break;
}
}
}

View File

@ -0,0 +1,58 @@
using Godot;
namespace BITKit;
/// <summary>
/// 虚拟相机接口定义
/// </summary>
public interface IVirtualCamera:IActivable
{
/// <summary>
/// 相机的FOV
/// </summary>
int FOV { get; }
/// <summary>
/// 相机是否已启用
/// </summary>
bool IsEnabled { get; }
/// <summary>
/// 相机坐标
/// </summary>
Vector3 Position { get; }
/// <summary>
/// 相机旋转
/// </summary>
Quaternion Rotation { get; }
}
/// <summary>
/// 基于Node3D的包括基础功能的虚拟相机
/// </summary>
public partial class VirtualCamera : Node3D, IVirtualCamera
{
[Export] private int fov;
[Export] private bool isEnabled;
public int FOV => fov;
public bool IsEnabled => isEnabled;
Vector3 IVirtualCamera.Position => GlobalPosition;
Quaternion IVirtualCamera.Rotation => Quaternion.FromEuler(GlobalRotation);
public void SetActive(bool active)
{
isEnabled = active;
}
public override void _Ready()
{
CameraService.Register(this);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
CameraService.UnRegister(this);
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using Godot;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using HttpClient = System.Net.Http.HttpClient;
namespace BITKit;
/// <summary>
/// 为Godot提供的BITApp加载服务
/// </summary>
public partial class BITAppForGodot : Node
{
/// <summary>
/// 依赖服务集合
/// </summary>
public static ServiceCollection ServiceCollection { get; private set; } = new();
/// <summary>
/// 依赖服务提供接口
/// </summary>
public static ServiceProvider ServiceProvider { get; private set; }
/// <summary>
/// 在构造函数中注册Logger
/// </summary>
public BITAppForGodot()
{
BIT4Log.OnLog += GD.Print;
BIT4Log.OnWarning += GD.PushWarning;
BIT4Log.OnNextLine += () => GD.Print();
BIT4Log.OnException += x=>GD.PrintErr(x.ToString());
//启动BITApp
BITApp.Start();
BIT4Log.Log<BITAppForGodot>("已创建BITApp");
}
public override async void _Ready()
{
BIT4Log.Log<BITAppForGodot>("正在创建BITWebApp");
//添加测试用HttpClient
ServiceCollection.AddSingleton<HttpClient>();
//构造依赖服务提供接口
ServiceProvider = ServiceCollection.BuildServiceProvider();
}
protected override void Dispose(bool disposing)
{
#pragma warning disable CS4014
//停止BITApp
BITApp.Stop();
#pragma warning restore CS4014
BIT4Log.Log<BITAppForGodot>("已安全退出App");
}
}

View File

@ -0,0 +1,56 @@
using Godot;
namespace BITKit;
/// <summary>
/// 固定间隔工具,用于控制执行速率
/// </summary>
[System.Serializable]
public class IntervalTimer
{
public IntervalTimer()
{
}
/// <summary>
/// 在构造函数中声明间隔时间
/// </summary>
/// <param name="interval"></param>
public IntervalTimer(ulong interval)
{
this.interval = interval;
}
/// <summary>
/// 间隔时间
/// </summary>
private readonly ulong interval;
/// <summary>
/// 可以执行的事件
/// </summary>
private ulong allowTime;
/// <summary>
/// 是否可以执行(执行重置间隔)
/// </summary>
public bool Allow
{
get
{
if (allowTime >= Time.GetTicksMsec()) return false;
Release();
return true;
}
}
/// <summary>
/// 是否可以执行(不会执行重置间隔)
/// </summary>
public bool AllowWithoutRelease => allowTime >= Time.GetTicksMsec();
/// <summary>
/// 重置执行间隔
/// </summary>
/// <param name="immediately">是否可以立即执行</param>
public void Release(bool immediately=false)
{
var currentTime = Time.GetTicksMsec();
allowTime = immediately ? currentTime : currentTime + interval*1000;
}
}

77
Scripts/ECS/Entity.cs Normal file
View File

@ -0,0 +1,77 @@
using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
using BITKit.Core.Entites;
namespace BITKit;
/// <summary>
/// 用于Godot的ECS.Entity实现
/// </summary>
public partial class Entity : Node,IEntity
{
/// <summary>
/// 类型组件的缓存
/// </summary>
private readonly Dictionary<Type,IEntityComponent> TypeComponents=new ();
/// <summary>
/// IEntityService的缓存
/// </summary>
private IEntitiesService _entitiesService;
/// <summary>
/// 所有EntityComponent
/// </summary>
private IEntityComponent[] _components;
IEntityComponent[] IEntity.Components => _components;
/// <summary>
/// IEntity.Id实现
/// </summary>
public ulong Id { get; private set; }
/// <summary>
/// 加载所有EntityComponent的内部实现
/// </summary>
public override void _Ready()
{
List<IEntityComponent> entityComponents = new();
Id = GetInstanceId();
_entitiesService = DI.Get<IEntitiesService>();
foreach (var x in MathNode.GetAllNode(this))
{
GetInstanceId();
if (x is not IEntityComponent component) continue;
component.Entity = this;
TypeComponents.TryAdd(x.GetType(),component);
BIT4Log.Log<Entity>($"已加载组件:{x.Name}");
component.OnAwake();
entityComponents.Add(component);
}
foreach (var component in TypeComponents.Values)
{
component.OnStart();
}
_entitiesService.Register(this);
this._components = entityComponents.ToArray();
}
public bool TryGetComponent<T>(out T component) where T : IEntityComponent
{
if (TypeComponents.TryGetValue(typeof(T), out var iComponent) && iComponent is T _component)
{
component = _component;
return true;
}
component = default;
return false;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_entitiesService.UnRegister(this);
}
}
public bool RegisterComponent<T>(T component) where T : IEntityComponent
{
return TypeComponents.TryAdd(typeof(T), component);
}
}

View File

@ -0,0 +1,13 @@
using BITKit.Core.Entites;
using Godot;
namespace BITKit;
/// <summary>
/// 基于Godot.Node3D的IEntityComponent实现
/// </summary>
public partial class EntityComponent : Node3D,IEntityComponent
{
public IEntity Entity { get; set; }
public virtual void OnStart(){}
public virtual void OnAwake(){}
}

View File

@ -0,0 +1,42 @@
using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using BITKit.Core.Entites;
// ReSharper disable All
namespace BITKit;
/// <summary>
/// 基于Godot.Node的IEntitiesService实现
/// </summary>
public partial class GodotEntitiesService : Node,IEntitiesService
{
public GodotEntitiesService()
{
DI.Register<IEntitiesService>(this);
}
private readonly Dictionary<ulong,IEntity> _entities=new ();
private CancellationTokenSource _cancellationTokenSource;
public IEntity[] Entities => _entities.Values.ToArray();
public bool Register(IEntity entity)
{
return _entities.TryAdd(entity.Id, entity);
}
public bool UnRegister(IEntity entity)
{
return _entities.TryRemove(entity.Id);
}
public override void _Ready()
{
_cancellationTokenSource = new();
}
protected override void Dispose(bool disposing)
{
if(disposing)_cancellationTokenSource.Cancel();
}
public CancellationToken CancellationToken => _cancellationTokenSource.Token;
}

View File

@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.Linq;
using Godot;
namespace BITKit;
/// <summary>
/// 为Godot.Node提供数学工具
/// </summary>
public static partial class MathNode
{
/// <summary>
/// 获取Node下所有的子Node节点
/// </summary>
/// <param name="self">Root Node</param>
/// <returns></returns>
public static IEnumerable<Node> GetAllNode(Node self)
{
List<Node> nodes = new() { self };
For(self);
void For(Node node)
{
foreach (var x in node.GetChildren())
{
For(x);
nodes.Add(x);
}
}
return nodes.Distinct();
}
}

View File

@ -0,0 +1,12 @@
using Godot;
namespace BITKit;
/// <summary>
/// ECS的Id组件用于提供Id
/// </summary>
public partial class IdComponent:EntityComponent
{
[Export]
public string Id;
}

View File

@ -0,0 +1,16 @@
using Godot;
using RosBridgeClient;
using RosSharp.RosBridgeClient.Protocols;
namespace BITKit;
/// <summary>
/// 使用Godot.Node作为容器的RosClient
/// </summary>
public partial class ROSClientService : Node
{
public override void _Ready()
{
WebSocketNetProtocol protocol = new("ws://");
RosSharp.RosBridgeClient.RosSocket client = new(protocol);
}
}

View File

@ -0,0 +1,30 @@
using Godot;
namespace BITKit;
/// <summary>
/// ECS中iFactory.Rotation的角度组件
/// </summary>
public partial class RotationComponent : EntityComponent
{
/// <summary>
/// 获取角度的路径
/// </summary>
[Export] public string Path { get; private set; }
/// <summary>
/// 角度的绝对权重例如90*0,0,1 = 0,0,90
/// </summary>
[Export] public Vector3 Weight { get; private set; }
/// <summary>
/// 角度的相对偏移
/// </summary>
[Export] public Vector3 Offset { get; private set; }
/// <summary>
/// 默认角度的缓存
/// </summary>
public Vector3 OriginalEuler { get; private set; }
public override void _Ready()
{
//保存默认角度
OriginalEuler = Rotation;
}
}

View File

@ -0,0 +1,168 @@
using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using BITKit.Core.Entites;
using Cysharp.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace BITKit;
/// <summary>
/// 单例SCADA Service,从http接口获取json后解析为指定数据
/// </summary>
public partial class SCADAService : Node
{
/// <summary>
/// 在构造函数中注入依赖
/// </summary>
public SCADAService()
{
BITAppForGodot.ServiceCollection.AddSingleton(this);
}
/// <summary>
/// 获取json的Url
/// </summary>
[Export]
private string url;
/// <summary>
/// 是否固定控制的Entity如果固定只会刷新一次如果不固定每帧都会刷新
/// </summary>
[Export]
private bool fixedEntities;
/// <summary>
/// 已加载的Entity
/// </summary>
private readonly Dictionary<string, IEntity> _entities = new();
/// <summary>
/// 最大并行请求数量
/// </summary>
private readonly LimitTimes requestRate =new (1);
/// <summary>
/// 请求数据的间隔
/// </summary>
private readonly IntervalTimer _intervalTimer = new(1);
/// <summary>
/// 取消令牌用于取消Http Get
/// </summary>
private CancellationToken _cancellationToken;
/// <summary>
/// http客户端
/// </summary>
private System.Net.Http.HttpClient httpClient;
/// <summary>
/// 获取Entity并加载依赖
/// </summary>
public override async void _Ready()
{
_cancellationToken = new CancellationToken();
if (!fixedEntities) return;
await UniTask.Yield();
LoadAllEntities();
BIT4Log.Log<SCADAService>($"已加载{_entities.Count}个设备");
httpClient = BITAppForGodot.ServiceProvider.GetService<System.Net.Http.HttpClient>();
}
/// <summary>
/// 内部方法从EntityService加载所有Entity
/// </summary>
private void LoadAllEntities()
{
foreach (var entity in DI.Get<IEntitiesService>().Entities)
{
if (entity.TryGetComponent<IdComponent>(out var deviceComponent))
{
_entities.Add(deviceComponent.Id,deviceComponent.Entity);
}
}
}
/// <summary>
/// 物理帧用于控制并发和间隔的同时请求数据
/// </summary>
/// <param name="delta"></param>
public override void _PhysicsProcess(double delta)
{
//依赖加载
httpClient ??= BITAppForGodot.ServiceProvider.GetService<System.Net.Http.HttpClient>();
//请求间隔控制+请求并发控制+检查依赖是否为Null
if (_intervalTimer.Allow && requestRate && httpClient is not null)
{
//发送请求
Request();
}
}
/// <summary>
/// 从http请求json
/// </summary>
private async void Request()
{
//获取json
var json =await httpClient.GetStringAsync(url, _cancellationToken);
try
{
//取消执行,如果已取消令牌
_cancellationToken.ThrowIfCancellationRequested();
}
catch (OperationCanceledException)
{
//返回并发数量
requestRate.Release();
return;
}
//返回并发数量
requestRate.Release();
//处理json
ProcessJson(json);
}
/// <summary>
/// 解析json
/// </summary>
/// <param name="json">从SCADA获取的Json</param>
private void ProcessJson(string json)
{
//首先从result中获取数组
var jArray = JsonConvert.DeserializeObject<JObject>(json)["result"]!.ToObject<JArray>();
//然后遍历所有数组的内容
foreach (var element in jArray)
{
//获取数组元素的Id
var id = element["id"]!.ToObject<string>();
//通过Id查找已加载的Entity
if (!_entities.TryGetValue(id, out var entity)) continue;
//加载数组中的"value"为json
var _json = element["value"]!.ToObject<string>();
//获取被加载为string的json
var obj = Json.ParseString(_json);
//反序列化string为原始json
var value = JObject.Parse(obj.ToString());
//提交json和entity
ProcessEntity(value,entity);
}
}
/// <summary>
/// 提交jObject数据和Entity进行解析和处理
/// </summary>
/// <param name="jObject">json [result] [0] [value] 中的原始json</param>
/// <param name="entity">引用实体如PLC-ZL</param>
private static void ProcessEntity(JObject jObject, IEntity entity)
{
//从Entity中加载所有Rotation Component
var rotationComponents = entity
.Components
.Where(x => x is RotationComponent)
.Select((x => (RotationComponent)x));
//遍历所有Rotation Component
foreach (var rotationComponent in rotationComponents)
{
//加载rotation需要的path,如 var angle = value["J1"]
var path = rotationComponent.Path;
//加载以获取到的角度
var currentAngle = jObject[path]!.ToObject<float>();
//最终角度 = 当前角度*角度权重 + 角度偏移 + 原始角度
var euler = currentAngle * rotationComponent.Weight + rotationComponent.Offset + rotationComponent.OriginalEuler;
//为Node3D.Rotation提交最后的角度计算结果
rotationComponent.Rotation = euler;
}
}
}

15
Services/Framework.tscn Normal file
View File

@ -0,0 +1,15 @@
[gd_scene load_steps=4 format=3 uid="uid://b2kkx25rbmq5q"]
[ext_resource type="Script" path="res://Scripts/Core/BITAppForGodot.cs" id="1_6djgg"]
[ext_resource type="Script" path="res://Scripts/ECS/GodotEntitiesService.cs" id="2_clugd"]
[ext_resource type="Script" path="res://Scripts/Factory/SCADAService.cs" id="3_ty1uc"]
[node name="Framework" type="Node"]
script = ExtResource("1_6djgg")
[node name="EntitiesManager" type="Node" parent="."]
script = ExtResource("2_clugd")
[node name="SCADAService" type="Node" parent="."]
script = ExtResource("3_ty1uc")
fixedEntities = true

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://lxp5hqmmunyg"
path.s3tc="res://.godot/imported/GridBox_Default.png-921cd0022ac15cc9e2634b8da6677424.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://Textures/GridBox_Default.png"
dest_files=["res://.godot/imported/GridBox_Default.png-921cd0022ac15cc9e2634b8da6677424.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

View File

@ -0,0 +1,19 @@
#if TOOLS
using Godot;
using System;
namespace BITKit;
[Tool]
public partial class RefencePlugin : EditorPlugin
{
public override void _EnterTree()
{
// Initialization of the plugin goes here.
}
public override void _ExitTree()
{
// Clean-up of the plugin goes here.
}
}
#endif

View File

@ -0,0 +1,7 @@
[plugin]
name="BITPlugins"
description="BITKit为Godot支持的插件 "
author="军火商小火柴"
version=""
script="RefencePlugin.cs"

9
appsettings.json Normal file
View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

22
iFactory.csproj Normal file
View File

@ -0,0 +1,22 @@
<Project Sdk="Godot.NET.Sdk/4.0.3">
<PropertyGroup>
<EnableDynamicLoading>true</EnableDynamicLoading>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AGV_System\Vol.Net6\RosBridgeClient\RosBridgeClient.csproj" />
<ProjectReference Include="..\BITKit\BITKit.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Remove="WebApplication\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0-preview.4.23259.5" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0-preview.4.23259.5" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Configuration.ConfigurationManager">
<HintPath>Lib\System.Configuration.ConfigurationManager.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

35
iFactory.sln Normal file
View File

@ -0,0 +1,35 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "iFactory", "iFactory.csproj", "{CC5E0EEB-F4D7-4F3C-85EE-EE6AA1B080EF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BITKit", "..\BITKit\BITKit.csproj", "{81C8377E-1A22-488B-A1F5-1CA61C70C0F1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RosBridgeClient", "..\AGV_System\Vol.Net6\RosBridgeClient\RosBridgeClient.csproj", "{D00A3B38-295F-4C0B-933A-12620142284F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
ExportDebug|Any CPU = ExportDebug|Any CPU
ExportRelease|Any CPU = ExportRelease|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CC5E0EEB-F4D7-4F3C-85EE-EE6AA1B080EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CC5E0EEB-F4D7-4F3C-85EE-EE6AA1B080EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC5E0EEB-F4D7-4F3C-85EE-EE6AA1B080EF}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU
{CC5E0EEB-F4D7-4F3C-85EE-EE6AA1B080EF}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU
{CC5E0EEB-F4D7-4F3C-85EE-EE6AA1B080EF}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU
{CC5E0EEB-F4D7-4F3C-85EE-EE6AA1B080EF}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU
{81C8377E-1A22-488B-A1F5-1CA61C70C0F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{81C8377E-1A22-488B-A1F5-1CA61C70C0F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{81C8377E-1A22-488B-A1F5-1CA61C70C0F1}.ExportDebug|Any CPU.ActiveCfg = Debug|Any CPU
{81C8377E-1A22-488B-A1F5-1CA61C70C0F1}.ExportDebug|Any CPU.Build.0 = Debug|Any CPU
{81C8377E-1A22-488B-A1F5-1CA61C70C0F1}.ExportRelease|Any CPU.ActiveCfg = Debug|Any CPU
{81C8377E-1A22-488B-A1F5-1CA61C70C0F1}.ExportRelease|Any CPU.Build.0 = Debug|Any CPU
{D00A3B38-295F-4C0B-933A-12620142284F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D00A3B38-295F-4C0B-933A-12620142284F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D00A3B38-295F-4C0B-933A-12620142284F}.ExportDebug|Any CPU.ActiveCfg = Debug|Any CPU
{D00A3B38-295F-4C0B-933A-12620142284F}.ExportDebug|Any CPU.Build.0 = Debug|Any CPU
{D00A3B38-295F-4C0B-933A-12620142284F}.ExportRelease|Any CPU.ActiveCfg = Debug|Any CPU
{D00A3B38-295F-4C0B-933A-12620142284F}.ExportRelease|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
EndGlobal

1
icon.svg Normal file
View File

@ -0,0 +1 @@
<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><g transform="translate(32 32)"><path d="m-16-32c-8.86 0-16 7.13-16 15.99v95.98c0 8.86 7.13 15.99 16 15.99h96c8.86 0 16-7.13 16-15.99v-95.98c0-8.85-7.14-15.99-16-15.99z" fill="#363d52"/><path d="m-16-32c-8.86 0-16 7.13-16 15.99v95.98c0 8.86 7.13 15.99 16 15.99h96c8.86 0 16-7.13 16-15.99v-95.98c0-8.85-7.14-15.99-16-15.99zm0 4h96c6.64 0 12 5.35 12 11.99v95.98c0 6.64-5.35 11.99-12 11.99h-96c-6.64 0-12-5.35-12-11.99v-95.98c0-6.64 5.36-11.99 12-11.99z" fill-opacity=".4"/></g><g stroke-width="9.92746" transform="matrix(.10073078 0 0 .10073078 12.425923 2.256365)"><path d="m0 0s-.325 1.994-.515 1.976l-36.182-3.491c-2.879-.278-5.115-2.574-5.317-5.459l-.994-14.247-27.992-1.997-1.904 12.912c-.424 2.872-2.932 5.037-5.835 5.037h-38.188c-2.902 0-5.41-2.165-5.834-5.037l-1.905-12.912-27.992 1.997-.994 14.247c-.202 2.886-2.438 5.182-5.317 5.46l-36.2 3.49c-.187.018-.324-1.978-.511-1.978l-.049-7.83 30.658-4.944 1.004-14.374c.203-2.91 2.551-5.263 5.463-5.472l38.551-2.75c.146-.01.29-.016.434-.016 2.897 0 5.401 2.166 5.825 5.038l1.959 13.286h28.005l1.959-13.286c.423-2.871 2.93-5.037 5.831-5.037.142 0 .284.005.423.015l38.556 2.75c2.911.209 5.26 2.562 5.463 5.472l1.003 14.374 30.645 4.966z" fill="#fff" transform="matrix(4.162611 0 0 -4.162611 919.24059 771.67186)"/><path d="m0 0v-47.514-6.035-5.492c.108-.001.216-.005.323-.015l36.196-3.49c1.896-.183 3.382-1.709 3.514-3.609l1.116-15.978 31.574-2.253 2.175 14.747c.282 1.912 1.922 3.329 3.856 3.329h38.188c1.933 0 3.573-1.417 3.855-3.329l2.175-14.747 31.575 2.253 1.115 15.978c.133 1.9 1.618 3.425 3.514 3.609l36.182 3.49c.107.01.214.014.322.015v4.711l.015.005v54.325c5.09692 6.4164715 9.92323 13.494208 13.621 19.449-5.651 9.62-12.575 18.217-19.976 26.182-6.864-3.455-13.531-7.369-19.828-11.534-3.151 3.132-6.7 5.694-10.186 8.372-3.425 2.751-7.285 4.768-10.946 7.118 1.09 8.117 1.629 16.108 1.846 24.448-9.446 4.754-19.519 7.906-29.708 10.17-4.068-6.837-7.788-14.241-11.028-21.479-3.842.642-7.702.88-11.567.926v.006c-.027 0-.052-.006-.075-.006-.024 0-.049.006-.073.006v-.006c-3.872-.046-7.729-.284-11.572-.926-3.238 7.238-6.956 14.642-11.03 21.479-10.184-2.264-20.258-5.416-29.703-10.17.216-8.34.755-16.331 1.848-24.448-3.668-2.35-7.523-4.367-10.949-7.118-3.481-2.678-7.036-5.24-10.188-8.372-6.297 4.165-12.962 8.079-19.828 11.534-7.401-7.965-14.321-16.562-19.974-26.182 4.4426579-6.973692 9.2079702-13.9828876 13.621-19.449z" fill="#478cbf" transform="matrix(4.162611 0 0 -4.162611 104.69892 525.90697)"/><path d="m0 0-1.121-16.063c-.135-1.936-1.675-3.477-3.611-3.616l-38.555-2.751c-.094-.007-.188-.01-.281-.01-1.916 0-3.569 1.406-3.852 3.33l-2.211 14.994h-31.459l-2.211-14.994c-.297-2.018-2.101-3.469-4.133-3.32l-38.555 2.751c-1.936.139-3.476 1.68-3.611 3.616l-1.121 16.063-32.547 3.138c.015-3.498.06-7.33.06-8.093 0-34.374 43.605-50.896 97.781-51.086h.066.067c54.176.19 97.766 16.712 97.766 51.086 0 .777.047 4.593.063 8.093z" fill="#478cbf" transform="matrix(4.162611 0 0 -4.162611 784.07144 817.24284)"/><path d="m0 0c0-12.052-9.765-21.815-21.813-21.815-12.042 0-21.81 9.763-21.81 21.815 0 12.044 9.768 21.802 21.81 21.802 12.048 0 21.813-9.758 21.813-21.802" fill="#fff" transform="matrix(4.162611 0 0 -4.162611 389.21484 625.67104)"/><path d="m0 0c0-7.994-6.479-14.473-14.479-14.473-7.996 0-14.479 6.479-14.479 14.473s6.483 14.479 14.479 14.479c8 0 14.479-6.485 14.479-14.479" fill="#414042" transform="matrix(4.162611 0 0 -4.162611 367.36686 631.05679)"/><path d="m0 0c-3.878 0-7.021 2.858-7.021 6.381v20.081c0 3.52 3.143 6.381 7.021 6.381s7.028-2.861 7.028-6.381v-20.081c0-3.523-3.15-6.381-7.028-6.381" fill="#fff" transform="matrix(4.162611 0 0 -4.162611 511.99336 724.73954)"/><path d="m0 0c0-12.052 9.765-21.815 21.815-21.815 12.041 0 21.808 9.763 21.808 21.815 0 12.044-9.767 21.802-21.808 21.802-12.05 0-21.815-9.758-21.815-21.802" fill="#fff" transform="matrix(4.162611 0 0 -4.162611 634.78706 625.67104)"/><path d="m0 0c0-7.994 6.477-14.473 14.471-14.473 8.002 0 14.479 6.479 14.479 14.473s-6.477 14.479-14.479 14.479c-7.994 0-14.471-6.485-14.471-14.479" fill="#414042" transform="matrix(4.162611 0 0 -4.162611 656.64056 631.05679)"/></g></svg>

After

Width:  |  Height:  |  Size: 4.1 KiB

37
icon.svg.import Normal file
View File

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://pdgsvm1momac"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

30
project.godot Normal file
View File

@ -0,0 +1,30 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=5
[application]
config/name="iFactory"
run/main_scene="res://Maps/Prototype.tscn"
config/features=PackedStringArray("4.0", "C#", "Forward Plus")
config/icon="res://icon.svg"
[dotnet]
project/assembly_name="iFactory"
[filesystem]
import/fbx/enabled=false
[rendering]
anti_aliasing/quality/msaa_3d=3
anti_aliasing/quality/screen_space_aa=1
anti_aliasing/quality/use_taa=true