繁体   English   中英

如何在iPhone中加载,渲染和显示由Maya或Blender创建的obj格式的3d模型,纹理为png或jpg?

[英]How to Load, render and display 3d model of obj format created by maya or blender in iphone with textures as png or jpg?

嗨,我知道网上有很多wavefrontobj解析器可以加载.obj模型,但是大多数都没有纹理加载,因此我需要知道如何加载TEXTURES(.png和.jpg)。 我也编写了用于缩放3d模型并与其进行交互的代码,但是它不起作用。 因此,谁能帮助我解决这个问题。 具有上述所有功能的任何示例应用程序将受到高度赞赏。

提前致谢..

缩放代码:

- (void)scale:(id)sender 
{
    if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) 
    {
        lastScale = 1.0;
        return;
    }

    CGFloat prevZoomValue = zoomValue;
    CGFloat scale = (1.0 - (lastScale - [(UIPinchGestureRecognizer*)sender scale]))/10;

    if ([(UIPinchGestureRecognizer*)sender scale] < 1)
    {
        //user is zooming in
        // range 1.0 to 0.0
        zoomValue -= scale;
    }
    else 
    {
        //user is zooming out
        // range > 1.0
        zoomValue += scale/10;
    }

    // if zoom value is not in the range then restore last value
    if (!(zoomValue < -0.1 && zoomValue > -10.0))
    {
        zoomValue = prevZoomValue;
        lastScale = [(UIPinchGestureRecognizer*)sender scale];
    }
}

互动代码:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//    NSMutableSet *currentTouches = [[[event touchesForView:self] mutableCopy] autorelease];
//    [currentTouches minusSet:touches];

    secondsInterval = CFAbsoluteTimeGetCurrent();
    //longPressTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(startLongPressCounter) userInfo:nil repeats:YES];

    // New touches are not yet included in the current touches for the view
    lastMovementPosition = [[touches anyObject] locationInView:self];
    rotateX = endMovementPosition.x;
    rotateY = endMovementPosition.y;
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    idleRotate = FALSE;

    CGPoint currentMovementPosition = [[touches anyObject] locationInView:self];
    NSLog(@"touchesMoved");

    rotateX = (lastMovementPosition.x - currentMovementPosition.x);
    rotateY = (lastMovementPosition.y - currentMovementPosition.y);

    //[self renderByRotatingAroundX:(lastMovementPosition.x - currentMovementPosition.x) rotatingAroundY:(lastMovementPosition.y - currentMovementPosition.y)];
    lastMovementPosition = currentMovementPosition;
}
NSString *path = [[NSBundle mainBundle] pathForResource:@"cubeimage" ofType:@"jpg"];
OpenGLTexture3D *newTexture = [[OpenGLTexture3D alloc] initWithFilename:path width:512 height:512];
self.texture = newTexture;
[newTexture release];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM