浏览代码

convert Matrix3 to struct

/main
xingwei.zhu 5 年前
当前提交
1f150601
共有 10 个文件被更改,包括 1063 次插入52 次删除
  1. 30
      Runtime/ui/painting/shader.cs
  2. 1
      Runtime/ui/painting/txt/mesh_generator.cs
  3. 9
      Runtime/ui/utils/basic_types/canvas_clip.cs
  4. 34
      Runtime/ui/utils/basic_types/canvas_impl.cs
  5. 8
      Runtime/ui/utils/basic_types/canvas_shader.cs
  6. 6
      Runtime/ui/utils/basic_types/canvas_utils.cs
  7. 3
      Runtime/ui/utils/basic_types/matrix.cs
  8. 8
      Runtime/ui/utils/basic_types/mesh_mesh.cs
  9. 15
      Runtime/ui/utils/basic_types/render_layer.cs
  10. 1001
      Runtime/ui/utils/basic_types/ui_matrix.cs

30
Runtime/ui/painting/shader.cs


public static Gradient linear(
Offset start, Offset end, List<Color> colors,
List<float> colorStops = null, TileMode tileMode = TileMode.clamp,
uiMatrix3 matrix = null) {
uiMatrix3? matrix = null) {
D.assert(PaintingUtils._offsetIsValid(start));
D.assert(PaintingUtils._offsetIsValid(end));
D.assert(colors != null && colors.Count >= 2);

public static Gradient radial(
Offset center, float radius, List<Color> colors,
List<float> colorStops = null, TileMode tileMode = TileMode.clamp,
uiMatrix3 matrix = null) {
uiMatrix3? matrix = null) {
D.assert(PaintingUtils._offsetIsValid(center));
D.assert(colors != null && colors.Count >= 2);

Offset center, List<Color> colors,
List<float> colorStops = null, TileMode tileMode = TileMode.clamp,
float startAngle = 0.0f, float endAngle = Mathf.PI * 2,
uiMatrix3 matrix = null) {
uiMatrix3? matrix = null) {
D.assert(PaintingUtils._offsetIsValid(center));
D.assert(colors != null && colors.Count >= 2);
D.assert(startAngle < endAngle);

public _LinearGradient(
Offset start, Offset end, List<Color> colors,
List<float> colorStops, TileMode tileMode,
uiMatrix3 matrix = null) {
uiMatrix3? matrix = null) {
this.start = start;
this.end = end;
this.colors = colors;

public readonly List<Color> colors;
public readonly List<float> colorStops;
public readonly TileMode tileMode;
public readonly uiMatrix3 matrix;
public readonly uiMatrix3? matrix;
public readonly uiMatrix3 ptsToUnit;
public readonly Image gradientTex;

public uiMatrix3 getGradientMat(uiMatrix3 mat) {
if (this.matrix != null) {
mat.postConcat(this.matrix);
mat.postConcat(this.matrix.Value);
}
mat.postConcat(this.ptsToUnit);

public _RadialGradient(
Offset center, float radius, List<Color> colors,
List<float> colorStops = null, TileMode tileMode = TileMode.clamp,
uiMatrix3 matrix = null
uiMatrix3? matrix = null
) {
this.center = center;
this.radius = radius;

public readonly List<Color> colors;
public readonly List<float> colorStops;
public readonly TileMode tileMode;
public readonly uiMatrix3 matrix;
public readonly uiMatrix3? matrix;
public readonly uiMatrix3 ptsToUnit;
public readonly Image gradientTex;

public uiMatrix3 getGradientMat(uiMatrix3 mat) {
if (this.matrix != null) {
mat.postConcat(this.matrix);
mat.postConcat(this.matrix.Value);
}
mat.postConcat(this.ptsToUnit);

Offset center, List<Color> colors,
List<float> colorStops = null, TileMode tileMode = TileMode.clamp,
float startAngle = 0.0f, float endAngle = Mathf.PI * 2,
uiMatrix3 matrix = null
uiMatrix3? matrix = null
) {
this.center = center;
this.colors = colors;

public readonly TileMode tileMode;
public readonly float startAngle;
public readonly float endAngle;
public readonly uiMatrix3 matrix;
public readonly uiMatrix3? matrix;
public readonly uiMatrix3 ptsToUnit;
public readonly Image gradientTex;
public readonly float bias;

public uiMatrix3 getGradientMat(uiMatrix3 mat) {
if (this.matrix != null) {
mat.postConcat(this.matrix);
mat.postConcat(this.matrix.Value);
}
mat.postConcat(this.ptsToUnit);

public class ImageShader : PaintShader {
public ImageShader(Image image,
TileMode tileMode = TileMode.clamp, uiMatrix3 matrix = null) {
TileMode tileMode = TileMode.clamp, uiMatrix3? matrix = null) {
this.image = image;
this.tileMode = tileMode;
this.matrix = matrix;

public readonly TileMode tileMode;
public readonly uiMatrix3 matrix;
public readonly uiMatrix3? matrix;
mat.postConcat(this.matrix);
mat.postConcat(this.matrix.Value);
}
mat.postScale(1f / this.image.width, 1f / this.image.height);

1
Runtime/ui/painting/txt/mesh_generator.cs


public override void clear() {
this.textBlob = null;
this.matrix = null;
this._mesh?.dispose();
this._mesh = null;
this._resolved = false;

9
Runtime/ui/utils/basic_types/canvas_clip.cs


uint _genId;
bool _isIntersectionOfRects;
uiRect _bound;
uiMatrix3 _invMat;
uiMatrix3? _invMat;
public ClipElement() {

}
if (this.convex) {
if (this.mesh.matrix != null && !this.mesh.matrix.isIdentity()) {
if (this.mesh.matrix != null && !this.mesh.matrix.Value.isIdentity()) {
this._invMat = uiMatrix3.I();
this.mesh.matrix.invert(this._invMat); // ignore if not invertible for now.
this._invMat = this.mesh.matrix.Value.invert();
rect = this._invMat.mapRect(rect);
rect = this._invMat.Value.mapRect(rect);
}
return this._convexContains(rect);

34
Runtime/ui/utils/basic_types/canvas_impl.cs


var filter = (_BlurImageFilter) paint.backdrop;
if (!(filter.sigmaX == 0 && filter.sigmaY == 0)) {
var points = new[] {bounds.topLeft, bounds.bottomLeft, bounds.bottomRight, bounds.topRight};
state.matrix.mapPoints(points);
state.matrix.Value.mapPoints(points);
var parentBounds = parentLayer.layerBounds;
for (int i = 0; i < 4; i++) {

layer.filterMode = filter.filterMode;
var points = new[] {bounds.topLeft, bounds.bottomLeft, bounds.bottomRight, bounds.topRight};
state.matrix.mapPoints(points);
state.matrix.Value.mapPoints(points);
var parentBounds = parentLayer.layerBounds;
for (int i = 0; i < 4; i++) {

void _translate(float dx, float dy) {
var state = this._currentLayer.currentState;
var matrix = uiMatrix3.makeTrans(dx, dy);
matrix.postConcat(state.matrix);
matrix.postConcat(state.matrix.Value);
state.matrix = matrix;
}

matrix.postConcat(state.matrix);
matrix.postConcat(state.matrix.Value);
state.matrix = matrix;
}

var matrix = uiMatrix3.makeRotate(radians);
matrix.postConcat(state.matrix);
matrix.postConcat(state.matrix.Value);
matrix.postConcat(state.matrix);
matrix.postConcat(state.matrix.Value);
state.matrix = matrix;
}
}

var matrix = uiMatrix3.makeSkew(sx, sy);
matrix.postConcat(state.matrix);
matrix.postConcat(state.matrix.Value);
state.matrix = matrix;
}

matrix.postConcat(state.matrix);
matrix.postConcat(state.matrix.Value);
state.matrix = matrix;
}

void _clipPath(uiPath path) {
var layer = this._currentLayer;
var state = layer.currentState;
layer.clipStack.clipPath(path, state.matrix, state.scale * this._devicePixelRatio);
layer.clipStack.clipPath(path, state.matrix.Value, state.scale * this._devicePixelRatio);
path.dispose();
}

var state = this._currentLayer.currentState;
var scale = state.scale * this._devicePixelRatio;
var matrix = new uiMatrix3(state.matrix);
var matrix = new uiMatrix3(state.matrix.Value);
matrix.preTranslate(offset.dx, offset.dy);
var mesh = TextBlobMesh.create(textBlob, scale, matrix);

cmd.properties.SetFloatArray(CmdDraw.matId, CmdDraw.idMat3.fMat);
}
else {
cmd.properties.SetFloatArray(CmdDraw.matId, mesh.matrix.fMat);
var mat = mesh.matrix.Value;
var array = new[] {
mat.kMScaleX, //0
mat.kMSkewX, //1
mat.kMTransX, //2
mat.kMSkewY, //3
mat.kMScaleY, //4
mat.kMTransY, //5
mat.kMPersp0, //6
mat.kMPersp1, //7
mat.kMPersp2 //8
};
cmd.properties.SetFloatArray(CmdDraw.matId, array);
}
cmdBuf.DrawMesh(cmd.meshObj, CmdDraw.idMat, cmd.material, 0, cmd.pass, cmd.properties);

8
Runtime/ui/utils/basic_types/canvas_shader.cs


);
}
static uiMatrix3 _getShaderMatBase(PictureFlusher.State state, uiMatrix3 meshMatrix) {
if (state.matrix == meshMatrix) {
static uiMatrix3 _getShaderMatBase(PictureFlusher.State state, uiMatrix3? meshMatrix) {
if (uiMatrix3.equals(state.matrix, meshMatrix)) {
return uiMatrix3.I();
}

return uiMatrix3.concat(state.invMatrix, meshMatrix);
return uiMatrix3.concat(state.invMatrix, meshMatrix.Value);
PictureFlusher.RenderLayer layer, Paint paint, uiMatrix3 meshMatrix, float alpha,
PictureFlusher.RenderLayer layer, Paint paint, uiMatrix3? meshMatrix, float alpha,
out int pass, out MaterialPropertyBlock props) {
Vector4 viewport = layer.viewport;

6
Runtime/ui/utils/basic_types/canvas_utils.cs


10, 11, 14, 11, 15, 14,
};
public static uiMeshMesh imageMesh(uiMatrix3 matrix,
public static uiMeshMesh imageMesh(uiMatrix3? matrix,
Offset srcTL, Offset srcBL, Offset srcBR, Offset srcTR,
uiRect dst) {
var vertices = ItemPoolManager.alloc<uiList<Vector3>>();

return uiMeshMesh.create(matrix, vertices, _triangles, uv);
}
public static uiMeshMesh imageMesh(uiMatrix3 matrix, uiRect src, uiRect dst) {
public static uiMeshMesh imageMesh(uiMatrix3? matrix, uiRect src, uiRect dst) {
var vertices = ItemPoolManager.alloc<uiList<Vector3>>();
vertices.SetCapacity(4);

return uiMeshMesh.create(matrix, vertices, _triangles, uv);
}
public static uiMeshMesh imageNineMesh(uiMatrix3 matrix, uiRect src, uiRect center, int srcWidth, int srcHeight, uiRect dst) {
public static uiMeshMesh imageNineMesh(uiMatrix3? matrix, uiRect src, uiRect center, int srcWidth, int srcHeight, uiRect dst) {
float x0 = dst.left;
float x3 = dst.right;
float x1 = x0 + ((center.left - src.left) * srcWidth);

3
Runtime/ui/utils/basic_types/matrix.cs


using UnityEngine;
namespace Unity.UIWidgets.ui {
/*
public class uiMatrix3 : IEquatable<uiMatrix3> {
public static uiMatrix3 makeScale(float sx, float sy) {
var m = new uiMatrix3();

return 1.0f / (float) det;
}
}
}*/
}

8
Runtime/ui/utils/basic_types/mesh_mesh.cs


public uiList<Vector3> vertices;
public uiList<int> triangles;
public uiList<Vector2> uv;
public uiMatrix3 matrix;
public uiMatrix3? matrix;
public uiRect rawBounds;
uiRect? _bounds;

if (this._bounds == null) {
this._bounds = this.matrix != null ? this.matrix.mapRect(this.rawBounds) : this.rawBounds;
this._bounds = this.matrix != null ? this.matrix.Value.mapRect(this.rawBounds) : this.rawBounds;
}
return this._bounds.Value;

return newMesh;
}
public static uiMeshMesh create(uiMatrix3 matrix, uiList<Vector3> vertices, uiList<int> triangles, uiList<Vector2> uv = null,
public static uiMeshMesh create(uiMatrix3? matrix, uiList<Vector3> vertices, uiList<int> triangles, uiList<Vector2> uv = null,
uiRect? rawBounds = null) {
D.assert(vertices != null);
D.assert(vertices.Count >= 0);

return this.transform(this.matrix);
}
public uiMeshMesh transform(uiMatrix3 matrix) {
public uiMeshMesh transform(uiMatrix3? matrix) {
var vertices = ItemPoolManager.alloc<uiList<Vector3>>();
vertices.SetCapacity(this.vertices.Count);
vertices.AddRange(this.vertices.data);

15
Runtime/ui/utils/basic_types/render_layer.cs


static readonly uiMatrix3 _id = uiMatrix3.I();
uiMatrix3 _matrix;
uiMatrix3? _matrix;
uiMatrix3 _invMatrix;
uiMatrix3? _invMatrix;
public static State create(uiMatrix3 matrix = null, float? scale = null, uiMatrix3 invMatrix = null) {
public static State create(uiMatrix3? matrix = null, float? scale = null, uiMatrix3? invMatrix = null) {
State newState = ItemPoolManager.alloc<State>();
newState._matrix = matrix ?? _id;
newState._scale = scale;

this._invMatrix = null;
}
public uiMatrix3 matrix {
public uiMatrix3? matrix {
get { return this._matrix; }
set {
this._matrix = value ?? _id;

public float scale {
get {
if (this._scale == null) {
this._scale = uiXformUtils.getScale(this._matrix);
this._scale = uiXformUtils.getScale(this._matrix.Value);
}
return this._scale.Value;
}

get {
if (this._invMatrix == null) {
this._invMatrix = uiMatrix3.I();
this._matrix.invert(this._invMatrix);
this._invMatrix = this._matrix.Value.invert();
return this._invMatrix;
return this._invMatrix.Value;
}
}

1001
Runtime/ui/utils/basic_types/ui_matrix.cs
文件差异内容过多而无法显示
查看文件

正在加载...
取消
保存