public GizmoDisposable(Color color, Matrix4x4 matrix) { //Cache the old color _oldColor = Gizmos.color; Gizmos.color = color; //Cache the old matrix _oldTransform = Gizmos.matrix; Gizmos.matrix = matrix; }
public HandleDisposable(Color color, Matrix4x4 matrix) { //Cache the old color _oldColor = Handles.color; Handles.color = color; //Cache the old matrix _oldTransform = Handles.matrix; Handles.matrix = matrix; }
void UpdateTransformMatrix() { Matrix4x4 matrix = Matrix4x4.identity; if (_skew.x != 0 || _skew.y != 0) { ToolSet.SkewMatrix(ref matrix, _skew.x, _skew.y); } if (_perspective) { matrix *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(_rotation), Vector3.one); } Vector3 camPos = Vector3.zero; if (matrix.isIdentity) { _transformMatrix = null; } else { _transformMatrix = matrix; camPos = new Vector3(_pivot.x * _contentRect.width, -_pivot.y * _contentRect.height, _focalLength); } //组件的transformMatrix是通过paintingMode实现的,因为全部通过矩阵变换的话,和unity自身的变换混杂在一起,无力理清。 if (_transformMatrix != null) { if (this is Container) { this.EnterPaintingMode(4, null); } } else { if (this is Container) { this.LeavePaintingMode(4); } } if (this._paintingMode > 0) { this.paintingGraphics.cameraPosition = camPos; this.paintingGraphics.vertexMatrix = _transformMatrix; this._paintingFlag = 1; } else if (this.graphics != null) { this.graphics.cameraPosition = camPos; this.graphics.vertexMatrix = _transformMatrix; _requireUpdateMesh = true; } _outlineChanged = true; }
public Plane(Vector3 center, Direction3 normal) { _cachedCenter = null; _cachedNormal = null; _cachedMatrix = null; _cachedPose = null; _cachedTransformMatrix = null; this.center = center; this.normal = normal; this.transform = null; }
/// <summary> /// コンストラクター /// </summary> public Transformable() { this.tx = 0; this.ty = 0; this.tz = 0; this.sx = 1; this.sy = 1; this.sz = 1; this.rot = Quaternion.Identity; this.matrix = null; }
internal static void LoadMatrix4x4Nullable(NetVariant variant, Matrix4x4?value) { if (value.HasValue) { variant.Matrix4x4 = value.Value; } else { variant.SetNull(); } }
public void SetTile(Vector3Int position, LayerTile tile, Matrix4x4?matrixTransform = null, Color?color = null) { if (Layers.TryGetValue(tile.LayerType, out var layer)) { layer.SetTile(position, tile, matrixTransform.GetValueOrDefault(Matrix4x4.identity), color.GetValueOrDefault(Color.white)); } else { LogMissingLayer(position, tile.LayerType); } }
public static AffineTransform CreateFromAny(Matrix4x4?matrix, Vector3?scale, Quaternion?rotation, Vector3?translation) { if (matrix.HasValue) { return(new AffineTransform(matrix.Value)); } else { return(new AffineTransform(scale, rotation, translation)); } }
public void End() { if (!matrixBeforeZoom.HasValue) { throw new InvalidOperationException("Must call Begin before calling End."); } GUI.matrix = matrixBeforeZoom.Value; matrixBeforeZoom = null; }
public static void UnityXRMock_setProjectionMatrix(Matrix4x4 projectionMatrix, Matrix4x4 inverseProjectionMatrix, bool hasValue) { if (hasValue) { NativeApi.projectionMatrix = projectionMatrix; } else { NativeApi.projectionMatrix = null; } }
public static Matrix?ToMonoGameMatrix(this Matrix4x4?mat) { if (!mat.HasValue) { return(null); } Matrix4x4 tM = mat.Value; return(new Matrix(tM.M11, tM.M12, tM.M13, tM.M14, tM.M21, tM.M22, tM.M23, tM.M24, tM.M31, tM.M32, tM.M33, tM.M34, tM.M41, tM.M42, tM.M43, tM.M44)); }
public bool MaybePushMatrix(Matrix4x4?m) { if (m != null) { PushMatrix(m.Value); return(true); } else { return(false); } }
public void Render(DateTime time, double parentOpacity = 1.0, Matrix4x4?renderTransform = null) { if (!Visibility) { return; } foreach (var subRenderable in _SubRenderables) { subRenderable.Render(time, Opacity * parentOpacity, renderTransform); } }
// Update is called once per frame void Update() { Matrix4x4?m = UDPJob.Instance.GetData(ID); if (m == null) { return; } transform.position = m.GetValueOrDefault().GetPosition(); transform.rotation = m.GetValueOrDefault().GetRotation(); }
public void InternalUpdateTile(Vector3 position, LayerTile layerTile, Matrix4x4?transformMatrix = null, Color?color = null) { if (layerTile.TileType == TileType.WindowDamaged) { position.z -= 1; } Vector3Int p = position.RoundToInt(); metaTileMap.SetTile(p, layerTile, transformMatrix, color); }
void ARCameraManagerOnFrameReceived(ARCameraFrameEventArgs cameraFrameEvent) { m_CurrentProjectionMatrix = cameraFrameEvent.projectionMatrix; if (cameraFrameEvent.textures.Count > 0) { var texture = cameraFrameEvent.textures[0]; m_CameraWidth = texture.width; m_CameraHeight = texture.height; m_RenderTextureDirty = true; } }
public void UpdateTile(Vector3Int cellPosition, LayerTile layerTile, Matrix4x4?transformMatrix = null, Color?color = null) { if (IsDifferent(cellPosition, layerTile, transformMatrix, color)) { InternalUpdateTile(cellPosition, layerTile, transformMatrix, color); AlertClients(cellPosition, layerTile.TileType, layerTile.name, transformMatrix, color); AddToChangeList(cellPosition, layerTile, transformMatrix: transformMatrix, color: color); } }
public static Vector3 GetHeadToCenterEyeTranslation() { // There are no known XR headsets that change head to center eye translation so use cached result if available if (_cachedHeadToCenterEyeTranslation.HasValue) { return(_cachedHeadToCenterEyeTranslation.Value); } Matrix4x4?head = null; Matrix4x4?centerEye = null; var states = new List <XRNodeState>(); InputTracking.GetNodeStates(states); foreach (var state in states) { if (state.nodeType != XRNode.Head && state.nodeType != XRNode.CenterEye) { continue; } Vector3 pos; Quaternion rot; if (!state.TryGetPosition(out pos)) { break; } if (!state.TryGetRotation(out rot)) { break; } if (state.nodeType == XRNode.Head) { head = Matrix4x4.TRS(pos, rot, Vector3.one); } if (state.nodeType == XRNode.CenterEye) { centerEye = Matrix4x4.TRS(pos, rot, Vector3.one); } } if (!head.HasValue || !centerEye.HasValue) { return(Vector3.zero); } var mat = centerEye.Value.inverse * head.Value; // Vce = Minv_ce*Mhead*Vhead // Extract translation. We assume no rotation between head and center eye _cachedHeadToCenterEyeTranslation = new Vector3(mat.m03, mat.m13, mat.m23); return(_cachedHeadToCenterEyeTranslation.Value); }
public void UpdateTile(Vector3Int cellPosition, TileType tileType, string tileName, Matrix4x4?transformMatrix = null, Color?color = null) { if (IsDifferent(cellPosition, tileType, tileName, transformMatrix, color)) { InternalUpdateTile(cellPosition, tileType, tileName, transformMatrix, color); AlertClients(cellPosition, tileType, tileName, transformMatrix, color); AddToChangeList(cellPosition, tileType: tileType, tileName: tileName, transformMatrix: transformMatrix, color: color); } }
/// <summary> /// This returns the transform matrix at the time the photo was captured, if location data if available. /// If it's not, that is probably an indication that the HoloLens is not tracking and its location is not known. /// It could also mean the VideoCapture stream is not running. /// If location data is unavailable then the camera to world matrix will be set to the identity matrix. /// </summary> /// <param name="matrix">The transform matrix used to convert between coordinate spaces. /// The matrix will have to be converted to a Unity matrix before it can be used by methods in the UnityEngine namespace. /// See https://forum.unity3d.com/threads/locatable-camera-in-unity.398803/ for details.</param> public bool TryGetCameraToWorldMatrix(out float[] outMatrix) { if (frameReference.Properties.ContainsKey(viewTransformGuid) == false) { outMatrix = GetIdentityMatrixFloatArray(); return(false); } if (worldOrigin == null) { outMatrix = GetIdentityMatrixFloatArray(); return(false); } Matrix4x4 cameraViewTransform = ConvertByteArrayToMatrix4x4(frameReference.Properties[viewTransformGuid] as byte[]); if (cameraViewTransform == null) { outMatrix = GetIdentityMatrixFloatArray(); return(false); } SpatialCoordinateSystem cameraCoordinateSystem = frameReference.Properties[cameraCoordinateSystemGuid] as SpatialCoordinateSystem; if (cameraCoordinateSystem == null) { outMatrix = GetIdentityMatrixFloatArray(); return(false); } Matrix4x4?cameraCoordsToUnityCoordsMatrix = cameraCoordinateSystem.TryGetTransformTo(worldOrigin); if (cameraCoordsToUnityCoordsMatrix == null) { outMatrix = GetIdentityMatrixFloatArray(); return(false); } Matrix4x4 worldToViewInCameraCoordsMatrix; Matrix4x4.Invert(cameraViewTransform, out worldToViewInCameraCoordsMatrix); Matrix4x4 worldToViewInUnityCoordsMatrix = Matrix4x4.Multiply(cameraCoordsToUnityCoordsMatrix.Value, worldToViewInCameraCoordsMatrix); Matrix4x4 viewToWorldInCameraCoordsMatrix = Matrix4x4.Transpose(worldToViewInUnityCoordsMatrix); viewToWorldInCameraCoordsMatrix.M31 *= -1f; viewToWorldInCameraCoordsMatrix.M32 *= -1f; viewToWorldInCameraCoordsMatrix.M33 *= -1f; viewToWorldInCameraCoordsMatrix.M34 *= -1f; outMatrix = ConvertMatrixToFloatArray(viewToWorldInCameraCoordsMatrix); return(true); }
public void SetTile(Vector3Int position, LayerTile tile, Matrix4x4?matrixTransform = null, Color?color = null) { if (Layers.TryGetValue(tile.LayerType, out var layer)) { if (Application.isPlaying == false) { layer.SetTile(position, tile, matrixTransform.GetValueOrDefault(Matrix4x4.identity), color.GetValueOrDefault(Color.white)); } TileLocation TileLcation = null; lock (PresentTiles) { PresentTiles[layer].TryGetValue(position, out TileLcation); } if (TileLcation != null) { TileLcation.Tile = tile; TileLcation.TransformMatrix = matrixTransform.GetValueOrDefault(Matrix4x4.identity); TileLcation.Colour = color.GetValueOrDefault(Color.white); TileLcation.OnStateChange(); } else { TileLcation = GetPooledTile(); TileLcation.PresentlyOn = layer; TileLcation.PresentMetaTileMap = this; TileLcation.TileCoordinates = position; TileLcation.Tile = tile; TileLcation.TransformMatrix = matrixTransform.GetValueOrDefault(Matrix4x4.identity); TileLcation.Colour = color.GetValueOrDefault(Color.white); lock (PresentTiles) { PresentTiles[layer][position] = TileLcation; } TileLcation.OnStateChange(); } // layer.SetTile(position, tile, // matrixTransform.GetValueOrDefault(Matrix4x4.identity), // color.GetValueOrDefault(Color.white)); } else { LogMissingLayer(position, tile.LayerType); } }
public static Mesh Clone(this Mesh source, bool recalculate = false, Matrix4x4?matrix = null, bool lightmaps = true, Mesh[] mergeMeshes = null) { Mesh clone = new Mesh(); clone.name = source.name; clone.vertices = source.vertices; clone.normals = source.normals; clone.tangents = source.tangents; clone.triangles = source.triangles; clone.uv = source.uv; clone.uv2 = source.uv2; clone.uv3 = source.uv3; clone.uv4 = source.uv4; clone.colors = source.colors; clone.colors32 = source.colors32; clone.bindposes = source.bindposes; clone.boneWeights = source.boneWeights; clone.subMeshCount = source.subMeshCount; clone.bounds = source.bounds; if (recalculate) { clone.RecalculateBounds(); } if (matrix != null) { Mesh regen = new Mesh(); regen.name = clone.name; // Setup Source Combine CombineInstance combine = new CombineInstance(); combine.transform = matrix.Value; combine.mesh = clone; List <CombineInstance> combines = new List <CombineInstance>(); combines.Add(combine); // Merge Other Combines if (mergeMeshes != null && mergeMeshes.Length > 0) { foreach (var mergeMesh in mergeMeshes) { combines.Add(new CombineInstance() { transform = matrix.Value, mesh = mergeMesh }); } } regen.CombineMeshes(combines.ToArray(), true, true, lightmaps); return(regen); } else { return(clone); } }
private void AddToChangeList(Vector3Int position, LayerTile layerTile, LayerType layerType = LayerType.None, Matrix4x4?transformMatrix = null, Color?color = null) { changeList.List.Add(new TileChangeEntry() { Position = position, LayerType = layerType, TileType = layerTile.TileType, TileName = layerTile.name, transformMatrix = transformMatrix, color = color }); }
internal AffineTransform(Matrix4x4?m, Vector3?s, Quaternion?r, Vector3?t) { if (m.HasValue) { Matrix4x4.Decompose(m.Value, out Scale, out Rotation, out Translation); } else { Rotation = r ?? Quaternion.Identity; Scale = s ?? Vector3.One; Translation = t ?? Vector3.Zero; } }
protected static void SerializeProperty(JsonWriter writer, string name, Matrix4x4?value, Matrix4x4?defval = null) { if (!value.HasValue) { return; } if (defval.HasValue && defval.Value.Equals(value.Value)) { return; } writer.WritePropertyName(name); _Serialize(writer, value.Value); }
public override void Render(DateTime now, double parentOpacity = 1.0, Matrix4x4?renderTransform = null) { if (_Animators.Count == 0) { return; } var passedTime = now - _ReferenceTime; var value = (passedTime.TotalMilliseconds % Duration.TotalMilliseconds) / Duration.TotalMilliseconds; var time = TimeSpan.FromMilliseconds(Duration.TotalMilliseconds * value); FindAnimator(time).Render(_ReferenceTime + time, Opacity * parentOpacity, renderTransform); }
public static Vector3[] ToWorldVertexs(this Bounds bounds, Matrix4x4?worldMat) { Vector3[] vs = bounds.ToVertexs(); if (worldMat.HasValue) { Matrix4x4 mat = worldMat.Value; for (int i = 0; i < 8; i++) { vs[i] = mat.MultiplyPoint(vs[i]); } } return(vs); }
/// <inheritdoc /> /// <summary> /// Wrap an already created texture in a GLTexture object. /// </summary> /// <param name="pointer">Pointer to the created OpenGL texture.</param> /// <param name="size">The size of the texture.</param> /// <param name="mulMatrix">An additional matrix to be multiplied to the texture matrix.</param> /// <param name="name">The name of the texture.</param> public GLTexture(uint pointer, Vector2 size, Matrix4x4?mulMatrix = null, string name = null) { Pointer = pointer; Size = size; TextureMatrix = Matrix4x4.CreateOrthographicOffCenter(0, Size.X * 2, Size.Y * 2, 0, 0, 1); Name = name ?? $"OpenGL Texture - {Pointer}"; Created = true; if (mulMatrix != null) { TextureMatrix *= (Matrix4x4)mulMatrix; } }
internal AffineTransform(Matrix4x4?matrix, Vector3?scale, Quaternion?rotation, Vector3?translation) { if (matrix.HasValue) { Matrix4x4.Decompose(matrix.Value, out this.Scale, out this.Rotation, out this.Translation); } else { this.Scale = scale ?? Vector3.One; this.Rotation = rotation ?? Quaternion.Identity; this.Translation = translation ?? Vector3.Zero; } }
//// =========================================================================================================== //// Constructors //// =========================================================================================================== public PerlinPattern( ColorMap colorMap, int octaves = 1, double persistence = 1, Matrix4x4?transform = null) : base(transform) { ColorMap = colorMap; Octaves = octaves; Persistence = persistence; _perlin = new Perlin(); }
public GizmoDisposable(Color?color, Matrix4x4?matrix) { if (color != null) { _oldColor = Gizmos.color; Gizmos.color = color.Value; } if (matrix != null) { _oldTransform = Gizmos.matrix; Gizmos.matrix = matrix.Value; } }
// Doesn't do material export; for that see ExportMeshPayload private GlTF_Node ExportMeshPayload_NoMaterial( BaseMeshPayload mesh, [CanBeNull] GlTF_Node parent, Matrix4x4?localXf = null) { ObjectName meshNameAndId = new ObjectName(mesh.legacyUniqueName); GeometryPool pool = mesh.geometry; Matrix4x4 xf = localXf ?? mesh.xform; // Create a Node and (usually) a Mesh, both named after meshNameAndId. // This is safe because the namespaces for Node and Mesh are distinct. // If we have already seen the GeometryPool, the Mesh will be reused. // In this (less common) case, the Node and Mesh will have different names. // We don't actually ever use the "VERTEXID" attribute, even in gltf1. // It's time to cut it away. // Also, in gltf2, it needs to be called _VERTEXID anyway since it's a custom attribute GlTF_VertexLayout gltfLayout = new GlTF_VertexLayout(G, pool.Layout); int numTris = pool.NumTriIndices / 3; if (numTris < 1) { return(null); } NumTris += numTris; GlTF_Mesh gltfMesh; // Share meshes for any repeated geometry pool. if (!m_meshCache.TryGetValue(pool, out gltfMesh)) { gltfMesh = new GlTF_Mesh(G); gltfMesh.name = GlTF_Mesh.GetNameFromObject(meshNameAndId); gltfMesh.PresentationNameOverride = mesh.geometryName; m_meshCache.Add(pool, gltfMesh); // Populate mesh data only once. AddMeshDependencies(meshNameAndId, mesh.exportableMaterial, gltfMesh, gltfLayout); gltfMesh.Populate(pool); G.meshes.Add(gltfMesh); } // The mesh may or may not be shared, but every mesh will have a distinct node to allow them // to have unique transforms. GlTF_Node node = GlTF_Node.GetOrCreate(G, meshNameAndId, xf, parent, out _); node.m_mesh = gltfMesh; node.PresentationNameOverride = mesh.nodeName; return(node); }
public Bipyramid(Vector3 a, Vector3 b, int polySegments = 6, float lengthFraction = 0.5f, float?radiusFraction = null, float?absoluteRadius = null, Transform transform = null, Matrix4x4?overrideMatrix = null) { this.a = a; this.b = b; this.polySegments = polySegments; this.lengthFraction = lengthFraction; this.radiusFraction = radiusFraction; this.absoluteRadius = absoluteRadius; this.transform = transform; this.overrideMatrix = overrideMatrix; }
public HandleDisposable(Matrix4x4 matrix) { //Cache the old matrix _oldTransform = Handles.matrix; Handles.matrix = matrix; }
/// <summary> /// 変換行列キャッシュの破棄 /// </summary> /// <remarks> /// <see cref="Transformable"/> および <see cref="Node"/> は高速化のために一度計算した変換行列をキャッシュして再利用します。 /// このメソッドはキャッシュを破棄し次回取得する際に再計算させます。 /// ユーザーがこのメソッドを呼ぶ必要はありません。 /// <note type="implement"> /// このメソッドをオーバーライドした場合、かならずオーバーライドされた基底クラスのメソッドを呼び出してください。 /// </note> /// </remarks> public virtual void InvalidateTransformCache() { this.matrix = null; }
void OnPostRender() { EnsureMaterial(ref velocityMaterial, velocityShader); if (_camera.orthographic || _camera.depthTextureMode == DepthTextureMode.None || velocityMaterial == null) { if (_camera.depthTextureMode == DepthTextureMode.None) _camera.depthTextureMode = DepthTextureMode.Depth; return; } timeScale = timeScaleNextFrame; timeScaleNextFrame = (Time.timeScale == 0f) ? timeScaleNextFrame : Time.timeScale; int bufferW = _camera.pixelWidth; int bufferH = _camera.pixelHeight; EnsureRenderTarget(ref velocityBuffer, bufferW, bufferH, velocityFormat, FilterMode.Point, 16); EnsureKeyword(velocityMaterial, "TILESIZE_10", neighborMaxSupport == NeighborMaxSupport.TileSize10); EnsureKeyword(velocityMaterial, "TILESIZE_20", neighborMaxSupport == NeighborMaxSupport.TileSize20); EnsureKeyword(velocityMaterial, "TILESIZE_40", neighborMaxSupport == NeighborMaxSupport.TileSize40); Matrix4x4 cameraP = _camera.projectionMatrix; Matrix4x4 cameraV = _camera.worldToCameraMatrix; Matrix4x4 cameraVP = cameraP * cameraV; if (velocityViewMatrix == null) velocityViewMatrix = cameraV; RenderTexture activeRT = RenderTexture.active; RenderTexture.active = velocityBuffer; { GL.Clear(true, true, Color.black); const int kPrepass = 0; const int kVertices = 1; const int kVerticesSkinned = 2; const int kTileMax = 3; const int kNeighborMax = 4; // 0: prepass var jitter = GetComponent<FrustumJitter>(); if (jitter != null) velocityMaterial.SetVector("_Corner", _camera.GetPerspectiveProjectionCornerRay(jitter.activeSample.x, jitter.activeSample.y)); else velocityMaterial.SetVector("_Corner", _camera.GetPerspectiveProjectionCornerRay()); velocityMaterial.SetMatrix("_CurrV", cameraV); velocityMaterial.SetMatrix("_CurrVP", cameraVP); velocityMaterial.SetMatrix("_PrevVP", cameraP * velocityViewMatrix.Value); velocityMaterial.SetPass(kPrepass); FullScreenQuad(); // 1 + 2: vertices + vertices skinned var obs = VelocityBufferTag.activeObjects; #if UNITY_EDITOR numResident = obs.Count; numRendered = 0; numDrawCalls = 0; #endif for (int i = 0, n = obs.Count; i != n; i++) { var ob = obs[i]; if (ob != null && ob.sleeping == false && ob.mesh != null) { velocityMaterial.SetMatrix("_CurrM", ob.localToWorldCurr); velocityMaterial.SetMatrix("_PrevM", ob.localToWorldPrev); velocityMaterial.SetPass(ob.useSkinnedMesh ? kVerticesSkinned : kVertices); for (int j = 0; j != ob.mesh.subMeshCount; j++) { Graphics.DrawMeshNow(ob.mesh, Matrix4x4.identity, j); #if UNITY_EDITOR numDrawCalls++; #endif } #if UNITY_EDITOR numRendered++; #endif } } // 3 + 4: tilemax + neighbormax if (neighborMaxGen) { int tileSize = 1; switch (neighborMaxSupport) { case NeighborMaxSupport.TileSize10: tileSize = 10; break; case NeighborMaxSupport.TileSize20: tileSize = 20; break; case NeighborMaxSupport.TileSize40: tileSize = 40; break; } int neighborMaxW = bufferW / tileSize; int neighborMaxH = bufferH / tileSize; EnsureRenderTarget(ref velocityNeighborMax, neighborMaxW, neighborMaxH, velocityFormat, FilterMode.Bilinear, 0); // tilemax RenderTexture tileMax = RenderTexture.GetTemporary(neighborMaxW, neighborMaxH, 0, velocityFormat); RenderTexture.active = tileMax; { velocityMaterial.SetTexture("_VelocityTex", velocityBuffer); velocityMaterial.SetVector("_VelocityTex_TexelSize", new Vector4(1f / bufferW, 1f / bufferH, 0f, 0f)); velocityMaterial.SetPass(kTileMax); FullScreenQuad(); } // neighbormax RenderTexture.active = velocityNeighborMax; { velocityMaterial.SetTexture("_VelocityTex", tileMax); velocityMaterial.SetVector("_VelocityTex_TexelSize", new Vector4(1f / neighborMaxW, 1f / neighborMaxH, 0f, 0f)); velocityMaterial.SetPass(kNeighborMax); FullScreenQuad(); } RenderTexture.ReleaseTemporary(tileMax); } else if (velocityNeighborMax != null) { RenderTexture.ReleaseTemporary(velocityNeighborMax); velocityNeighborMax = null; } } RenderTexture.active = activeRT; velocityViewMatrix = cameraV; }
void UpdateTransformMatrix() { Matrix4x4 matrix = Matrix4x4.identity; if (_skew.x != 0 || _skew.y != 0) ToolSet.SkewMatrix(ref matrix, _skew.x, _skew.y); if (_perspective) matrix *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(_rotation), Vector3.one); Vector3 camPos = Vector3.zero; if (matrix.isIdentity) _transformMatrix = null; else { _transformMatrix = matrix; camPos = new Vector3(_pivot.x * _contentRect.width, -_pivot.y * _contentRect.height, _focalLength); } //组件的transformMatrix是通过paintingMode实现的,因为全部通过矩阵变换的话,和unity自身的变换混杂在一起,无力理清。 if (_transformMatrix != null) { if (this is Container) this.EnterPaintingMode(3, null); } else { if (this is Container) this.LeavePaintingMode(3); } if (this._paintingMode > 0) { this.paintingGraphics.cameraPosition = camPos; this.paintingGraphics.vertexMatrix = _transformMatrix; this._paintingFlag = 1; } else if (this.graphics != null) { this.graphics.cameraPosition = camPos; this.graphics.vertexMatrix = _transformMatrix; _requireUpdateMesh = true; } }
public GizmoDisposable(Matrix4x4 matrix) { //Cache the old matrix _oldTransform = Gizmos.matrix; Gizmos.matrix = matrix; }