Tanoda
MeshUtil.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System;
10using System.Collections.Generic;
11using UnityEngine;
12using UnityEngine.Rendering;
13using Leap.Unity.Query;
14
16
17 public static class MeshUtil {
18 public const int MAX_VERT_COUNT = 65535;
19
20 public static List<UVChannelFlags> allUvChannels;
21 static MeshUtil() {
22 allUvChannels = new List<UVChannelFlags>();
23 allUvChannels.Add(UVChannelFlags.UV0);
24 allUvChannels.Add(UVChannelFlags.UV1);
25 allUvChannels.Add(UVChannelFlags.UV2);
26 allUvChannels.Add(UVChannelFlags.UV3);
27 }
28
29 public static void RemapUvs(List<Vector4> uvs, Rect mapping) {
30 RemapUvs(uvs, mapping, uvs.Count);
31 }
32
33 public static void RemapUvs(List<Vector4> uvs, Rect mapping, int lastCount) {
34 for (int i = uvs.Count - lastCount; i < uvs.Count; i++) {
35 Vector4 uv = uvs[i];
36 uv.x = mapping.x + uv.x * mapping.width;
37 uv.y = mapping.y + uv.y * mapping.height;
38 uvs[i] = uv;
39 }
40 }
41
42 public static int Index(this UVChannelFlags flags) {
43 switch (flags) {
44 case UVChannelFlags.UV0:
45 return 0;
46 case UVChannelFlags.UV1:
47 return 1;
48 case UVChannelFlags.UV2:
49 return 2;
50 case UVChannelFlags.UV3:
51 return 3;
52 }
53 throw new InvalidOperationException();
54 }
55 }
56}