2 * Copyright(c) 2024 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.ComponentModel;
20 using Tizen.NUI.Scene3D;
22 namespace Tizen.AIAvatar
25 /// Specialized <see cref="BlendShapeIndex"/> to control avatar blend shape.
29 /// AvatarBlendShapeIndex leftEyeBlink = new AvatarBlendShapeIndex(avatar.BlendShapeMapper, BlendShapeType.EyeBlinkLeft);
31 /// // We can change the property later.
32 /// AVatarBlendShapeIndex rightEyeBlink = new AvatarJointTransformIndex(avatar.BlendShapeMapper);
33 /// rightEyeBlink.AvatarBlendShapeType = (uint)BlendShapeType.EyeBlinkRight;
36 [EditorBrowsable(EditorBrowsableState.Never)]
37 internal class AvatarBlendShapeIndex : BlendShapeIndex
39 internal AvatarPropertyMapper nameMapper = null;
40 internal uint blendShapeType;
42 internal AvatarBlendShapeIndex(AvatarPropertyMapper mapper) : base()
47 internal AvatarBlendShapeIndex(AvatarPropertyMapper mapper, PropertyKey blendShapeId) : base(new PropertyKey(GetPropertyNameFromMapper(mapper, blendShapeId)))
52 internal AvatarBlendShapeIndex(AvatarPropertyMapper nodeMapper, NodeType nodeType, PropertyKey blendShapeId)
53 : base(new PropertyKey(GetPropertyNameFromMapper(nodeMapper, (uint)nodeType)), blendShapeId)
57 internal AvatarBlendShapeIndex(AvatarPropertyMapper blendShapeMapper, BlendShapeType blendShapeType) : this(blendShapeMapper, (uint)blendShapeType)
61 internal AvatarBlendShapeIndex(AvatarPropertyMapper mapper, uint blendShapeType) : base(new PropertyKey(GetPropertyNameFromMapper(mapper, blendShapeType)))
64 this.blendShapeType = blendShapeType;
67 internal AvatarBlendShapeIndex(AvatarPropertyMapper nodeMapper, NodeType nodeType, AvatarPropertyMapper blendShapeMapper, BlendShapeType blendShapeType)
68 : base(new PropertyKey(GetPropertyNameFromMapper(nodeMapper, (uint)nodeType)), new PropertyKey(GetPropertyNameFromMapper(blendShapeMapper, (uint)blendShapeType)))
70 nameMapper = blendShapeMapper;
71 this.blendShapeType = (uint)blendShapeType;
75 /// Get the name of given index.
77 /// <param name="mapper">Name mapper for given index</param>
78 /// <param name="id">Target ID what we want to get name</param>
79 /// <returns>Name, or null if invalid</returns>
80 private static string GetPropertyNameFromMapper(AvatarPropertyMapper mapper, PropertyKey id)
86 if (id.Type == PropertyKey.KeyType.String)
91 var str = mapper?.GetPropertyName((uint)id.IndexKey) ?? "";
96 /// Get the name of given BlendShape.
98 /// <param name="mapper">Name mapper for given index</param>
99 /// <param name="type">Type of joint what we want to get name</param>
100 /// <returns>Name, or null if invalid</returns>
101 private static string GetPropertyNameFromMapper(AvatarPropertyMapper mapper, uint type)
103 var str = mapper?.GetPropertyName(type) ?? "";
108 /// TODO : Explain me
110 [EditorBrowsable(EditorBrowsableState.Never)]
111 public AvatarPropertyMapper NameMapper
121 using PropertyKey blendShapeId = new(GetPropertyNameFromMapper(nameMapper, blendShapeType));
122 base.BlendShapeId = blendShapeId;
127 /// TODO : Explain me
129 [EditorBrowsable(EditorBrowsableState.Never)]
130 public uint AvatarBlendShapeType
134 return blendShapeType;
138 blendShapeType = value;
140 using PropertyKey blendShapeId = new(GetPropertyNameFromMapper(nameMapper, blendShapeType));
141 base.BlendShapeId = blendShapeId;
146 /// Hijack property to control Avatar specified logic.
148 [EditorBrowsable(EditorBrowsableState.Never)]
149 public new PropertyKey BlendShapeId
153 return base.BlendShapeId;
159 if (value.Type == PropertyKey.KeyType.Index)
161 blendShapeType = (uint)value.IndexKey;
163 using PropertyKey blendShapeId = new(GetPropertyNameFromMapper(nameMapper, value));
164 base.BlendShapeId = blendShapeId;
168 base.BlendShapeId = value;