# <vgl-shape>

# Example Usage

<template>
  <div>
    <vgl-renderer>
      <template #scene>
        <vgl-scene>
          <vgl-mesh>
            <template #geometry>
              <vgl-shape-geometry>
                <template #shapes>
                  <vgl-shape
                    :d="outerD[outerPath]"
                    auto-close
                  >
                    <template #holes>
                      <vgl-path
                        v-for="{ key, path, offset: [x, y] } of innerPaths"
                        :key="key"
                        :d="'M' + x + ' ' + y + innerD[path]"
                        auto-close
                      />
                    </template>
                  </vgl-shape>
                </template>
              </vgl-shape-geometry>
            </template>
            <template #material>
              <vgl-mesh-basic-material />
            </template>
          </vgl-mesh>
        </vgl-scene>
      </template>
      <template #camera>
        <vgl-orthographic-camera
          rotation="lookAt"
          :position-z="1"
          :top="11"
          :bottom="-11"
        />
      </template>
    </vgl-renderer>
    <aside>
      <label>
        Outer path:
        <select v-model="outerPath">
          <option value="square">Square</option>
          <option value="triangle">Triangle</option>
        </select>
      </label>
      <div>
        Inner paths:
        <div
          v-for="{ key, path, offset: [x, y] } of innerPaths"
          :key="key"
        >
          <label>
            Path {{ key }}:
            <select
              :selected="path"
              @change="setPath(key, $event)"
            >
              <option value="square">Square</option>
              <option value="triangle">Triangle</option>
            </select>
          </label>
          <label>
            Offset X:
            <input
              type="range"
              min="-5"
              max="5"
              step="0.1"
              :value="x"
              @change="setOffsetX(key, $event)"
            >
          </label>
          <label>
            Offset Y:
            <input
              type="range"
              min="-5"
              max="5"
              step="0.1"
              :value="y"
              @change="setOffsetY(key, $event)"
            >
          </label>
          <button @click="deletePath(key)">
            -
          </button>
        </div>
        <button @click="addPath">
          +
        </button>
      </div>
    </aside>
  </div>
</template>

<script>
export default {
  data: () => ({
    outerPath: 'square',
    innerPaths: [],
    outerD: {
      square: 'M -10, -10 h 20 v 20 h -20',
      triangle: 'M -12, -10 h 24 l -12, 20',
    },
    innerD: {
      square: 'm -2, -2 h 4 v 4 h -4',
      triangle: 'm -2.5, -2 h 5 l -2.5, 4',
    },
    maxKey: 1,
  }),
  methods: {
    deletePath(targetKey) {
      this.innerPaths.splice(this.innerPaths.findIndex(({ key }) => key === targetKey), 1);
    },
    addPath() {
      this.innerPaths.push({ key: this.maxKey, path: 'square', offset: [0, 0] });
      this.maxKey += 1;
    },
    setPath(targetKey, { target: { value } }) {
      const index = this.innerPaths.findIndex(({ key }) => key === targetKey);
      const obj = this.innerPaths[index];
      this.innerPaths.splice(index, 1, { ...obj, path: value });
    },
    setOffsetX(targetKey, { target: { value } }) {
      const index = this.innerPaths.findIndex(({ key }) => key === targetKey);
      const obj = this.innerPaths[index];
      this.innerPaths.splice(index, 1, { ...obj, offset: [value, obj.offset[1]] });
    },
    setOffsetY(targetKey, { target: { value } }) {
      const index = this.innerPaths.findIndex(({ key }) => key === targetKey);
      const obj = this.innerPaths[index];
      this.innerPaths.splice(index, 1, { ...obj, offset: [obj.offset[0], value] });
    },
  },
};
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

# Props

  • autoClose : boolean
    Whether the path to be automatically closed or not.
  • d : string
    A path definition like SVG syntax.
    Defaults to [object Object]

# Slots

  • holes
    Paths representing lacking parts of the shape.