This repository has no description
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2023 MizunagiKB <mizukb@live.jp>
3using System;
4using Godot;
5
6
7#pragma warning disable IDE1006
8
9
10public partial class demo_fade : Node2D
11{
12 const System.String DEFAULT_ASSET = "res://addons/gd_cubism/example/res/live2d/mao_pro_jp/runtime/mao_pro.model3.json";
13
14 GDCubismUserModelCS cubism_model;
15 GDCubismUserModelCS cubism_model_sv;
16
17 double color_h;
18
19
20 private void recalc_model_position(GDCubismUserModelCS model)
21 {
22 if(model.Assets == "") return;
23
24 Godot.Collections.Dictionary canvas_info = model.GetCanvasInfo();
25
26 if(canvas_info.Count > 0)
27 {
28 Vector2 vct_viewport_size = new(GetViewportRect().Size.X, GetViewportRect().Size.Y);
29 Vector2 size_in_pixels = (Vector2)canvas_info["size_in_pixels"];
30 float scale = vct_viewport_size.Y / Math.Max(size_in_pixels.X, size_in_pixels.Y);
31 model.GetInternalObject().Position = new(vct_viewport_size.X * 0.5f, vct_viewport_size.Y * 0.5f);
32 model.GetInternalObject().Scale = new(scale, scale);
33 }
34 }
35
36 public override void _Ready()
37 {
38 this.cubism_model = new(GetNode<Node2D>("GDCubismUserModel"));
39 if (this.cubism_model.Assets == "")
40 {
41 this.cubism_model.Assets = DEFAULT_ASSET;
42 }
43
44 this.cubism_model_sv = new(GetNode<Node2D>("Sprite2D/SubViewport/GDCubismUserModel"));
45 if (this.cubism_model_sv.Assets == "")
46 {
47 this.cubism_model_sv.Assets = DEFAULT_ASSET;
48 }
49
50 this.color_h = GetNode<HSlider>("HSlider").Value;
51 }
52
53 public override void _Process(double delta)
54 {
55 this.color_h += (delta * 0.25);
56
57 if (this.color_h > 360.0)
58 {
59 this.color_h -= 360.0;
60 }
61
62 Color color = Color.FromHsv((float)this.color_h, 1.0f, 1.0f, (float)GetNode<HSlider>("HSlider").Value / 100.0f);
63
64 this.cubism_model.GetInternalObject().Modulate = color;
65 GetNode<Sprite2D>("Sprite2D").Modulate = color;
66 }
67}