-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadGLTF.cs
58 lines (50 loc) · 2.25 KB
/
LoadGLTF.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using Stride.Core.Mathematics;
using Stride.Input;
using Stride.Engine;
using Stride.Core.Diagnostics;
using Stride.Shaders.Parser.Mixins;
using Stride.Graphics;
using System.Linq;
using System.IO;
using GltfImport.GltfParser;
namespace GltfImport
{
public class LoadGLTF : SyncScript
{
// Declared public member fields and properties will show in the game studio
private bool loaded = false;
public string Path { get; set; }
public SharpGLTF.Schema2.ModelRoot fox_glb;
public override void Start()
{
//Entity.Transform.Position = Vector3.UnitY;
Log.ActivateLog(LogMessageType.Info);
// var fox_glb = SharpGLTF.Schema2.ModelRoot.Load("D:/Downloads/glTF/cube/AnimatedCube.gltf");
//fox_glb = SharpGLTF.Schema2.ModelRoot.Load("D:/Downloads/glTF/fox/Fox.gltf");
// var fox_glb = SharpGLTF.Schema2.ModelRoot.Load("D:/Downloads/glTF/icosphere/icosphere.gltf");
// var fox_glb = SharpGLTF.Schema2.ModelRoot.Load("D:/Downloads/glTF/torus/torus.gltf");
//fox_glb = SharpGLTF.Schema2.ModelRoot.Load("C:/Users/kafia/Documents/blender try/SimpleCube.gltf");
//fox_glb = SharpGLTF.Schema2.ModelRoot.ReadGLB(File.OpenRead("D:/codeProj/xenproj/GltfImport/GltfImport/Resources/Fox.glb"));
fox_glb = SharpGLTF.Schema2.ModelRoot.Load("D:/codeProj/xenproj/GltfImport/GltfImport/Resources/FoxEmbedded.gltf");
}
public override void Update()
{
if (!loaded)
{
Entity.Add(new ModelComponent(GltfMeshParser.LoadFirstModel(GraphicsDevice, fox_glb)));
var animCmp = Entity.GetOrCreate<AnimationComponent>();
var animations = GltfMeshParser.ConvertAnimations(fox_glb);
foreach(var anim in animations)
{
animCmp.Animations.Add(anim.Key, anim.Value);
}
animCmp.Play("Run");
Log.Info("Model Loaded");
loaded = true;
}
DebugText.Print(Entity.Transform.Position.ToString(),new Int2(10,10));
//var model = Entity.Get<ModelComponent>().Materials[0].;
}
}
}