A few thumbnail changes.

This commit is contained in:
Graphictoria 2022-08-25 22:07:30 -04:00
parent 6d7b781470
commit fd22eb092c
4 changed files with 104 additions and 4 deletions

View File

@ -52,19 +52,25 @@ class ThumbnailController extends Controller
$valid = $validator->valid();
$model = ('App\\Models\\' . $renderType)::where('id', $valid['id'])->first();
$valid['type'] = strtolower($valid['type']);
if($renderType == 'User') {
if($valid['position'] == null)
$valid['position'] = 'Full';
$valid['position'] = strtolower($valid['position']);
} elseif($renderType == 'Asset') {
if(!$model->{$valid['type'] == '3d' ? 'canRender3D' : 'isRenderable'}()) {
$validator->errors()->add('id', 'This asset cannot be rendered.');
return ValidationHelper::generateValidatorError($validator);
}
// TODO: XlXi: Turn this into a switch case and fill in the rest of the unrenderables.
// Things like HTML assets should just have a generic "default" image.
if($model->assetTypeId == 1)
$model = Asset::where('id', $model->parentAsset)->first();
}
$valid['type'] = strtolower($valid['type']);
if($model->thumbnail2DHash && $valid['type'] == '2d')
return response(['status' => 'success', 'data' => route('content', $model->thumbnail2DHash)]);

View File

@ -151,6 +151,74 @@ class Asset extends Model
return $this->belongsTo(AssetVersion::class, 'assetVersionId');
}
public function isWearable()
{
switch($this->assetTypeId)
{
case 2: // T-Shirt
case 8: // Hat
case 11: // Shirt
case 12: // Pants
case 17: // Head
case 18: // Face
case 19: // Gear
case 25: // Arms
case 26: // Legs
case 27: // Torso
case 28: // Right Arm
case 29: // Left Arm
case 30: // Left Leg
case 31: // Right Leg
case 32: // Package
return true;
}
return false;
}
public function isRenderable()
{
switch($this->assetTypeId)
{
case 2: // T-Shirt
case 4: // Mesh
case 8: // Hat
case 9: // Place
case 10: // Model
case 11: // Shirt
case 12: // Pants
case 13: // Decal
case 17: // Head
case 18: // Face
case 19: // Gear
case 25: // Arms
case 26: // Legs
case 27: // Torso
case 28: // Right Arm
case 29: // Left Arm
case 30: // Left Leg
case 31: // Right Leg
case 32: // Package
return true;
}
return false;
}
public function canRender3D()
{
switch($this->assetTypeId)
{
case 9: // Place
case 10: // Model
case 13: // Decal
case 18: // Face
return false;
}
return $this->isRenderable();
}
public function getThumbnail()
{
$renderId = $this->id;

View File

@ -88,7 +88,7 @@ const Scene = ({json}) => {
/>
</EffectComposer>
*/}
<OrbitControls makeDefault ref={controls} enableDamping={false} enablePan={false} />
<OrbitControls makeDefault ref={controls} enableDamping={false} enablePan={false} autoRotate={true} />
</>
)
}
@ -114,8 +114,13 @@ class ThumbnailTool extends Component {
this.thumbnail2d = thumbnailElement.getAttribute('data-asset-thumbnail-2d');
this.assetId = thumbnailElement.getAttribute('data-asset-id');
this.assetName = thumbnailElement.getAttribute('data-asset-name');
this.wearable = Boolean(thumbnailElement.getAttribute('data-wearable'));
this.renderable3d = Boolean(thumbnailElement.getAttribute('data-renderable3d'));
this.setState({ initialLoading: false });
if(localStorage.getItem('gt-use-3d-thumbnails') === 'true')
this.toggle3D();
}
}
@ -164,6 +169,7 @@ class ThumbnailTool extends Component {
let is3d = !this.state.is3d;
this.setState({ loading: true, is3d: is3d, seed3d: Math.random() });
localStorage.setItem('gt-use-3d-thumbnails', is3d);
if(is3d) {
this.loadThumbnail(`thumbnails/v1/asset?id=${this.assetId}&type=3D`, true);
@ -207,10 +213,24 @@ class ThumbnailTool extends Component {
/>
)
}
{ this.wearable || this.renderable3d ?
<div className='d-flex position-absolute bottom-0 end-0 pb-2 pe-2'>
<button className='btn btn-secondary me-2' onClick={ this.tryAsset } disabled={ this.state.loading }>Try On</button>
<button className='btn btn-secondary' onClick={ this.toggle3D } disabled={ this.state.loading }>{ this.state.is3d ? '2D' : '3D' }</button>
{
this.wearable ?
<button className='btn btn-secondary me-2' onClick={ this.tryAsset } disabled={ this.state.loading }>Try On</button>
:
null
}
{
this.renderable3d ?
<button className='btn btn-secondary' onClick={ this.toggle3D } disabled={ this.state.loading }>{ this.state.is3d ? '2D' : '3D' }</button>
:
null
}
</div>
:
null
}
</>
}
</>

View File

@ -62,6 +62,12 @@
data-asset-thumbnail-3d="{{ route('thumbnails.v1.asset', ['id' => $asset->id]) }}"
data-asset-name="{{ $asset->name }}"
data-asset-id="{{ $asset->id }}"
@if($asset->isWearable() && Auth::check())
data-wearable="true"
@endif
@if($asset->canRender3D())
data-renderable3d="true"
@endif
>
<img src="{{ $asset->getThumbnail() }}" alt="{{ $asset->name }}" class="img-fluid" />
</div>