protected void StoreAsset(FlexExt.Asset _asset) { m_particles = new Vector4[_asset.numParticles]; if (_asset.numParticles > 0) { FlexUtils.SafeFastCopy(_asset.particles, m_particles); } m_maxParticles = _asset.maxParticles; m_springIndices = new int[_asset.numSprings * 2]; if (_asset.numSprings > 0) { FlexUtils.SafeFastCopy(_asset.springIndices, m_springIndices); } m_springCoefficients = new float[_asset.numSprings]; if (_asset.numSprings > 0) { FlexUtils.SafeFastCopy(_asset.springCoefficients, m_springCoefficients); } m_springRestLengths = new float[_asset.numSprings]; if (_asset.numSprings > 0) { FlexUtils.SafeFastCopy(_asset.springRestLengths, m_springRestLengths); } m_shapeIndices = new int[_asset.numShapeIndices]; if (_asset.numShapeIndices > 0) { FlexUtils.SafeFastCopy(_asset.shapeIndices, m_shapeIndices); } m_shapeOffsets = new int[_asset.numShapes]; if (_asset.numShapes > 0) { FlexUtils.SafeFastCopy(_asset.shapeOffsets, m_shapeOffsets); } m_shapeCoefficients = new float[_asset.numShapes]; if (_asset.numShapes > 0) { FlexUtils.SafeFastCopy(_asset.shapeCoefficients, m_shapeCoefficients); } m_shapeCenters = new Vector3[_asset.numShapes]; if (_asset.numShapes > 0) { FlexUtils.SafeFastCopy(_asset.shapeCenters, m_shapeCenters); } m_triangleIndices = new int[_asset.numTriangles * 3]; if (_asset.numTriangles > 0) { FlexUtils.SafeFastCopy(_asset.triangleIndices, m_triangleIndices); } m_inflatable = _asset.inflatable; m_inflatableVolume = _asset.inflatableVolume; m_inflatablePressure = _asset.inflatablePressure; m_inflatableStiffness = _asset.inflatableStiffness; }
protected void CreateAsset() { m_asset = default(FlexExt.Asset); if (m_particles.Length > 0) { m_asset.particles = Marshal.AllocHGlobal(m_particles.Length * Marshal.SizeOf(default(Vector4))); FlexUtils.SafeFastCopy(m_particles, m_asset.particles); m_asset.numParticles = m_particles.Length; } m_asset.maxParticles = Mathf.Max(m_maxParticles, m_particles.Length); if (m_springIndices.Length > 0 && m_springCoefficients.Length > 0 && m_springRestLengths.Length > 0) { m_asset.springIndices = Marshal.AllocHGlobal(m_springIndices.Length * Marshal.SizeOf(default(int))); FlexUtils.SafeFastCopy(m_springIndices, m_asset.springIndices); m_asset.springCoefficients = Marshal.AllocHGlobal(m_springCoefficients.Length * Marshal.SizeOf(default(float))); FlexUtils.SafeFastCopy(m_springCoefficients, m_asset.springCoefficients); m_asset.springRestLengths = Marshal.AllocHGlobal(m_springRestLengths.Length * Marshal.SizeOf(default(float))); FlexUtils.SafeFastCopy(m_springRestLengths, m_asset.springRestLengths); m_asset.numSprings = m_springRestLengths.Length; } if (m_shapeIndices.Length > 0 && m_shapeOffsets.Length > 0 && m_shapeCoefficients.Length > 0 && m_shapeCenters.Length > 0) { m_asset.shapeIndices = Marshal.AllocHGlobal(m_shapeIndices.Length * Marshal.SizeOf(default(int))); FlexUtils.SafeFastCopy(m_shapeIndices, m_asset.shapeIndices); m_asset.numShapeIndices = m_shapeIndices.Length; m_asset.shapeOffsets = Marshal.AllocHGlobal(m_shapeOffsets.Length * Marshal.SizeOf(default(int))); FlexUtils.SafeFastCopy(m_shapeOffsets, m_asset.shapeOffsets); m_asset.shapeCoefficients = Marshal.AllocHGlobal(m_shapeCoefficients.Length * Marshal.SizeOf(default(float))); FlexUtils.SafeFastCopy(m_shapeCoefficients, m_asset.shapeCoefficients); m_asset.shapeCenters = Marshal.AllocHGlobal(m_shapeCenters.Length * Marshal.SizeOf(default(Vector3))); FlexUtils.SafeFastCopy(m_shapeCenters, m_asset.shapeCenters); m_asset.numShapes = m_shapeCenters.Length; } if (m_triangleIndices.Length > 0) { m_asset.triangleIndices = Marshal.AllocHGlobal(m_triangleIndices.Length * Marshal.SizeOf(default(int))); FlexUtils.SafeFastCopy(m_triangleIndices, m_asset.triangleIndices); m_asset.numTriangles = m_triangleIndices.Length / 3; } // @@@ Inflatables crash on some GPUs bool disableInflatables = !SystemInfo.graphicsDeviceVendor.Contains("NVIDIA"); // @@@ m_asset.inflatable = m_inflatable && !disableInflatables; m_asset.inflatableVolume = m_inflatableVolume; m_asset.inflatablePressure = m_inflatablePressure; m_asset.inflatableStiffness = m_inflatableStiffness; m_assetHandle.Allocate(); m_assetHandle.asset = m_asset; }