1
1
package io.github.sceneview.node
2
2
3
- import android.media.MediaPlayer
4
- import com.google.android.filament.RenderableManager
5
- import io.github.sceneview.geometries.Plane
6
- import io.github.sceneview.loaders.MaterialLoader
7
- import io.github.sceneview.material.VideoMaterial
8
- import io.github.sceneview.math.Direction
9
- import io.github.sceneview.math.Position
10
- import io.github.sceneview.math.Size
11
-
12
- open class VideoNode (
13
- videoMaterial : VideoMaterial ,
14
- val player : MediaPlayer ,
15
- size : Size = Plane .DEFAULT_SIZE ,
16
- center : Position = Plane .DEFAULT_CENTER ,
17
- normal : Direction = Plane .DEFAULT_NORMAL ,
18
- scaleToVideoRatio : Boolean = true ,
19
- /* *
20
- * Keep the video aspect ratio.
21
- * - `true` to fit within max width or height
22
- * - `false` the video will be stretched to the node scale
23
- */
24
- keepAspectRatio : Boolean = true ,
25
- /* *
26
- * The parent node.
27
- *
28
- * If set to null, this node will not be attached.
29
- *
30
- * The local position, rotation, and scale of this node will remain the same.
31
- * Therefore, the world position, rotation, and scale of this node may be different after the
32
- * parent changes.
33
- */
34
- parent : Node ? = null ,
35
- renderableApply : RenderableManager .Builder .() -> Unit = {}
36
- ) : PlaneNode(
37
- engine = videoMaterial.engine,
38
- size = size,
39
- center = center,
40
- normal = normal,
41
- materialInstance = videoMaterial.instance,
42
- parent = parent,
43
- renderableApply = renderableApply
44
- ) {
45
- init {
46
- if (scaleToVideoRatio) {
47
- player.doOnVideoSized { player, width, height ->
48
- if (player == this .player) {
49
- if (keepAspectRatio) {
50
- scale = scale.apply {
51
- x = if (width >= height) 1.0f else width.toFloat() / height.toFloat()
52
- y = if (width >= height) height.toFloat() / width.toFloat() else 1.0f
53
- }
54
- }
55
- }
56
- }
57
- }
58
- }
59
-
60
- constructor (
61
- materialLoader: MaterialLoader ,
62
- player: MediaPlayer ,
63
- chromaKeyColor: Int? = null ,
64
- scaleToVideoRatio: Boolean = true ,
65
- /* *
66
- * Keep the video aspect ratio.
67
- * - `true` to fit within max width or height
68
- * - `false` the video will be stretched to the node scale
69
- */
70
- keepAspectRatio: Boolean = true ,
71
- size: Size = Plane .DEFAULT_SIZE ,
72
- center: Position = Plane .DEFAULT_CENTER ,
73
- normal: Direction = Plane .DEFAULT_NORMAL ,
74
- /* *
75
- * The parent node.
76
- *
77
- * If set to null, this node will not be attached.
78
- *
79
- * The local position, rotation, and scale of this node will remain the same.
80
- * Therefore, the world position, rotation, and scale of this node may be different after the
81
- * parent changes.
82
- */
83
- parent: Node ? = null ,
84
- renderableApply: RenderableManager .Builder .() -> Unit = {}
85
- ) : this (
86
- videoMaterial = materialLoader.createVideoMaterial(player, chromaKeyColor),
87
- player = player,
88
- scaleToVideoRatio = scaleToVideoRatio,
89
- keepAspectRatio = keepAspectRatio,
90
- size = size,
91
- center = center,
92
- normal = normal,
93
- parent = parent,
94
- renderableApply = renderableApply
95
- )
96
-
97
- override fun destroy () {
98
- super .destroy()
99
-
100
- player.stop()
101
- }
102
- }
103
-
104
-
105
- fun MediaPlayer.doOnVideoSized (block : (player: MediaPlayer , videoWidth: Int , videoHeight: Int ) -> Unit ) {
106
- if (videoWidth > 0 && videoHeight > 0 ) {
107
- block(this , videoWidth, videoHeight)
108
- } else {
109
- setOnVideoSizeChangedListener { _, width: Int , height: Int ->
110
- if (width > 0 && height > 0 ) {
111
- block(this , width, height)
112
- }
113
- }
114
- }
115
- }
3
+ // TODO: To finish
4
+ // open class VideoNode private constructor(
5
+ // engine: Engine,
6
+ // val materialLoader: MaterialLoader,
7
+ // entity: Entity = EntityManager.get().create(),
8
+ // parent: Node? = null,
9
+ // mediaPlayer: MediaPlayer,
10
+ // val texture: Texture,
11
+ // /**
12
+ // * `null` to adjust size on the normalized image size
13
+ // */
14
+ // val size: Size? = null,
15
+ // center: Position = Plane.DEFAULT_CENTER,
16
+ // normal: Direction = Plane.DEFAULT_NORMAL,
17
+ // builder: RenderableManager.Builder.() -> Unit = {}
18
+ // ) : PlaneNode(
19
+ // engine, entity, parent,
20
+ // size ?: normalize(Size(mediaPlayer.videoWidth.toFloat(), mediaPlayer.videoHeight.toFloat())),
21
+ // center, normal,
22
+ // materialLoader.createVideoInstance(texture),
23
+ // builder
24
+ // ) {
25
+ // var mediaPlayer = mediaPlayer
26
+ // set(value) {
27
+ // field = value
28
+ // texture.setExternalStream()setBitmap(engine, value)
29
+ // if (size == null) {
30
+ // updateGeometry(
31
+ // size = normalize(Size(value.videoWidth.toFloat(), value.videoHeight.toFloat()))
32
+ // )
33
+ // }
34
+ // }
35
+ //
36
+ // init {
37
+ // if (size == null) {
38
+ // mediaPlayer.doOnVideoSized { player, width, height ->
39
+ // if (player == this.player) {
40
+ // updateGeometry(size = normalize(Size(width.toFloat(), height.toFloat())))
41
+ // }
42
+ // }
43
+ // }
44
+ // }
45
+ // }
46
+ //
47
+ // open class VideoNode(
48
+ // videoMaterial: VideoMaterial,
49
+ // val player: MediaPlayer,
50
+ // size: Size = Plane.DEFAULT_SIZE,
51
+ // center: Position = Plane.DEFAULT_CENTER,
52
+ // normal: Direction = Plane.DEFAULT_NORMAL,
53
+ // scaleToVideoRatio: Boolean = true,
54
+ // /**
55
+ // * Keep the video aspect ratio.
56
+ // * - `true` to fit within max width or height
57
+ // * - `false` the video will be stretched to the node scale
58
+ // */
59
+ // keepAspectRatio: Boolean = true,
60
+ // /**
61
+ // * The parent node.
62
+ // *
63
+ // * If set to null, this node will not be attached.
64
+ // *
65
+ // * The local position, rotation, and scale of this node will remain the same.
66
+ // * Therefore, the world position, rotation, and scale of this node may be different after the
67
+ // * parent changes.
68
+ // */
69
+ // parent: Node? = null,
70
+ // renderableApply: RenderableManager.Builder.() -> Unit = {}
71
+ // ) : PlaneNode(
72
+ // engine = videoMaterial.engine,
73
+ // size = size,
74
+ // center = center,
75
+ // normal = normal,
76
+ // materialInstance = videoMaterial.instance,
77
+ // parent = parent,
78
+ // renderableApply = renderableApply
79
+ // ) {
80
+ //
81
+ //
82
+ // constructor(
83
+ // materialLoader: MaterialLoader,
84
+ // player: MediaPlayer,
85
+ // chromaKeyColor: Int? = null,
86
+ // scaleToVideoRatio: Boolean = true,
87
+ // /**
88
+ // * Keep the video aspect ratio.
89
+ // * - `true` to fit within max width or height
90
+ // * - `false` the video will be stretched to the node scale
91
+ // */
92
+ // keepAspectRatio: Boolean = true,
93
+ // size: Size = Plane.DEFAULT_SIZE,
94
+ // center: Position = Plane.DEFAULT_CENTER,
95
+ // normal: Direction = Plane.DEFAULT_NORMAL,
96
+ // /**
97
+ // * The parent node.
98
+ // *
99
+ // * If set to null, this node will not be attached.
100
+ // *
101
+ // * The local position, rotation, and scale of this node will remain the same.
102
+ // * Therefore, the world position, rotation, and scale of this node may be different after the
103
+ // * parent changes.
104
+ // */
105
+ // parent: Node? = null,
106
+ // renderableApply: RenderableManager.Builder.() -> Unit = {}
107
+ // ) : this(
108
+ // videoMaterial = materialLoader.createVideoInstance(player, chromaKeyColor),
109
+ // player = player,
110
+ // scaleToVideoRatio = scaleToVideoRatio,
111
+ // keepAspectRatio = keepAspectRatio,
112
+ // size = size,
113
+ // center = center,
114
+ // normal = normal,
115
+ // parent = parent,
116
+ // renderableApply = renderableApply
117
+ // )
118
+ //
119
+ // override fun destroy() {
120
+ // super.destroy()
121
+ //
122
+ // player.stop()
123
+ // }
124
+ // }
125
+ //
126
+ //
127
+ // fun MediaPlayer.doOnVideoSized(block: (player: MediaPlayer, videoWidth: Int, videoHeight: Int) -> Unit) {
128
+ // if (videoWidth > 0 && videoHeight > 0) {
129
+ // block(this, videoWidth, videoHeight)
130
+ // } else {
131
+ // setOnVideoSizeChangedListener { _, width: Int, height: Int ->
132
+ // if (width > 0 && height > 0) {
133
+ // block(this, width, height)
134
+ // }
135
+ // }
136
+ // }
137
+ // }
0 commit comments