Я также пытался создать собственный сценарий экспорта Alembic и использовать его, но происходит то же самое, что бы я ни делал. делать. Я проверил, вызывается ли функция Update, но даже с экспортером Alembic это, похоже, так (она вызывается повсюду, так что дело не в том, что основной поток заблокирован). Просто его эффекты больше не видны в окне просмотра или в файле Alembic.
Я новичок в Unity, поэтому, вероятно, есть простое решение, или я не понимаю чего-то базового в Unity. экспортер.
Вот код сетки GameObject:
Код: Выделить всё
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
public class CustomMesh : MonoBehaviour
{
private Mesh mesh;
private Vector3[] vertices;
private int[] triangles;
void Start()
{
mesh = new Mesh();
GetComponent().mesh = mesh;
CreateShape();
UpdateMesh();
}
void CreateShape()
{
// Define vertices (positions of the mesh points)
vertices = new Vector3[]
{
new Vector3(0, 0, 0), // Vertex 0
new Vector3(0, 1, 0), // Vertex 1
new Vector3(1, 1, 0), // Vertex 2
new Vector3(1, 0, 0) // Vertex 3
};
// Define triangles (the order of vertices that make up each triangle face)
triangles = new int[]
{
0, 1, 2, // First triangle
0, 2, 3 // Second triangle
};
}
void UpdateMesh()
{
mesh.Clear();
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.RecalculateNormals(); // For proper lighting
}
void Update()
{
// Example: Move vertex 0 over time
vertices[0] = new Vector3(Mathf.Sin(Time.time), 0, 0);
//Debug.Log("Update.");
// Apply changes to the mesh
UpdateMesh();
}
}
Код: Выделить всё
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Formats.Alembic.Exporter;
public class AlembicCustomExporter : MonoBehaviour
{
public AlembicExporter alembicExporter; // Drag the exporter component here
public float exportDuration = 5f; // How long the animation is
public float frameRate = 30f; // Frames per second for export
private bool isExporting = false;
void Start()
{
// Start capturing the animation in a coroutine
StartCoroutine(CaptureAnimation());
}
IEnumerator CaptureAnimation()
{
isExporting = true;
float timePerFrame = 1f / frameRate; // Calculate time interval for each frame
float startTime = Time.time; // Track the starting time
float currentTime = 0f;
int frameCount = 0;
// Begin recording with Alembic
alembicExporter.BeginRecording();
// Loop for the duration of the export (in seconds)
while (currentTime < exportDuration)
{
// Wait for the next frame
yield return new WaitForEndOfFrame();
// Wait for the next frame time based on the frame rate
yield return new WaitForSeconds(timePerFrame);
// Update the elapsed time and frame count
currentTime = Time.time - startTime;
frameCount++;
Debug.Log($"Frame {frameCount} captured at {Time.time}s");
}
// End the recording after the duration has passed
alembicExporter.EndRecording();
isExporting = false;
Debug.Log("Alembic export completed.");
}
}
[img]https://i.sstatic.net /65iNFwWB.png[/img]
Подробнее здесь: https://stackoverflow.com/questions/790 ... namic-mesh
Мобильная версия