private void GetTextureRangeAndOffset(KeyframeTextureBaker.BakedData bakedData, KeyframeTextureBaker.AnimationClipData clipData, out float range, out float offset, out float onePixelOffset, out int textureWidth) { float onePixel = 1f / bakedData.Texture0.width; float start = (float)clipData.PixelStart / bakedData.Texture0.width + onePixel * 0.5f; float end = (float)clipData.PixelEnd / bakedData.Texture0.width + onePixel * 0.5f; onePixelOffset = onePixel; textureWidth = bakedData.Texture0.width; range = end - start; offset = start; }
private void initilize() { if (init) { return; } init = true; PreSetting setting = Resources.Load <PreSetting>("PreSetting"); var bakingObject = GameObject.Instantiate(setting.go) as GameObject; SkinnedMeshRenderer renderer = bakingObject.GetComponentInChildren <SkinnedMeshRenderer>(); LodData lodData = new LodData(); lodData.Lod1Mesh = setting.mesh0; lodData.Lod2Mesh = setting.mesh1; lodData.Lod3Mesh = setting.mesh2; lodData.Lod1Distance = 10; lodData.Lod2Distance = 20; lodData.Lod3Distance = 30; Material material = setting.material; //SkinnedMeshRenderer r = Combine.CombineIt(bakingObject.transform); bakedData = KeyframeTextureBaker.BakeClips(renderer, GetAllAnimationClips(renderer.GetComponentInParent <Animation>()), lodData); //bakedData = KeyframeTextureBaker.BakeClips(r, GetAllAnimationClips(r.GetComponentInParent<Animation>()), lodData); TransferAnimationData(); //UnityEngine.Object fGo = Resources.Load("Formation"); for (int i = 0; i < formationCount; i++) { Vector3 formationPosition = new Vector3(i % 5 * (width + 30), 1, i / 5 * (height + 20)); //GameObject instance = Object.Instantiate(fGo) as GameObject; //instance.name = "Formation_" + i; //Formation form = instance.GetComponent<Formation>(); //form.Init(width, height); //instance.transform.position = formationPosition; FormationData data = new FormationData(); data.width = width; data.height = height; data.formationPosition = formationPosition; formationList.Add(data); } lodDrawer0 = new LodedDrawerECS(bakedData.NewMesh, material, bakedData); lodDrawer1 = new LodedDrawerECS(bakedData.lods.Lod1Mesh, material, bakedData); lodDrawer2 = new LodedDrawerECS(bakedData.lods.Lod2Mesh, material, bakedData); lodDrawer3 = new LodedDrawerECS(bakedData.lods.Lod3Mesh, material, bakedData); }
public LodedDrawer(Mesh mesh, Material mat, KeyframeTextureBaker.BakedData data, AnimationClipDataBaked[] clipData, List <Formation> formList) { count = formList.Count * formList[0].Count(); animationClipData = clipData; bakedData = data; material = new Material(mat); meshToDraw = mesh; indirectArgs[0] = meshToDraw.GetIndexCount(0); argsBuffer = new ComputeBuffer(1, indirectArgs.Length * sizeof(uint), ComputeBufferType.IndirectArguments); objectRotationsBuffer = new ComputeBuffer(count, 16); objectPositionsBuffer = new ComputeBuffer(count, 16); textureCoordinatesBuffer = new ComputeBuffer(count, 12); material.SetTexture("_AnimationTexture0", bakedData.Texture0); material.SetTexture("_AnimationTexture1", bakedData.Texture1); material.SetTexture("_AnimationTexture2", bakedData.Texture2); }
void Start() { var bakingObject = GameObject.Instantiate(go); SkinnedMeshRenderer renderer = bakingObject.GetComponentInChildren <SkinnedMeshRenderer>(); lodData = new LodData(); lodData.Lod1Mesh = mesh0; lodData.Lod2Mesh = mesh1; lodData.Lod3Mesh = mesh2; lodData.Lod1Distance = 10; lodData.Lod2Distance = 20; lodData.Lod3Distance = 30; bakedData = KeyframeTextureBaker.BakeClips(renderer, GetAllAnimationClips(renderer.GetComponentInParent <Animation>()), lodData); TransferAnimationData(); UnityEngine.Object fGo = Resources.Load("Formation"); for (int i = 0; i < formationCount; i++) { int width = 12; int height = 6; Vector3 formationPosition = new Vector3(i % 5 * (width + 5), 1, i / 5 * (height + 4)); GameObject instance = Instantiate(fGo) as GameObject; instance.name = "Formation_" + i; Formation form = instance.GetComponent <Formation>(); form.Init(width, height); instance.transform.position = formationPosition; formationList.Add(form); } //SaveTextureToFile(bakedData.Texture0, "tp1.png"); //SaveTextureToFile(bakedData.Texture1, "tp2.png"); //SaveTextureToFile(bakedData.Texture2, "tp3.png"); lodDrawer0 = new LodedDrawer(bakedData.NewMesh, material, bakedData, animationClipData, formationList); lodDrawer1 = new LodedDrawer(bakedData.lods.Lod1Mesh, material, bakedData, animationClipData, formationList); lodDrawer2 = new LodedDrawer(bakedData.lods.Lod2Mesh, material, bakedData, animationClipData, formationList); lodDrawer3 = new LodedDrawer(bakedData.lods.Lod3Mesh, material, bakedData, animationClipData, formationList); }
public LodedDrawerECS(Mesh mesh, Material mat, KeyframeTextureBaker.BakedData data) { count = GPUSKinAnimBakeSystem.formationCount * GPUSKinAnimBakeSystem.width * GPUSKinAnimBakeSystem.height; //formList.Count * formList[0].count(); bakedData = data; material = new Material(mat); meshToDraw = mesh; indirectArgs[0] = meshToDraw.GetIndexCount(0); argsBuffer = new ComputeBuffer(1, indirectArgs.Length * sizeof(uint), ComputeBufferType.IndirectArguments); objectRotationsBuffer = new ComputeBuffer(count, 16); objectPositionsBuffer = new ComputeBuffer(count, 16); textureCoordinatesBuffer = new ComputeBuffer(count, 12); listPositionData = new NativeList <float4>(count, Allocator.Persistent); listRotationData = new NativeList <quaternion>(count, Allocator.Persistent); listTexturePositionData = new NativeList <float3>(count, Allocator.Persistent); material.SetTexture("_AnimationTexture0", bakedData.Texture0); material.SetTexture("_AnimationTexture1", bakedData.Texture1); material.SetTexture("_AnimationTexture2", bakedData.Texture2); }