universo-platform-3d

Форк
0
349 строк · 6.9 Кб
1
import { ApiProperty } from '@nestjs/swagger'
2
import {
3
  ArrayMinSize,
4
  IsArray,
5
  IsBoolean,
6
  IsNotEmpty,
7
  IsNumber,
8
  IsObject,
9
  IsOptional,
10
  IsString,
11
  MaxLength,
12
  ValidateIf
13
} from 'class-validator'
14
import { ASSET_TYPE } from '../../option-sets/asset-type'
15
import { Vector4AsArray } from '../../option-sets/vectors'
16
import { ROLE } from '../../roles/models/role.enum'
17
import { Tags } from '../../tag/models/tags.schema'
18
import { Transform } from 'class-transformer'
19
import { ObjectId } from 'mongodb'
20

21
export class CreateAssetDto {
22
  /**
23
   * Required properties
24
   */
25
  @IsNotEmpty()
26
  @IsString()
27
  @MaxLength(300) // abitrary max length
28
  @ApiProperty({
29
    example: 'An Awesome Asset',
30
    required: true
31
  })
32
  name: string
33

34
  @IsNotEmpty()
35
  @IsString()
36
  @ApiProperty({ enum: ASSET_TYPE })
37
  assetType: ASSET_TYPE
38

39
  /**
40
   * Optional Properties
41
   */
42
  @IsOptional()
43
  @ApiProperty({
44
    example: 'The default role permission for this Asset',
45
    enum: ROLE,
46
    required: false
47
  })
48
  defaultRole?: ROLE
49

50
  @IsOptional()
51
  @MaxLength(5000) // abitrary max length
52
  @ApiProperty({
53
    required: false,
54
    example: "The Awesome Asset's Description"
55
  })
56
  description?: string
57

58
  @IsOptional()
59
  @IsBoolean()
60
  @ApiProperty({ required: false })
61
  mirrorPublicLibrary?: boolean
62

63
  @IsOptional()
64
  @IsString()
65
  @ApiProperty({ required: false })
66
  customData?: string
67

68
  /**
69
   * START Section: Third Party Source for Mirror Public Library
70
   */
71
  @IsOptional()
72
  @IsString()
73
  @ApiProperty({
74
    required: false,
75
    example: 'CG Trader'
76
  })
77
  thirdPartySourceDisplayName?: string
78

79
  @IsOptional()
80
  @IsString()
81
  @ApiProperty({
82
    required: false,
83
    example: 'https://www.cgtrader.com/'
84
  })
85
  thirdPartySourceUrl?: string
86
  /**
87
   * END Section: Third Party Source for Mirror Public Library
88
   */
89

90
  @IsOptional()
91
  @IsString()
92
  @ApiProperty({
93
    required: false
94
  })
95
  thumbnail?: string
96

97
  /**
98
   * @deprecated use tagsV2 instead (separate collection)
99
   */
100
  @IsOptional()
101
  @IsString({ each: true })
102
  @ApiProperty({ required: false })
103
  categories?: string[]
104

105
  @IsOptional()
106
  @MaxLength(5000) // abitrary max length
107
  @ApiProperty({ required: false })
108
  currentFile?: string
109

110
  @IsOptional()
111
  @MaxLength(64)
112
  @ApiProperty({ required: false })
113
  fileHash?: string
114

115
  @IsOptional()
116
  @IsBoolean()
117
  @ApiProperty({ required: false })
118
  public?: boolean
119

120
  // Transform properties.
121
  @IsOptional()
122
  @IsNumber()
123
  @ApiProperty({ required: false })
124
  initPositionX?: number
125

126
  @IsOptional()
127
  @IsNumber()
128
  @ApiProperty({ required: false })
129
  initPositionY?: number
130

131
  @IsOptional()
132
  @IsNumber()
133
  @ApiProperty({ required: false })
134
  initPositionZ?: number
135

136
  @IsOptional()
137
  @IsNumber()
138
  @ApiProperty({ required: false })
139
  initRotationX?: number
140

141
  @IsOptional()
142
  @IsNumber()
143
  @ApiProperty({ required: false })
144
  initRotationY?: number
145

146
  @IsOptional()
147
  @IsNumber()
148
  @ApiProperty({ required: false })
149
  initRotationZ?: number
150

151
  @IsOptional()
152
  @IsNumber()
153
  @ApiProperty({ required: false })
154
  initScaleX?: number
155

156
  @IsOptional()
157
  @IsNumber()
158
  @ApiProperty({ required: false })
159
  initScaleY?: number
160

161
  @IsOptional()
162
  @IsNumber()
163
  @ApiProperty({ required: false })
164
  initScaleZ?: number
165

166
  // Physics properties.
167
  @IsOptional()
168
  @IsBoolean()
169
  @ApiProperty({ required: false })
170
  collisionEnabled?: boolean
171

172
  @IsOptional()
173
  @IsBoolean()
174
  @ApiProperty({ required: false })
175
  staticEnabled?: boolean
176

177
  @IsOptional()
178
  @IsNumber()
179
  @ApiProperty({ required: false })
180
  massKg?: number
181

182
  @IsOptional()
183
  @IsNumber()
184
  @ApiProperty({ required: false })
185
  gravityScale?: number
186

187
  // Material properties.
188
  @IsOptional()
189
  @ApiProperty({ required: false })
190
  objectColor?: Vector4AsArray
191

192
  @IsOptional()
193
  @ApiProperty({ required: false })
194
  tags?: Tags
195

196
  @IsOptional()
197
  @ApiProperty({ required: false })
198
  assetPack?: boolean
199

200
  @ValidateIf((o) => o.assetPack)
201
  @IsNotEmpty()
202
  @Transform(({ value }) => value.map((id: string) => new ObjectId(id)))
203
  @IsArray()
204
  @ApiProperty({ required: false })
205
  assetsInPack?: string[]
206
}
207

208
// See https://www.loom.com/share/7e09d2777ef94368bcd5fd8c8341b5ef for walkthrough of DTOs with discriminators
209
export class CreateMaterialDto extends CreateAssetDto {
210
  @IsOptional()
211
  @IsString()
212
  @ApiProperty({ required: false })
213
  materialName?: string
214

215
  @IsOptional()
216
  @IsString()
217
  @ApiProperty({ required: false })
218
  materialTransparencyMode?: string
219

220
  @IsOptional()
221
  @IsString()
222
  @ApiProperty({ required: false })
223
  materialTransparencyProperties?: string
224

225
  @IsOptional()
226
  @IsArray()
227
  @ApiProperty({
228
    required: false,
229
    description: 'Array of ObjectIDs of Textures (Assets)'
230
  })
231
  textures?: string
232

233
  @IsOptional()
234
  @IsObject()
235
  @ApiProperty()
236
  parameters: any
237

238
  @IsOptional()
239
  @IsArray()
240
  @ApiProperty({
241
    required: false,
242
    description: 'Array of ObjectIDs of Textures (Assets)'
243
  })
244
  externalAssetIds?: string
245

246
  @IsOptional()
247
  @IsString()
248
  @ApiProperty()
249
  materialType: string
250

251
  @IsOptional()
252
  @IsString()
253
  @ApiProperty({ required: false })
254
  code?: string
255
}
256

257
export class CreateTextureDto extends CreateAssetDto {
258
  @IsOptional()
259
  @IsString()
260
  @ApiProperty({ required: false })
261
  textureImageFileHashMD5?: string
262

263
  @IsOptional()
264
  @IsString()
265
  @ApiProperty({ required: false })
266
  textureLowQualityFileHashMD5?: string
267

268
  @IsOptional()
269
  @IsString()
270
  @ApiProperty({ required: false })
271
  textureImagePropertyAppliesTo?: string
272
}
273

274
export class CreateMapDto extends CreateAssetDto {
275
  @IsOptional()
276
  @IsString()
277
  @ApiProperty({ required: false })
278
  mapName?: string
279

280
  // Heightmap Image property. This references an Asset
281
  @IsOptional()
282
  @ApiProperty({ required: false })
283
  heightmapAssetId?: string
284

285
  // Material property. This references an Asset
286
  @IsOptional()
287
  @ApiProperty({ required: false })
288
  flatMaterialAssetId?: string
289

290
  // Material property. This references an Asset
291
  @IsOptional()
292
  @ApiProperty({ required: false })
293
  cliffMaterialAssetId?: string
294

295
  @IsOptional()
296
  @IsNumber()
297
  @ApiProperty({ required: false })
298
  mapSize?: number
299

300
  @IsOptional()
301
  @IsNumber()
302
  @ApiProperty({ required: false })
303
  mapPrecision?: number
304

305
  @IsOptional()
306
  @IsNumber()
307
  @ApiProperty({ required: false })
308
  heightScale?: number
309

310
  @IsOptional()
311
  @IsNumber()
312
  @ApiProperty({ required: false })
313
  layerOffset?: number
314

315
  @IsOptional()
316
  @IsNumber()
317
  @ApiProperty({ required: false })
318
  flatUVScale?: number
319

320
  @IsOptional()
321
  @IsNumber()
322
  @ApiProperty({ required: false })
323
  cliffUVScale?: number
324

325
  @IsOptional()
326
  @IsNumber()
327
  @ApiProperty({ required: false })
328
  flatCliffRatio?: number
329

330
  @IsOptional()
331
  @IsArray()
332
  @IsNumber({}, { each: true })
333
  @ApiProperty({ required: false })
334
  flatColor?: Vector4AsArray
335

336
  @IsOptional()
337
  @IsArray()
338
  @IsNumber({}, { each: true })
339
  @ApiProperty({ required: false })
340
  cliffColor?: Vector4AsArray
341

342
  @IsOptional()
343
  @ApiProperty({ required: false })
344
  colormapAssetId?: string
345

346
  @IsOptional()
347
  @ApiProperty({ required: false })
348
  colormapStrength?: number
349
}
350

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.