public static IDisposable DisplayUndoable(this AnimatorBase animatorBase, IModelDoc2 modelDoc, double framerate = 30, int layer = 0)
        {
            animatorBase.OnStart(DateTime.Now);

            var d = new CompositeDisposable();

            OpenGlRenderer.DisplayUndoable(animatorBase, modelDoc, layer).DisposeWith(d);
            Redraw(modelDoc, framerate).DisposeWith(d);
            return(d);
        }
        public void InitializeAnimator(string cacheDictKey, Vec3f rotation, Shape blockShape, MeshRef meshref)
        {
            if (api.Side != EnumAppSide.Client)
            {
                throw new NotImplementedException("Server side animation system not implemented yet.");
            }

            animator = GetAnimator(api, cacheDictKey, blockShape);

            render = new BEAnimatableRenderer(api as ICoreClientAPI, be.Pos, rotation, animator, activeAnimationsByAnimCode, meshref);
        }
        public static AnimatorBase GetAnimator(ICoreAPI api, string cacheDictKey, Shape blockShape)
        {
            if (blockShape == null)
            {
                return(null);
            }

            object animCacheObj;
            Dictionary <string, AnimCacheEntry> animCache = null;

            api.ObjectCache.TryGetValue("beAnimCache", out animCacheObj);
            animCache = animCacheObj as Dictionary <string, AnimCacheEntry>;
            if (animCache == null)
            {
                api.ObjectCache["beAnimCache"] = animCache = new Dictionary <string, AnimCacheEntry>();
            }

            AnimatorBase animator;

            AnimCacheEntry cacheObj = null;

            if (animCache.TryGetValue(cacheDictKey, out cacheObj))
            {
                animator = api.Side == EnumAppSide.Client ?
                           new ClientAnimator(() => 1, cacheObj.RootPoses, cacheObj.Animations, cacheObj.RootElems, blockShape.JointsById) :
                           new ServerAnimator(() => 1, cacheObj.RootPoses, cacheObj.Animations, cacheObj.RootElems, blockShape.JointsById)
                ;
            }
            else
            {
                for (int i = 0; blockShape.Animations != null && i < blockShape.Animations.Length; i++)
                {
                    blockShape.Animations[i].GenerateAllFrames(blockShape.Elements, blockShape.JointsById);
                }

                animator = api.Side == EnumAppSide.Client ?
                           new ClientAnimator(() => 1, blockShape.Animations, blockShape.Elements, blockShape.JointsById) :
                           new ServerAnimator(() => 1, blockShape.Animations, blockShape.Elements, blockShape.JointsById)
                ;

                animCache[cacheDictKey] = new AnimCacheEntry()
                {
                    Animations = blockShape.Animations,
                    RootElems  = (animator as ClientAnimator).rootElements,
                    RootPoses  = (animator as ClientAnimator).RootPoses
                };
            }


            return(animator);
        }
示例#4
0
        public BEAnimatableRenderer(ICoreClientAPI capi, BlockPos pos, Vec3f rotation, AnimatorBase animator, Dictionary <string, AnimationMetaData> activeAnimationsByAnimCode, MeshRef meshref)
        {
            this.pos      = pos;
            this.capi     = capi;
            this.animator = animator;
            this.activeAnimationsByAnimCode = activeAnimationsByAnimCode;
            this.meshref  = meshref;
            this.rotation = rotation;
            if (rotation == null)
            {
                rotation = new Vec3f();
            }

            textureId = capi.BlockTextureAtlas.GetPosition(capi.World.BlockAccessor.GetBlock(pos), "rusty").atlasTextureId;

            capi.Event.RegisterRenderer(this, EnumRenderStage.Opaque, "beanimatable");
        }
        public BEAnimatableRenderer(ICoreClientAPI capi, BlockPos pos, Vec3f rotation, AnimatorBase animator, Dictionary <string, AnimationMetaData> activeAnimationsByAnimCode, MeshRef meshref)
        {
            this.pos      = pos;
            this.capi     = capi;
            this.animator = animator;
            this.activeAnimationsByAnimCode = activeAnimationsByAnimCode;
            this.meshref  = meshref;
            this.rotation = rotation;
            if (rotation == null)
            {
                this.rotation = new Vec3f();
            }

            textureId = capi.BlockTextureAtlas.AtlasTextureIds[0];

            capi.Event.EnqueueMainThreadTask(() =>
            {
                capi.Event.RegisterRenderer(this, EnumRenderStage.Opaque, "beanimatable");
                capi.Event.RegisterRenderer(this, EnumRenderStage.ShadowFar, "beanimatable");
                capi.Event.RegisterRenderer(this, EnumRenderStage.ShadowNear, "beanimatable");
            }, "registerrenderers");
        }
        public void InitializeAnimator(string cacheDictKey, MeshData meshdata, Shape shape, Vec3f rotation)
        {
            if (meshdata == null)
            {
                throw new ArgumentException("meshdata cannot be null");
            }

            ICoreClientAPI capi = api as ICoreClientAPI;

            animator = GetAnimator(api, cacheDictKey, shape);


            if (RuntimeEnv.MainThreadId == System.Threading.Thread.CurrentThread.ManagedThreadId)
            {
                renderer = new BEAnimatableRenderer(api as ICoreClientAPI, be.Pos, rotation, animator, activeAnimationsByAnimCode, capi.Render.UploadMesh(meshdata));
            }
            else
            {
                renderer = new BEAnimatableRenderer(api as ICoreClientAPI, be.Pos, rotation, animator, activeAnimationsByAnimCode, null);
                (api as ICoreClientAPI).Event.EnqueueMainThreadTask(() => {
                    renderer.meshref = capi.Render.UploadMesh(meshdata);
                }, "uploadmesh");
            }
        }
        public void InitializeAnimatorServer(string cacheDictKey, Shape blockShape)
        {
            animator = GetAnimator(api, cacheDictKey, blockShape);

            be.RegisterGameTickListener(animTickServer, 20);
        }