簡體   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