public static UniVRM10.MorphTargetBinding Build10(this MorphTargetBind bind, GameObject root, Vrm10Importer.ModelMap loader, VrmLib.Model model) { var libNode = model.Nodes[bind.Node.Value]; var node = loader.Nodes[libNode].transform; var mesh = loader.Meshes[libNode.MeshGroup]; var relativePath = node.RelativePathFrom(root.transform); return(new UniVRM10.MorphTargetBinding(relativePath, bind.Index.Value, bind.Weight.Value)); }
public static UniVRM10.MorphTargetBinding Build10(this MorphTargetBind bind, GameObject root, RuntimeUnityBuilder.ModelMap loader, VrmLib.Model model) { var libNode = model.Nodes[bind.Node.Value]; var node = loader.Nodes[libNode].transform; var mesh = loader.Meshes[libNode.MeshGroup]; var relativePath = node.RelativePathFrom(root.transform); // VRM-1.0 では値域は [0-1.0f] return(new UniVRM10.MorphTargetBinding(relativePath, bind.Index.Value, bind.Weight.Value * 100.0f)); }
public static VrmLib.Expression FromGltf(this UniGLTF.Extensions.VRMC_vrm.Expression x, List <VrmLib.Node> nodes, List <VrmLib.Material> materials) { var expression = new VrmLib.Expression((VrmLib.ExpressionPreset)x.Preset, x.Name, x.IsBinary.HasValue && x.IsBinary.Value) { IgnoreBlink = x.IgnoreBlink.GetValueOrDefault(), IgnoreLookAt = x.IgnoreLookAt.GetValueOrDefault(), IgnoreMouth = x.IgnoreMouth.GetValueOrDefault(), }; if (x.MorphTargetBinds != null) { foreach (var y in x.MorphTargetBinds) { var node = nodes[y.Node.Value]; var blendShapeName = node.Mesh.MorphTargets[y.Index.Value].Name; var blendShapeBind = new MorphTargetBind(node, blendShapeName, y.Weight.Value); expression.MorphTargetBinds.Add(blendShapeBind); } } if (x.MaterialColorBinds != null) { foreach (var y in x.MaterialColorBinds) { var material = materials[y.Material.Value]; var materialColorBind = new MaterialColorBind(material, EnumUtil.Cast <MaterialBindType>(y.Type), y.TargetValue.ToVector4(Vector4.Zero)); expression.MaterialColorBinds.Add(materialColorBind); } } if (x.TextureTransformBinds != null) { foreach (var y in x.TextureTransformBinds) { var material = materials[y.Material.Value]; var materialUVBind = new TextureTransformBind(material, y.Scaling.ToVector2(Vector2.One), y.Offset.ToVector2(Vector2.Zero)); expression.TextureTransformBinds.Add(materialUVBind); } } return(expression); }
// public static ExpressionManager FromGltf(this UniGLTF.VRMC_vrm.Expression master, List<VrmLib.Node> nodes, List<VrmLib.Material> materials) // { // var manager = new ExpressionManager(); // foreach (var x in master.BlendShapeGroups) // { // VrmLib.Expression expression = FromGltf(x, nodes, materials); // manager.ExpressionList.Add(expression); // }; // return manager; // } public static UniGLTF.Extensions.VRMC_vrm.MorphTargetBind ToGltf(this MorphTargetBind self, List <VrmLib.Node> nodes) { var name = self.Name; var value = self.Value; var index = self.Node.Mesh.MorphTargets.FindIndex(x => x.Name == name); if (index < 0) { throw new IndexOutOfRangeException(string.Format("MorphTargetName {0} is not found", name)); } return(new UniGLTF.Extensions.VRMC_vrm.MorphTargetBind { Node = nodes.IndexOfThrow(self.Node), Index = self.Node.Mesh.MorphTargets.FindIndex(x => x.Name == name), Weight = value, }); }