private List <AnimationClip> ImportAnimationClips(glTF gltf, Axises invertAxis)
        {
            var animationClips = new List <AnimationClip>();

            for (var i = 0; i < gltf.animations.Count; ++i)
            {
                var clip = new AnimationClip();
                clip.ClearCurves();
                clip.legacy = true;
                clip.name   = gltf.animations[i].name;
                if (string.IsNullOrEmpty(clip.name))
                {
                    clip.name = $"legacy_{i}";
                }
                clip.wrapMode = WrapMode.Loop;

                var animation = gltf.animations[i];
                if (string.IsNullOrEmpty(animation.name))
                {
                    animation.name = $"animation:{i}";
                }

                animationClips.Add(AnimationImporterUtil.ConvertAnimationClip(gltf, animation, invertAxis.Create()));
            }

            return(animationClips);
        }
예제 #2
0
 public void setBasis(Vector3[] newBasis)
 {
     Basis  = Cylinder.Basis = Sphere.Basis = Triangle.Basis = Hypercube.Basis = newBasis;
     axises = new Axises(Constants.axisPosition, device);
     axises.paint(Constants.AxisColor);
     Hypercube.setCamera = true;
     cube = new Hypercube(Constants.SphereColor, Constants.CylinderColor, device);
     Invalidate();
 }
예제 #3
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            var asset = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(ctx.assetPath);

            if (asset == null)
            {
                // first time. set default setting
                m_reverseAxis = UniGLTFPreference.GltfIOAxis;
            }
            ScriptedImporterImpl.Import(this, ctx, m_reverseAxis);
        }
예제 #4
0
        public static IAxisInverter Create(this Axises axis)
        {
            switch (axis)
            {
            case Axises.Z: return(new ReverseZ());

            case Axises.X: return(new ReverseX());

            default: throw new NotImplementedException();
            }
        }
예제 #5
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     base.OnRender(drawingContext);
     Axises.Height = ActualHeight;
     Axises.Width  = ActualWidth;
     Axises.InvalidateVisual();
     MyCanvas.InvalidateVisual();
     MyCanvas.Children.Add(new Rectangle {
         Width = ActualWidth, Height = ActualHeight, Fill = new SolidColorBrush(Colors.Transparent)
     });
     Drawer.Draw();
     Console.WriteLine("OnRender");
 }
예제 #6
0
        public gltfExporter(glTF gltf, Axises invertAxis = Axises.Z)
        {
            glTF = gltf;

            glTF.extensionsUsed.AddRange(ExtensionUsed);

            glTF.asset = new glTFAssets
            {
                generator = "UniGLTF-" + UniGLTFVersion.VERSION,
                version   = "2.0",
            };

            m_axisInverter = invertAxis.Create();
        }
예제 #7
0
 public void updateGraphics(Color SphereColor, Color CylinderColor, Color OldSphereColor, Color OldCylinderColor)
 {
     if (Basis != null)
     {
         axises = new Axises(Constants.axisPosition, device);
         axises.paint(Constants.AxisColor);
         //string[] cubants = cube.cubants.ToArray();
         //Color[] cubantColors = cube.cubantColors.ToArray();
         //cube = new Hypercube(Constants.SphereColor, Constants.CylinderColor, device);
         cube.pant(SphereColor, CylinderColor, OldSphereColor, OldCylinderColor);
         //for (int i = 0; i < cubants.Length; i++)
         //{
         //   cube.setCubant(cubants[i], cubantColors[3 * i], cubantColors[3 * i + 1], cubantColors[3 * i + 2]);
         //}
     }
     Invalidate();
 }
예제 #8
0
        /// <summary>
        /// 重新清除前面已生成的对象
        /// </summary>
        public void Reset()
        {
            foreach (var c in Children)
            {
                if (c is FrameworkElement)
                {
                    var fe = c as FrameworkElement;
                    if (fe.Parent != null)
                    {
                        this.Parent.Children.Remove(fe);
                    }
                }
            }

            Children.Clear();
            Axises.Clear();
            //计算布局
            SetCanvasLayout();
        }
예제 #9
0
        private List <AnimationClip> ImportAnimationClips(glTF gltf, Axises invertAxis)
        {
            var animationClips = new List <AnimationClip>();

            for (var i = 0; i < gltf.animations.Count; ++i)
            {
                var clip = new AnimationClip();
                clip.ClearCurves();
                clip.legacy = true;
                clip.name   = gltf.animations[i].name;
                if (string.IsNullOrEmpty(clip.name))
                {
                    clip.name = $"legacy_{i}";
                }
                clip.wrapMode = WrapMode.Loop;

                var animation = gltf.animations[i];
                if (string.IsNullOrEmpty(animation.name))
                {
                    animation.name = $"animation:{i}";
                }

                AxisInverter inverter = default;
                switch (invertAxis)
                {
                case Axises.X:
                    inverter = AxisInverter.ReverseX;
                    break;

                case Axises.Z:
                    inverter = AxisInverter.ReverseZ;
                    break;

                default:
                    throw new System.Exception();
                }

                animationClips.Add(AnimationImporterUtil.ConvertAnimationClip(gltf, animation, inverter));
            }

            return(animationClips);
        }
예제 #10
0
        private static void Export(GameObject go, string path, MeshExportSettings settings, Axises inverseAxis)
        {
            var ext   = Path.GetExtension(path).ToLower();
            var isGlb = false;

            switch (ext)
            {
            case ".glb": isGlb = true; break;

            case ".gltf": isGlb = false; break;

            default: throw new System.Exception();
            }

            var gltf = new glTF();

            using (var exporter = new gltfExporter(gltf, inverseAxis))
            {
                exporter.Prepare(go);
                exporter.Export(settings, AssetTextureUtil.IsTextureEditorAsset);
            }


            if (isGlb)
            {
                var bytes = gltf.ToGlbBytes();
                File.WriteAllBytes(path, bytes);
            }
            else
            {
                var(json, buffers) = gltf.ToGltf(path);
                // without BOM
                var encoding = new System.Text.UTF8Encoding(false);
                File.WriteAllText(path, json, encoding);
                // write to local folder
                var dir = Path.GetDirectoryName(path);
                foreach (var b in buffers)
                {
                    var bufferPath = Path.Combine(dir, b.uri);
                    File.WriteAllBytes(bufferPath, b.GetBytes().ToArray());
                }
            }

            if (path.StartsWithUnityAssetPath())
            {
                AssetDatabase.ImportAsset(path.ToUnityRelativePath());
                AssetDatabase.Refresh();
            }
        }
예제 #11
0
        /// <summary>
        /// glb をパースして、UnityObject化、さらにAsset化する
        /// </summary>
        /// <param name="scriptedImporter"></param>
        /// <param name="context"></param>
        /// <param name="reverseAxis"></param>
        public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, Axises reverseAxis)
        {
#if VRM_DEVELOP
            Debug.Log("OnImportAsset to " + scriptedImporter.assetPath);
#endif

            //
            // Parse(parse glb, parser gltf json)
            //
            var parser = new GltfParser();
            parser.ParsePath(scriptedImporter.assetPath);

            //
            // Import(create unity objects)
            //
            var externalObjectMap = scriptedImporter.GetExternalObjectMap();

            using (var loaded = new ImporterContext(parser, null,
                                                    externalObjectMap.Where(x => x.Value != null).Select(x => (x.Value.name, x.Value)).Concat(
                                                        EnumerateTexturesFromUri(externalObjectMap, parser, UnityPath.FromUnityPath(scriptedImporter.assetPath).Parent))))
            {
                // settings TextureImporters
                foreach (var textureInfo in GltfTextureEnumerator.Enumerate(parser.GLTF))
                {
                    TextureImporterConfigurator.Configure(textureInfo, loaded.TextureFactory.ExternalMap);
                }

                loaded.InvertAxis = reverseAxis;
                loaded.Load();
                loaded.ShowMeshes();

                loaded.TransferOwnership(o =>
                {
#if VRM_DEVELOP
                    Debug.Log($"[{o.GetType().Name}] {o.name} will not destroy");
#endif

                    context.AddObjectToAsset(o.name, o);
                    if (o is GameObject)
                    {
                        // Root GameObject is main object
                        context.SetMainObject(loaded.Root);
                    }

                    return(true);
                });
            }
        }
예제 #12
0
        /// <summary>
        /// glb をパースして、UnityObject化、さらにAsset化する
        /// </summary>
        /// <param name="scriptedImporter"></param>
        /// <param name="context"></param>
        /// <param name="reverseAxis"></param>
        public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, Axises reverseAxis)
        {
#if VRM_DEVELOP
            Debug.Log("OnImportAsset to " + scriptedImporter.assetPath);
#endif

            //
            // Parse(parse glb, parser gltf json)
            //
            var parser = new GltfParser();
            parser.ParsePath(scriptedImporter.assetPath);

            //
            // Import(create unity objects)
            //
            var externalObjectMap = scriptedImporter.GetExternalObjectMap().Select(kv => (kv.Value.name, kv.Value)).ToArray();

            var externalTextures = EnumerateTexturesFromUri(externalObjectMap, parser, UnityPath.FromUnityPath(scriptedImporter.assetPath).Parent).ToArray();

            using (var loader = new ImporterContext(parser, externalObjectMap.Concat(externalTextures)))
            {
                // settings TextureImporters
                foreach (var(key, textureInfo) in GltfTextureEnumerator.EnumerateAllTexturesDistinct(parser))
                {
                    TextureImporterConfigurator.Configure(textureInfo, loader.TextureFactory.ExternalMap);
                }

                loader.InvertAxis = reverseAxis;
                loader.Load();
                loader.ShowMeshes();

                loader.TransferOwnership(o =>
                {
                    context.AddObjectToAsset(o.name, o);
                    if (o is GameObject)
                    {
                        // Root GameObject is main object
                        context.SetMainObject(loader.Root);
                    }

                    return(true);
                });
            }
        }
예제 #13
0
 /// <summary>
 /// Gets the name of the axis
 /// </summary>
 /// <param name="axis">Target axis</param>
 /// <param name="playerIndex">Index of the player</param>
 /// <returns>The name of the axis</returns>
 public static string GetAxisName(Axises axis, int playerIndex)
 {
     return(axis.ToString() + playerIndex);
 }
예제 #14
0
 private void RadioButton6_CheckedChanged(object sender, EventArgs e)
 {
     _endAxis = Axises.Y;
 }
예제 #15
0
 private void RadioButton1_CheckedChanged(object sender, EventArgs e)
 {
     _startAxis = Axises.X;
 }
        public List <AnimationClip> Import(glTF gltf, GameObject root, List <Transform> _nodes, List <AnimationClip> _clips, Axises invertAxis)
        {
            var animationClips = new List <AnimationClip>();

            if (gltf.animations != null && gltf.animations.Any())
            {
                var animation = root.AddComponent <Animation>();
                animationClips.AddRange(ImportAnimationClips(gltf, invertAxis));

                foreach (var clip in animationClips)
                {
                    animation.AddClip(clip, clip.name);
                }
                if (animationClips.Count > 0)
                {
                    animation.clip = animationClips.First();
                }
            }
            return(animationClips);
        }