public override Graphics.Mesh.CGfxModifier CloneModifier(CRenderContext rc)
        {
            var result = new CGfxInstancingModifier();

            result.Name = Name;
            return(result);
            //var ptr = SDK_GfxModifier_CloneModifier(CoreObject, rc.CoreObject);
            //var result = new CGfxInstancingModifier(ptr);
            //result.Name = Name;
            //return result;
        }
        public async System.Threading.Tasks.Task Init(RName name, bool shadow)
        {
            mMaxNumber     = DefaultMaxNumber;
            mInstDataArray = new VSInstantData[mMaxNumber];
            mPosData       = new Vector3[mMaxNumber];
            mScaleData     = new Vector4[mMaxNumber];
            mRotateData    = new Quaternion[mMaxNumber];
            mF41Data       = new UInt32_4[mMaxNumber];

            unsafe
            {
                var rc = CEngine.Instance.RenderContext;
                CVertexBufferDesc desc = new CVertexBufferDesc();
                desc.CPUAccess = (UInt32)ECpuAccess.CAS_WRITE;
                desc.ByteWidth = (UInt32)(sizeof(Vector3) * mMaxNumber);
                desc.Stride    = (UInt32)sizeof(Vector3);
                mPosVB         = rc.CreateVertexBuffer(desc);

                desc.ByteWidth = (UInt32)(sizeof(Vector4) * mMaxNumber);
                desc.Stride    = (UInt32)sizeof(Vector4);
                mScaleVB       = rc.CreateVertexBuffer(desc);

                desc.ByteWidth = (UInt32)(sizeof(Quaternion) * mMaxNumber);
                desc.Stride    = (UInt32)sizeof(Quaternion);
                mRotateVB      = rc.CreateVertexBuffer(desc);

                desc.ByteWidth = (UInt32)(sizeof(Vector4) * mMaxNumber);
                desc.Stride    = (UInt32)sizeof(Vector4);
                mF41VB         = rc.CreateVertexBuffer(desc);

                var bfDesc = new CGpuBufferDesc();
                bfDesc.SetMode(true, false);
                bfDesc.ByteWidth           = (uint)(mMaxNumber * sizeof(VSInstantData));
                bfDesc.StructureByteStride = (uint)sizeof(VSInstantData);
                mInstDataBuffer            = rc.CreateGpuBuffer(bfDesc, IntPtr.Zero);

                var srvDesc = new ISRVDesc();
                srvDesc.ToDefault();
                srvDesc.ViewDimension        = EResourceDimension.RESOURCE_DIMENSION_BUFFER;
                srvDesc.Buffer.ElementOffset = 0;
                srvDesc.Buffer.NumElements   = (uint)mMaxNumber;
                mInstDataView = rc.CreateShaderResourceViewFromBuffer(mInstDataBuffer, srvDesc);
            }

            MeshActor = await Actor.GActor.NewMeshActorAsync(name);

            MeshComp = MeshActor.GetComponent <GMeshComponent>();
            var modifier = MeshComp.SceneMesh.MdfQueue.FindModifier <CGfxInstancingModifier>();

            if (modifier == null)
            {
                modifier = new CGfxInstancingModifier();
                MeshComp.SceneMesh.MdfQueue.AddModifier(modifier);
            }
            if (shadow)
            {
                modifier.SetShadowHost(this);
            }
            else
            {
                modifier.SetHost(this);
            }

            MeshComp.IsIdentityDrawTransform = true;
            MeshActor.Placement.Location     = Vector3.Zero;
            CEngine.Instance.HitProxyManager.MapActor(MeshActor);

            mAttachVBs.BindVertexBuffer(EVertexSteamType.VST_InstPos, mPosVB);
            mAttachVBs.BindVertexBuffer(EVertexSteamType.VST_InstScale, mScaleVB);
            mAttachVBs.BindVertexBuffer(EVertexSteamType.VST_InstQuat, mRotateVB);
            mAttachVBs.BindVertexBuffer(EVertexSteamType.VST_F4_1, mF41VB);

            mAttachSRVs.VSBindTexture(13, mInstDataView);
        }