public void GenerateVAT(string targetName, int renderersCount, float duration, int frames, Bounds bounds, Bounds startBounds, List <Vector3>[] renderersPositions, List <Quaternion>[] renderersRotations) { EnsureFolders(); if (!_highPrecisionPosition) { WritePositionsTexture(targetName, renderersCount, frames, bounds, renderersPositions); } else { WriteHighPrecisionPositionsTextures(targetName, renderersCount, frames, bounds, renderersPositions); } WriteRotationsTexture(targetName, renderersCount, frames, renderersRotations); VATAnimation vatAnimation = ScriptableObject.CreateInstance <VATAnimation>(); vatAnimation.Frames = frames; vatAnimation.Duration = duration; vatAnimation.BoundsCenter = bounds.center; vatAnimation.BoundsExtents = bounds.extents; vatAnimation.StartBoundsCenter = startBounds.center; vatAnimation.StartBoundsExtents = startBounds.extents; vatAnimation.HighPrecisionPositionMode = _highPrecisionPosition; vatAnimation.PartsCount = renderersCount; vatAnimation.PartsIdsInUV3 = vatAnimation.PartsCount > 256; if (!_highPrecisionPosition) { vatAnimation.PositionsTex = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/" + SAVE_FOLDER_TEXTURES + targetName + "_PositionTex.png", typeof(Texture2D)); SetTextureSettings(vatAnimation.PositionsTex); } else { vatAnimation.PositionsTex = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/" + SAVE_FOLDER_TEXTURES + targetName + "_PositionTex.png", typeof(Texture2D)); SetTextureSettings(vatAnimation.PositionsTex); vatAnimation.PositionsTexB = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/" + SAVE_FOLDER_TEXTURES + targetName + "_PositionTexB.png", typeof(Texture2D)); SetTextureSettings(vatAnimation.PositionsTexB); } vatAnimation.RotationsTex = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/" + SAVE_FOLDER_TEXTURES + targetName + "_RotationTex.png", typeof(Texture2D)); SetTextureSettings(vatAnimation.RotationsTex); string animationPath = "Assets/" + SAVE_FOLDER + targetName + ".asset"; AssetDatabase.CreateAsset(vatAnimation, animationPath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); VATMeshGenerator vatMeshGenerator = new VATMeshGenerator(); vatMeshGenerator.SetMeshBounds(targetName, bounds); vatMeshGenerator.SetAnimationToPrefab(targetName, (VATAnimation)AssetDatabase.LoadAssetAtPath(animationPath, typeof(VATAnimation))); Debug.LogError("Generation Finished"); }
public void StartRecording() { Debug.LogError("Recording Started"); _target.transform.position = Vector3.zero; _target.gameObject.SetActive(true); _bounds = new Bounds(); _targetRenderers = _target.GetComponentsInChildren <Renderer>(); _targetRigidBodies = _target.GetComponentsInChildren <Rigidbody>(); _renderersPositions = new List <Vector3> [_targetRenderers.Length]; for (int i = 0; i < _renderersPositions.Length; i++) { _renderersPositions[i] = new List <Vector3>(); } _renderersRotations = new List <Quaternion> [_targetRenderers.Length]; for (int i = 0; i < _renderersRotations.Length; i++) { _renderersRotations[i] = new List <Quaternion>(); } _frames = Mathf.CeilToInt(_recordingTime * _framesPerSecond); _frameTime = 1f / (float)_framesPerSecond; _timer = 0; _recordingStarted = true; _currrentFrame = -1; VATMeshGenerator vatMeshGenerator = new VATMeshGenerator(); UpdateBounds(); _startBounds = _bounds; vatMeshGenerator.GenerateMesh(_target.name, _targetRenderers, _startBounds); RecordFrame(); if (_callWhenStartRecording != null) { _callWhenStartRecording.Invoke(); } }