ARKit add 2D Video flipped by X











up vote
1
down vote

favorite












So I have following code to create custom wall



    let wall = SCNPlane(width: CGFloat(distance),
height: CGFloat(height))
wall.firstMaterial = wallMaterial()
let node = SCNNode(geometry: wall)

// always render before the beachballs
node.renderingOrder = -10

// get center point
node.position = SCNVector3(from.x + (to.x - from.x) * 0.5,
from.y + height * 0.5,
from.z + (to.z - from.z) * 0.5)
node.eulerAngles = SCNVector3(0,
-atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0.5,
0)


And Now I am adding simple SCNPlane on hit test and add video (skscene to it)



          // first.node is hittest result 

let node = SCNNode(geometry: SCNPlane(width: CGFloat(width) , height: CGFloat(height))
node.geometry?.firstMaterial?.isDoubleSided = true
node.geometry?.firstMaterial?.diffuse.contents = self.create2DVideoScene(xScale: first.node.eulerAngles.y < 0 ? -1 : nil)
node.position = nodesWithDistance.previous.node.mainNode.position

node.eulerAngles = first.node.eulerAngles


Here How I created 2d node



 /// Creates 2D video scene
private func create2DVideoScene (xScale:CGFloat?) -> SKScene {
var videoPlayer = AVPlayer()

if let validURL = Bundle.main.url(forResource: "video", withExtension: "mp4", subdirectory: "/art.scnassets") {
let item = AVPlayerItem(url: validURL)
videoPlayer = AVPlayer(playerItem: item)
}
let videoNode = SKVideoNode(avPlayer: videoPlayer)
videoNode.yScale *= -1

// While debug I observe that if first.node.rotation.y in - , then we need to change xScale to -1 (when wall draw from right -> left )

if let xScale = xScale {
videoNode.xScale *= xScale

}


videoNode.play()

let skScene = SKScene(size: self.sceneView.frame.size)
skScene.scaleMode = .aspectFill
skScene.backgroundColor = .green
skScene.addChild(videoNode)
videoNode.position = CGPoint(x: skScene.size.width/2, y: skScene.size.height/2)
videoNode.size = skScene.size
return skScene
}


Issue :: If I draw wall node from left to right means first point is on left side and other point on right side and draw wall between them. Then Video is flipped.



If I draw from right to left means first point is on right side and second point is on left side and draw line between them then video is perfectly fine.



To fix this I checked wall eulerAngles check the line self.create2DVideoScene but this is not working in every area of real world



I want video should not be start flipped in front of user



EDIT



video is flipped because ofeulerAngles is different in both case while create a wall




Angle point1 to point2 --> (0.000000 -1.000000 0.000000 3.735537)



Angle point2 to point1 -- > (0.000000 -1.000000 0.000000 0.478615)






Issue video Click here to play video



Please please provide the suggestion or solution of this issue .



enter image description here



Video flipped



Flipped










share|improve this question
























  • Note that in recent versions of SceneKit using a SKScene and a SKVideoNode is not necessary. You can directly set the AVPlayer as the contents of a SCNMaterialProperty instance.
    – mnuages
    Nov 13 at 13:47










  • @mnuages Thanks for comment I have already tried this. I have already added video i.e AVplayer directly but issue is drawing wall from RIGHT -> LEFT working fine but drawing LEFT -> RIGHT show AVPlayer Flipped
    – Prashant Tukadiya
    Nov 13 at 13:52










  • Issue is with -atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0. but i am not able to figure it out
    – Prashant Tukadiya
    Nov 13 at 13:53










  • I don't understand what you mean by "draw from left to right" versus "draw from right to left"
    – mnuages
    Nov 13 at 14:35










  • @mnuages sorry for my bad English See the image where I written point 1 and point 2. If I draw point 1 ---> point 2 video is normal. But at same position if I draw from point 2 --> point 1 video is flipping as shown in image 2
    – Prashant Tukadiya
    Nov 13 at 14:45















up vote
1
down vote

favorite












So I have following code to create custom wall



    let wall = SCNPlane(width: CGFloat(distance),
height: CGFloat(height))
wall.firstMaterial = wallMaterial()
let node = SCNNode(geometry: wall)

// always render before the beachballs
node.renderingOrder = -10

// get center point
node.position = SCNVector3(from.x + (to.x - from.x) * 0.5,
from.y + height * 0.5,
from.z + (to.z - from.z) * 0.5)
node.eulerAngles = SCNVector3(0,
-atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0.5,
0)


And Now I am adding simple SCNPlane on hit test and add video (skscene to it)



          // first.node is hittest result 

let node = SCNNode(geometry: SCNPlane(width: CGFloat(width) , height: CGFloat(height))
node.geometry?.firstMaterial?.isDoubleSided = true
node.geometry?.firstMaterial?.diffuse.contents = self.create2DVideoScene(xScale: first.node.eulerAngles.y < 0 ? -1 : nil)
node.position = nodesWithDistance.previous.node.mainNode.position

node.eulerAngles = first.node.eulerAngles


Here How I created 2d node



 /// Creates 2D video scene
private func create2DVideoScene (xScale:CGFloat?) -> SKScene {
var videoPlayer = AVPlayer()

if let validURL = Bundle.main.url(forResource: "video", withExtension: "mp4", subdirectory: "/art.scnassets") {
let item = AVPlayerItem(url: validURL)
videoPlayer = AVPlayer(playerItem: item)
}
let videoNode = SKVideoNode(avPlayer: videoPlayer)
videoNode.yScale *= -1

// While debug I observe that if first.node.rotation.y in - , then we need to change xScale to -1 (when wall draw from right -> left )

if let xScale = xScale {
videoNode.xScale *= xScale

}


videoNode.play()

let skScene = SKScene(size: self.sceneView.frame.size)
skScene.scaleMode = .aspectFill
skScene.backgroundColor = .green
skScene.addChild(videoNode)
videoNode.position = CGPoint(x: skScene.size.width/2, y: skScene.size.height/2)
videoNode.size = skScene.size
return skScene
}


Issue :: If I draw wall node from left to right means first point is on left side and other point on right side and draw wall between them. Then Video is flipped.



If I draw from right to left means first point is on right side and second point is on left side and draw line between them then video is perfectly fine.



To fix this I checked wall eulerAngles check the line self.create2DVideoScene but this is not working in every area of real world



I want video should not be start flipped in front of user



EDIT



video is flipped because ofeulerAngles is different in both case while create a wall




Angle point1 to point2 --> (0.000000 -1.000000 0.000000 3.735537)



Angle point2 to point1 -- > (0.000000 -1.000000 0.000000 0.478615)






Issue video Click here to play video



Please please provide the suggestion or solution of this issue .



enter image description here



Video flipped



Flipped










share|improve this question
























  • Note that in recent versions of SceneKit using a SKScene and a SKVideoNode is not necessary. You can directly set the AVPlayer as the contents of a SCNMaterialProperty instance.
    – mnuages
    Nov 13 at 13:47










  • @mnuages Thanks for comment I have already tried this. I have already added video i.e AVplayer directly but issue is drawing wall from RIGHT -> LEFT working fine but drawing LEFT -> RIGHT show AVPlayer Flipped
    – Prashant Tukadiya
    Nov 13 at 13:52










  • Issue is with -atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0. but i am not able to figure it out
    – Prashant Tukadiya
    Nov 13 at 13:53










  • I don't understand what you mean by "draw from left to right" versus "draw from right to left"
    – mnuages
    Nov 13 at 14:35










  • @mnuages sorry for my bad English See the image where I written point 1 and point 2. If I draw point 1 ---> point 2 video is normal. But at same position if I draw from point 2 --> point 1 video is flipping as shown in image 2
    – Prashant Tukadiya
    Nov 13 at 14:45













up vote
1
down vote

favorite









up vote
1
down vote

favorite











So I have following code to create custom wall



    let wall = SCNPlane(width: CGFloat(distance),
height: CGFloat(height))
wall.firstMaterial = wallMaterial()
let node = SCNNode(geometry: wall)

// always render before the beachballs
node.renderingOrder = -10

// get center point
node.position = SCNVector3(from.x + (to.x - from.x) * 0.5,
from.y + height * 0.5,
from.z + (to.z - from.z) * 0.5)
node.eulerAngles = SCNVector3(0,
-atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0.5,
0)


And Now I am adding simple SCNPlane on hit test and add video (skscene to it)



          // first.node is hittest result 

let node = SCNNode(geometry: SCNPlane(width: CGFloat(width) , height: CGFloat(height))
node.geometry?.firstMaterial?.isDoubleSided = true
node.geometry?.firstMaterial?.diffuse.contents = self.create2DVideoScene(xScale: first.node.eulerAngles.y < 0 ? -1 : nil)
node.position = nodesWithDistance.previous.node.mainNode.position

node.eulerAngles = first.node.eulerAngles


Here How I created 2d node



 /// Creates 2D video scene
private func create2DVideoScene (xScale:CGFloat?) -> SKScene {
var videoPlayer = AVPlayer()

if let validURL = Bundle.main.url(forResource: "video", withExtension: "mp4", subdirectory: "/art.scnassets") {
let item = AVPlayerItem(url: validURL)
videoPlayer = AVPlayer(playerItem: item)
}
let videoNode = SKVideoNode(avPlayer: videoPlayer)
videoNode.yScale *= -1

// While debug I observe that if first.node.rotation.y in - , then we need to change xScale to -1 (when wall draw from right -> left )

if let xScale = xScale {
videoNode.xScale *= xScale

}


videoNode.play()

let skScene = SKScene(size: self.sceneView.frame.size)
skScene.scaleMode = .aspectFill
skScene.backgroundColor = .green
skScene.addChild(videoNode)
videoNode.position = CGPoint(x: skScene.size.width/2, y: skScene.size.height/2)
videoNode.size = skScene.size
return skScene
}


Issue :: If I draw wall node from left to right means first point is on left side and other point on right side and draw wall between them. Then Video is flipped.



If I draw from right to left means first point is on right side and second point is on left side and draw line between them then video is perfectly fine.



To fix this I checked wall eulerAngles check the line self.create2DVideoScene but this is not working in every area of real world



I want video should not be start flipped in front of user



EDIT



video is flipped because ofeulerAngles is different in both case while create a wall




Angle point1 to point2 --> (0.000000 -1.000000 0.000000 3.735537)



Angle point2 to point1 -- > (0.000000 -1.000000 0.000000 0.478615)






Issue video Click here to play video



Please please provide the suggestion or solution of this issue .



enter image description here



Video flipped



Flipped










share|improve this question















So I have following code to create custom wall



    let wall = SCNPlane(width: CGFloat(distance),
height: CGFloat(height))
wall.firstMaterial = wallMaterial()
let node = SCNNode(geometry: wall)

// always render before the beachballs
node.renderingOrder = -10

// get center point
node.position = SCNVector3(from.x + (to.x - from.x) * 0.5,
from.y + height * 0.5,
from.z + (to.z - from.z) * 0.5)
node.eulerAngles = SCNVector3(0,
-atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0.5,
0)


And Now I am adding simple SCNPlane on hit test and add video (skscene to it)



          // first.node is hittest result 

let node = SCNNode(geometry: SCNPlane(width: CGFloat(width) , height: CGFloat(height))
node.geometry?.firstMaterial?.isDoubleSided = true
node.geometry?.firstMaterial?.diffuse.contents = self.create2DVideoScene(xScale: first.node.eulerAngles.y < 0 ? -1 : nil)
node.position = nodesWithDistance.previous.node.mainNode.position

node.eulerAngles = first.node.eulerAngles


Here How I created 2d node



 /// Creates 2D video scene
private func create2DVideoScene (xScale:CGFloat?) -> SKScene {
var videoPlayer = AVPlayer()

if let validURL = Bundle.main.url(forResource: "video", withExtension: "mp4", subdirectory: "/art.scnassets") {
let item = AVPlayerItem(url: validURL)
videoPlayer = AVPlayer(playerItem: item)
}
let videoNode = SKVideoNode(avPlayer: videoPlayer)
videoNode.yScale *= -1

// While debug I observe that if first.node.rotation.y in - , then we need to change xScale to -1 (when wall draw from right -> left )

if let xScale = xScale {
videoNode.xScale *= xScale

}


videoNode.play()

let skScene = SKScene(size: self.sceneView.frame.size)
skScene.scaleMode = .aspectFill
skScene.backgroundColor = .green
skScene.addChild(videoNode)
videoNode.position = CGPoint(x: skScene.size.width/2, y: skScene.size.height/2)
videoNode.size = skScene.size
return skScene
}


Issue :: If I draw wall node from left to right means first point is on left side and other point on right side and draw wall between them. Then Video is flipped.



If I draw from right to left means first point is on right side and second point is on left side and draw line between them then video is perfectly fine.



To fix this I checked wall eulerAngles check the line self.create2DVideoScene but this is not working in every area of real world



I want video should not be start flipped in front of user



EDIT



video is flipped because ofeulerAngles is different in both case while create a wall




Angle point1 to point2 --> (0.000000 -1.000000 0.000000 3.735537)



Angle point2 to point1 -- > (0.000000 -1.000000 0.000000 0.478615)






Issue video Click here to play video



Please please provide the suggestion or solution of this issue .



enter image description here



Video flipped



Flipped







ios swift scenekit arkit






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 at 10:53

























asked Nov 13 at 13:42









Prashant Tukadiya

6,74721746




6,74721746












  • Note that in recent versions of SceneKit using a SKScene and a SKVideoNode is not necessary. You can directly set the AVPlayer as the contents of a SCNMaterialProperty instance.
    – mnuages
    Nov 13 at 13:47










  • @mnuages Thanks for comment I have already tried this. I have already added video i.e AVplayer directly but issue is drawing wall from RIGHT -> LEFT working fine but drawing LEFT -> RIGHT show AVPlayer Flipped
    – Prashant Tukadiya
    Nov 13 at 13:52










  • Issue is with -atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0. but i am not able to figure it out
    – Prashant Tukadiya
    Nov 13 at 13:53










  • I don't understand what you mean by "draw from left to right" versus "draw from right to left"
    – mnuages
    Nov 13 at 14:35










  • @mnuages sorry for my bad English See the image where I written point 1 and point 2. If I draw point 1 ---> point 2 video is normal. But at same position if I draw from point 2 --> point 1 video is flipping as shown in image 2
    – Prashant Tukadiya
    Nov 13 at 14:45


















  • Note that in recent versions of SceneKit using a SKScene and a SKVideoNode is not necessary. You can directly set the AVPlayer as the contents of a SCNMaterialProperty instance.
    – mnuages
    Nov 13 at 13:47










  • @mnuages Thanks for comment I have already tried this. I have already added video i.e AVplayer directly but issue is drawing wall from RIGHT -> LEFT working fine but drawing LEFT -> RIGHT show AVPlayer Flipped
    – Prashant Tukadiya
    Nov 13 at 13:52










  • Issue is with -atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0. but i am not able to figure it out
    – Prashant Tukadiya
    Nov 13 at 13:53










  • I don't understand what you mean by "draw from left to right" versus "draw from right to left"
    – mnuages
    Nov 13 at 14:35










  • @mnuages sorry for my bad English See the image where I written point 1 and point 2. If I draw point 1 ---> point 2 video is normal. But at same position if I draw from point 2 --> point 1 video is flipping as shown in image 2
    – Prashant Tukadiya
    Nov 13 at 14:45
















Note that in recent versions of SceneKit using a SKScene and a SKVideoNode is not necessary. You can directly set the AVPlayer as the contents of a SCNMaterialProperty instance.
– mnuages
Nov 13 at 13:47




Note that in recent versions of SceneKit using a SKScene and a SKVideoNode is not necessary. You can directly set the AVPlayer as the contents of a SCNMaterialProperty instance.
– mnuages
Nov 13 at 13:47












@mnuages Thanks for comment I have already tried this. I have already added video i.e AVplayer directly but issue is drawing wall from RIGHT -> LEFT working fine but drawing LEFT -> RIGHT show AVPlayer Flipped
– Prashant Tukadiya
Nov 13 at 13:52




@mnuages Thanks for comment I have already tried this. I have already added video i.e AVplayer directly but issue is drawing wall from RIGHT -> LEFT working fine but drawing LEFT -> RIGHT show AVPlayer Flipped
– Prashant Tukadiya
Nov 13 at 13:52












Issue is with -atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0. but i am not able to figure it out
– Prashant Tukadiya
Nov 13 at 13:53




Issue is with -atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0. but i am not able to figure it out
– Prashant Tukadiya
Nov 13 at 13:53












I don't understand what you mean by "draw from left to right" versus "draw from right to left"
– mnuages
Nov 13 at 14:35




I don't understand what you mean by "draw from left to right" versus "draw from right to left"
– mnuages
Nov 13 at 14:35












@mnuages sorry for my bad English See the image where I written point 1 and point 2. If I draw point 1 ---> point 2 video is normal. But at same position if I draw from point 2 --> point 1 video is flipping as shown in image 2
– Prashant Tukadiya
Nov 13 at 14:45




@mnuages sorry for my bad English See the image where I written point 1 and point 2. If I draw point 1 ---> point 2 video is normal. But at same position if I draw from point 2 --> point 1 video is flipping as shown in image 2
– Prashant Tukadiya
Nov 13 at 14:45












1 Answer
1






active

oldest

votes

















up vote
0
down vote













I have fixed issue with temporary solution still looking for a better one



Issue is of wall. wall is flipped other side of camera when draw from right to left direction. I have figure it out by setting isDoubleSided = false and by applying a image as diffuse contents which has text and I can see that image is flipped itself.



I have tried many things but this one helps me




  1. Normalize vector

  2. Find the cross between to SCNVectors

  3. If y > 0 I just swapped from and to Value


Code



    let normalizedTO = to.normalized()
let normalizedFrom = from.normalized()
let angleBetweenTwoVectors = normalizedTO.cross(normalizedFrom)

var from = from
var to = to
if angleBetweenTwoVectors.y > 0 {
let temp = from
from = to
to = temp
}

// Inside extension of SCNVector3
func normalized() -> SCNVector3 {
if self.length() == 0 {
return self
}

return self / self.length()
}

func cross(_ vec: SCNVector3) -> SCNVector3 {
return SCNVector3(self.y * vec.z - self.z * vec.y, self.z * vec.x - self.x * vec.z, self.x * vec.y - self.y * vec.x)
}


Hope it is helpful. If anyone know better solution please answer it.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282351%2farkit-add-2d-video-flipped-by-x%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    I have fixed issue with temporary solution still looking for a better one



    Issue is of wall. wall is flipped other side of camera when draw from right to left direction. I have figure it out by setting isDoubleSided = false and by applying a image as diffuse contents which has text and I can see that image is flipped itself.



    I have tried many things but this one helps me




    1. Normalize vector

    2. Find the cross between to SCNVectors

    3. If y > 0 I just swapped from and to Value


    Code



        let normalizedTO = to.normalized()
    let normalizedFrom = from.normalized()
    let angleBetweenTwoVectors = normalizedTO.cross(normalizedFrom)

    var from = from
    var to = to
    if angleBetweenTwoVectors.y > 0 {
    let temp = from
    from = to
    to = temp
    }

    // Inside extension of SCNVector3
    func normalized() -> SCNVector3 {
    if self.length() == 0 {
    return self
    }

    return self / self.length()
    }

    func cross(_ vec: SCNVector3) -> SCNVector3 {
    return SCNVector3(self.y * vec.z - self.z * vec.y, self.z * vec.x - self.x * vec.z, self.x * vec.y - self.y * vec.x)
    }


    Hope it is helpful. If anyone know better solution please answer it.






    share|improve this answer

























      up vote
      0
      down vote













      I have fixed issue with temporary solution still looking for a better one



      Issue is of wall. wall is flipped other side of camera when draw from right to left direction. I have figure it out by setting isDoubleSided = false and by applying a image as diffuse contents which has text and I can see that image is flipped itself.



      I have tried many things but this one helps me




      1. Normalize vector

      2. Find the cross between to SCNVectors

      3. If y > 0 I just swapped from and to Value


      Code



          let normalizedTO = to.normalized()
      let normalizedFrom = from.normalized()
      let angleBetweenTwoVectors = normalizedTO.cross(normalizedFrom)

      var from = from
      var to = to
      if angleBetweenTwoVectors.y > 0 {
      let temp = from
      from = to
      to = temp
      }

      // Inside extension of SCNVector3
      func normalized() -> SCNVector3 {
      if self.length() == 0 {
      return self
      }

      return self / self.length()
      }

      func cross(_ vec: SCNVector3) -> SCNVector3 {
      return SCNVector3(self.y * vec.z - self.z * vec.y, self.z * vec.x - self.x * vec.z, self.x * vec.y - self.y * vec.x)
      }


      Hope it is helpful. If anyone know better solution please answer it.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        I have fixed issue with temporary solution still looking for a better one



        Issue is of wall. wall is flipped other side of camera when draw from right to left direction. I have figure it out by setting isDoubleSided = false and by applying a image as diffuse contents which has text and I can see that image is flipped itself.



        I have tried many things but this one helps me




        1. Normalize vector

        2. Find the cross between to SCNVectors

        3. If y > 0 I just swapped from and to Value


        Code



            let normalizedTO = to.normalized()
        let normalizedFrom = from.normalized()
        let angleBetweenTwoVectors = normalizedTO.cross(normalizedFrom)

        var from = from
        var to = to
        if angleBetweenTwoVectors.y > 0 {
        let temp = from
        from = to
        to = temp
        }

        // Inside extension of SCNVector3
        func normalized() -> SCNVector3 {
        if self.length() == 0 {
        return self
        }

        return self / self.length()
        }

        func cross(_ vec: SCNVector3) -> SCNVector3 {
        return SCNVector3(self.y * vec.z - self.z * vec.y, self.z * vec.x - self.x * vec.z, self.x * vec.y - self.y * vec.x)
        }


        Hope it is helpful. If anyone know better solution please answer it.






        share|improve this answer












        I have fixed issue with temporary solution still looking for a better one



        Issue is of wall. wall is flipped other side of camera when draw from right to left direction. I have figure it out by setting isDoubleSided = false and by applying a image as diffuse contents which has text and I can see that image is flipped itself.



        I have tried many things but this one helps me




        1. Normalize vector

        2. Find the cross between to SCNVectors

        3. If y > 0 I just swapped from and to Value


        Code



            let normalizedTO = to.normalized()
        let normalizedFrom = from.normalized()
        let angleBetweenTwoVectors = normalizedTO.cross(normalizedFrom)

        var from = from
        var to = to
        if angleBetweenTwoVectors.y > 0 {
        let temp = from
        from = to
        to = temp
        }

        // Inside extension of SCNVector3
        func normalized() -> SCNVector3 {
        if self.length() == 0 {
        return self
        }

        return self / self.length()
        }

        func cross(_ vec: SCNVector3) -> SCNVector3 {
        return SCNVector3(self.y * vec.z - self.z * vec.y, self.z * vec.x - self.x * vec.z, self.x * vec.y - self.y * vec.x)
        }


        Hope it is helpful. If anyone know better solution please answer it.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 at 6:19









        Prashant Tukadiya

        6,74721746




        6,74721746






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282351%2farkit-add-2d-video-flipped-by-x%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?