Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UNRI2-113, UNRI2-105, and UNRI2-106 PR's combined into one. #6

Merged
merged 6 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/*
12 changes: 12 additions & 0 deletions dgi_3d_viewer.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,15 @@ description: View 3D objects in Drupal.
package: Media
type: module
core_version_requirement: ^9
dependencies:
- entity_reference_revisions:entity_reference_revisions
- drupal:field
- field_group:field_group
- drupal:file
- filehash:filehash
- drupal:language
- drupal:media
- paragraphs:paragraphs
- drupal:path
- islandora:islandora
- islandora_defaults:islandora_defaults
Comment on lines +7 to +17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encountering in the context of D10 stuff, but anything not in core here should be declared in the composer.json.

... though, I also wonder: How much are we actually dependent on? Grep'ing for entity_reference_revisions, field_group, filehash, islandora and islandora_defaults, only finding this info.yml. Only real direct non-core dependency is paragraphs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Planning to adjust things in #16

4 changes: 2 additions & 2 deletions dgi_3d_viewer.libraries.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Test library for compiling threejs pieces into a single file.
test_threejs:
js:
js/test_threejs.js:
js/dist/test_threejs.js:
attributes:
type: module
dependencies:
Expand All @@ -12,7 +12,7 @@ test_threejs:
# The compiled js for rendering a viewer powered by Three.js
dgi_3d_viewer:
js:
js/dgi_3d_viewer.js:
js/dist/dgi_3d_viewer.js:
attributes:
type: module
dependencies:
Expand Down
77 changes: 77 additions & 0 deletions dgi_3d_viewer.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/**
* @file
* Hook implementations.
*/

use Drupal\Core\Asset\AttachedAssetsInterface;
use Drupal\paragraphs\ParagraphInterface;
use Drupal\media\MediaInterface;

/**
* Implements hook_ENTITY_TYPE_presave().
*/
function dgi_3d_viewer_media_presave(MediaInterface $media) {
if ($media->bundle() !== '3d_object') {
return;
}
$camera = $media->get('field_camera')->referencedEntities()[0] ?? NULL;

if (!$camera) {
$media->field_customcamera = NULL;
return;
}

$camera_settings = dgi_3d_viewer_flatten_camera_values($camera);

$media->field_customcamera = serialize($camera_settings);
}

/**
* Flatten camera values.
*/
function dgi_3d_viewer_flatten_camera_values(ParagraphInterface $camera) {
$type = $camera->bundle();
$camera_settings = [
'settings' => [
'near' => $camera->field_near->value,
'far' => $camera->field_far->value,
'position' => [
'x' => $camera->field_position_x->value,
'y' => $camera->field_position_y->value,
'z' => $camera->field_position_z->value,
],
'rotation' => [
'x' => $camera->field_rotation_x->value,
'y' => $camera->field_rotation_y->value,
'z' => $camera->field_rotation_z->value,
],
],
];
switch ($type) {
case 'orthographic_camera_settings':
$camera_settings['type'] = 'OrthographicCamera';
$camera_settings['settings']['top'] = $camera->field_top->value;
$camera_settings['settings']['bottom'] = $camera->field_bottom->value;
$camera_settings['settings']['left'] = $camera->field_left->value;
$camera_settings['settings']['right'] = $camera->field_right->value;
break;

case 'perspective_camera_settings':
$camera_settings['type'] = 'PerspectiveCamera';
$camera_settings['settings']['aspect'] = $camera->field_aspect->value;
$camera_settings['settings']['fov'] = $camera->field_fov->value;
break;
}

return $camera_settings;
}
Comment on lines +31 to +69
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If, instead of rolling paragraphs, we rolled our own field type(s?) explicitly for the purpose, it could have all this (re)structuring built in to it.


/**
* Implements hook_js_settings_alter().
*/
function dgi_3d_viewer_js_settings_alter(array &$settings, AttachedAssetsInterface $assets) {
// Check if prod split is enabled.
$settings['isProd'] = \Drupal::config('config_split.config_split.prod')->get('status');
}
Comment on lines +71 to +77
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really not be binding to some other arbitrary configuration... as in, strictly, this entire module should now be dependent on the config_split.config_split.prod split existing.

... we should either have a module-specific debug flag, or make use of Drupal core's devel/error reporting stuff, maybe https://github.com/discoverygarden/dgi-starter/blob/43a70275f535b94705b58d3b6997882efcd23892/config/sync/system.logging.yml#L3 ?

Loading