Skip to content

Commit b70c635

Browse files
committed
add live support
1 parent a8ca433 commit b70c635

23 files changed

+395
-36
lines changed

src/Threejs/src/Camera/Camera.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,30 @@
1919
*/
2020
abstract class Camera
2121
{
22-
public Vector3 $position;
22+
public Vector3 $position;
23+
public string $type;
2324

24-
public function __construct(?Vector3 $position = null)
25-
{
26-
$this->position = $position ?? new Vector3(0, 0, 5);
27-
}
25+
public function __construct(?Vector3 $position = null)
26+
{
27+
$this->position = $position ?? new Vector3(0, 0, 5);
28+
}
29+
30+
public static function fromArray(array $camera): self
31+
{
32+
$camera['position'] = Vector3::fromArray($camera['position']);
33+
$type = $camera['type'];
34+
unset($camera['type']);
35+
$cameraObject = new static(...$camera);
36+
$cameraObject->type = $type;
37+
38+
return $cameraObject;
39+
}
40+
41+
public function toArray(): array
42+
{
43+
return [
44+
'type' => $this->type,
45+
'position' => $this->position->toArray(),
46+
];
47+
}
2848
}

src/Threejs/src/Camera/OrthographicCamera.php renamed to src/Threejs/src/Camera/Orthographic.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* @author Sylvain Blondeau <[email protected]>
1818
*/
19-
final class OrthographicCamera extends Camera
19+
final class Orthographic extends Camera
2020
{
2121
public string $type = 'Orthographic';
2222

src/Threejs/src/Camera/PerspectiveCamera.php renamed to src/Threejs/src/Camera/Perspective.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* @author Sylvain Blondeau <[email protected]>
1818
*/
19-
final class PerspectiveCamera extends Camera
19+
final class Perspective extends Camera
2020
{
2121
public string $type = 'Perspective';
2222

src/Threejs/src/Geometry/Box.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,16 @@ public function __construct(
2828
parent::__construct();
2929
$this->type = self::TYPE;
3030
}
31+
32+
33+
34+
public function toArray(): array
35+
{
36+
return [
37+
'width' => $this->width,
38+
'height' => $this->height,
39+
'depth' => $this->depth,
40+
'type' => $this->type,
41+
];
42+
}
3143
}

src/Threejs/src/Geometry/BufferGeometry.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,16 @@ public function __construct(
2323
{
2424
}
2525

26+
public static function fromArray(array $geometry): self
27+
{
28+
$type = $geometry['type'];
29+
unset($geometry['type']);
30+
$geometryObject = new static(...$geometry);
31+
$geometryObject->type = $type;
32+
33+
return $geometryObject;
34+
}
35+
36+
abstract public function toArray(): array;
2637

2738
}

src/Threejs/src/Geometry/Cylinder.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ public function __construct(
3333
parent::__construct();
3434
$this->type = self::TYPE;
3535
}
36+
37+
public function toArray(): array
38+
{
39+
return [
40+
'radiusTop' => $this->radiusTop,
41+
'radiusBottom' => $this->radiusBottom,
42+
'height' => $this->height,
43+
'radialSegments' => $this->radialSegments,
44+
'heightSegments' => $this->heightSegments,
45+
'openEnded' => $this->openEnded,
46+
'thetaStart' => $this->thetaStart,
47+
'thetaLength' => $this->thetaLength,
48+
];
49+
}
3650
}
3751

3852

src/Threejs/src/Geometry/Plane.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,15 @@ public function __construct(
2828
parent::__construct();
2929
$this->type = self::TYPE;
3030
}
31+
32+
public function toArray(): array
33+
{
34+
return [
35+
'width' => $this->width,
36+
'height' => $this->height,
37+
'widthSegments' => $this->widthSegments,
38+
'heightSegments' => $this->heightSegments,
39+
'type' => $this->type,
40+
];
41+
}
3142
}

src/Threejs/src/Geometry/Sphere.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,14 @@ public function __construct(
2727
parent::__construct();
2828
$this->type = self::TYPE;
2929
}
30+
31+
public function toArray(): array
32+
{
33+
return [
34+
'radius' => $this->radius,
35+
'widthSegments' => $this->widthSegments,
36+
'heightSegments' => $this->heightSegments,
37+
'type' => $this->type,
38+
];
39+
}
3040
}

src/Threejs/src/Light/AmbientLight.php renamed to src/Threejs/src/Light/Ambient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* @author Sylvain Blondeau <[email protected]>
1616
*/
17-
final class AmbientLight extends Light
17+
final class Ambient extends Light
1818
{
1919
public const string TYPE = 'Ambient';
2020

src/Threejs/src/Light/DirectionalLight.php renamed to src/Threejs/src/Light/Directional.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* @author Sylvain Blondeau <[email protected]>
1818
*/
19-
final class DirectionalLight extends Light
19+
final class Directional extends Light
2020
{
2121
public const string TYPE = 'Directional';
2222

@@ -30,5 +30,28 @@ public function __construct(
3030

3131
) {
3232
parent::__construct($color, $intensity);
33+
}
34+
35+
public static function fromArray(array $light): self
36+
{
37+
$light['position'] = Vector3::fromArray($light['position']);
38+
$light['target'] = Vector3::fromArray($light['target']);
39+
$type = $light['type'];
40+
unset($light['type']);
41+
$lightObject = new static(...$light);
42+
$lightObject->type = $type;
43+
44+
return $lightObject;
45+
}
46+
47+
public function toArray(): array
48+
{
49+
return [
50+
'type' => $this->type,
51+
'color' => $this->color,
52+
'intensity' => $this->intensity,
53+
'position' => $this->position->toArray(),
54+
'target' => $this->target->toArray(),
55+
];
3356
}
3457
}

0 commit comments

Comments
 (0)